index.js 571 B

1234567891011121314151617181920212223242526272829
  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. };