| 1 |
"use strict"; |
| 2 |
|
| 3 |
var normalizeOpts = require("es5-ext/object/normalize-options") |
| 4 |
, resolveLength = require("./lib/resolve-length") |
| 5 |
, plain = require("./plain"); |
| 6 |
|
| 7 |
module.exports = function (fn/*, options*/) { |
| 8 |
var options = normalizeOpts(arguments[1]), length; |
| 9 |
|
| 10 |
if (!options.normalizer) { |
| 11 |
length = options.length = resolveLength(options.length, fn.length, options.async); |
| 12 |
if (length !== 0) { |
| 13 |
if (options.primitive) { |
| 14 |
if (length === false) { |
| 15 |
options.normalizer = require("./normalizers/primitive"); |
| 16 |
} else if (length > 1) { |
| 17 |
options.normalizer = require("./normalizers/get-primitive-fixed")(length); |
| 18 |
} |
| 19 |
} else if (length === false) options.normalizer = require("./normalizers/get")(); |
| 20 |
else if (length === 1) options.normalizer = require("./normalizers/get-1")(); |
| 21 |
else options.normalizer = require("./normalizers/get-fixed")(length); |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
// Assure extensions |
| 26 |
if (options.async) require("./ext/async"); |
| 27 |
if (options.promise) require("./ext/promise"); |
| 28 |
if (options.dispose) require("./ext/dispose"); |
| 29 |
if (options.maxAge) require("./ext/max-age"); |
| 30 |
if (options.max) require("./ext/max"); |
| 31 |
if (options.refCounter) require("./ext/ref-counter"); |
| 32 |
|
| 33 |
return plain(fn, options); |
| 34 |
}; |