From 1476fb58de9526ae09a7e92e37faa0e42ff53c77 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Thu, 31 Jul 2014 14:29:08 -0700 Subject: [PATCH] simplify logic in the constructor --- index.js | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/index.js b/index.js index 183d637..03f4976 100644 --- a/index.js +++ b/index.js @@ -9,32 +9,23 @@ var parse = css.parse; var stringify = css.stringify; /** - * Expose `rework`. + * Expose `Rework`. */ -exports = module.exports = rework; +exports = module.exports = Rework; /** - * Initialize a new stylesheet `Rework` with `str`. + * Initialize a new stylesheet `Rework` with `obj`. * - * @param {String} str + * @param {Object|String} obj * @param {Object} options * @return {Rework} * @api public */ -function rework(str, options) { - return new Rework(parse(str, options)); -} - -/** - * Initialize a new stylesheet `Rework` with `obj`. - * - * @param {Object} obj - * @api private - */ - -function Rework(obj) { +function Rework(obj, options) { + if (!(this instanceof Rework)) return new Rework(obj, options); + if ('string' == typeof obj) obj = parse(obj, options); this.obj = obj; }