diff --git a/index.js b/index.js index 9237ba7..158b884 100644 --- a/index.js +++ b/index.js @@ -7,7 +7,7 @@ var normalizeOpts = require('es5-ext/object/normalize-options') module.exports = function (fn/*, options*/) { var options = normalizeOpts(arguments[1]), length; - if (!options.normalizer && !options.serialize) { + if (!options.normalizer) { length = options.length = resolveLength(options.length, fn.length, options.async); if (length === 0) { options.normalizer = require('./lib/normalizers/0'); diff --git a/lib/configure-map.js b/lib/configure-map.js index c7b2949..930c504 100644 --- a/lib/configure-map.js +++ b/lib/configure-map.js @@ -27,18 +27,18 @@ module.exports = function (original, length, options) { else memLength = original.length; if (options.normalizer) { - get = callable(options.normalizer.get); - if (options.normalizer.set !== undefined) { - set = callable(options.normalizer.set); - del = callable(options.normalizer.delete); - clear = callable(options.normalizer.clear); + if (typeof options.normalizer === 'function') { + set = get = options.normalizer; } else { - set = get; + get = callable(options.normalizer.get); + if (options.normalizer.set !== undefined) { + set = callable(options.normalizer.set); + del = callable(options.normalizer.delete); + clear = callable(options.normalizer.clear); + } else { + set = get; + } } - } else if (options.serialize) { - set = get = (function (serialize) { - return function (args) { return serialize.apply(null, args); }; - }(callable(options.serialize))); } if (options.resolvers != null) { diff --git a/test/index.js b/test/index.js index f8794ce..a78997d 100644 --- a/test/index.js +++ b/test/index.js @@ -90,9 +90,9 @@ module.exports = function (t, a) { } }; }, - "Serialize": function () { + "Normalizer function": function () { var i = 0, fn = function () { ++i; return join.call(arguments, '|'); }, mfn; - mfn = t(fn, { serialize: Boolean }); + mfn = t(fn, { normalizer: function (args) { return Boolean(args[0]); } }); a(mfn(false, 'raz'), 'false|raz', "#1"); a(mfn(0, 'dwa'), 'false|raz', "#2"); a(i, 1, "Called once");