You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
571 B

4 years ago
  1. 'use strict';
  2. var isArrayish = require('is-arrayish');
  3. var concat = Array.prototype.concat;
  4. var slice = Array.prototype.slice;
  5. var swizzle = module.exports = function swizzle(args) {
  6. var results = [];
  7. for (var i = 0, len = args.length; i < len; i++) {
  8. var arg = args[i];
  9. if (isArrayish(arg)) {
  10. // http://jsperf.com/javascript-array-concat-vs-push/98
  11. results = concat.call(results, slice.call(arg));
  12. } else {
  13. results.push(arg);
  14. }
  15. }
  16. return results;
  17. };
  18. swizzle.wrap = function (fn) {
  19. return function () {
  20. return fn(swizzle(arguments));
  21. };
  22. };