index.js 1.2 KB

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