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.

39 lines
1.2 KiB

4 years ago
  1. # simple-swizzle [![Travis-CI.org Build Status](https://img.shields.io/travis/Qix-/node-simple-swizzle.svg?style=flat-square)](https://travis-ci.org/Qix-/node-simple-swizzle) [![Coveralls.io Coverage Rating](https://img.shields.io/coveralls/Qix-/node-simple-swizzle.svg?style=flat-square)](https://coveralls.io/r/Qix-/node-simple-swizzle)
  2. > [Swizzle](https://en.wikipedia.org/wiki/Swizzling_(computer_graphics)) your function arguments; pass in mixed arrays/values and get a clean array
  3. ## Usage
  4. ```js
  5. var swizzle = require('simple-swizzle');
  6. function myFunc() {
  7. var args = swizzle(arguments);
  8. // ...
  9. return args;
  10. }
  11. myFunc(1, [2, 3], 4); // [1, 2, 3, 4]
  12. myFunc(1, 2, 3, 4); // [1, 2, 3, 4]
  13. myFunc([1, 2, 3, 4]); // [1, 2, 3, 4]
  14. ```
  15. Functions can also be wrapped to automatically swizzle arguments and be passed
  16. the resulting array.
  17. ```js
  18. var swizzle = require('simple-swizzle');
  19. var swizzledFn = swizzle.wrap(function (args) {
  20. // ...
  21. return args;
  22. });
  23. swizzledFn(1, [2, 3], 4); // [1, 2, 3, 4]
  24. swizzledFn(1, 2, 3, 4); // [1, 2, 3, 4]
  25. swizzledFn([1, 2, 3, 4]); // [1, 2, 3, 4]
  26. ```
  27. ## License
  28. Licensed under the [MIT License](http://opensource.org/licenses/MIT).
  29. You can find a copy of it in [LICENSE](LICENSE).