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.

README.md 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # flat-util [![Build Status](https://travis-ci.com/jonkemp/flat-util.svg?branch=master)](https://travis-ci.com/jonkemp/flat-util)
  2. > Flatten a nested array.
  3. The nesting can be to any depth. If you pass shallow, the array will only be flattened one level.
  4. ## Features
  5. - Small utility to flatten nested arrays.
  6. - Free of TypeScript. 😄
  7. ## Install
  8. Install with [npm](https://npmjs.org/package/flat-util)
  9. ```
  10. $ npm install flat-util
  11. ```
  12. Or [unpkg](https://unpkg.com/flat-util/)
  13. ```
  14. <script src="https://unpkg.com/flat-util@1.1.4/umd/index.js" />
  15. ```
  16. Check out the unit tests on [CodePen](https://codepen.io/jonkemp/full/YzPBmwz).
  17. ## Usage
  18. ```js
  19. const flatten = require('flat-util');
  20. flatten([1, 2, [3, 4]]);
  21. //=> [1, 2, 3, 4]
  22. flatten([1, [2], [3, [[4]]]]);
  23. //=> [1, 2, 3, 4];
  24. flatten([1, [2], [3, [[4]]]], true);
  25. //=> [1, 2, 3, [[4]]];
  26. ```
  27. ---
  28. | **Like us a lot?** Help others know why you like us! **Review this package on [pkgreview.dev](https://pkgreview.dev/npm/flat-util)** | ➡ | [![Review us on pkgreview.dev](https://i.ibb.co/McjVMfb/pkgreview-dev.jpg)](https://pkgreview.dev/npm/flat-util) |
  29. | ----------------------------------------------------------------------------------------------------------------------------------------- | --- | --------------------------------------------------------------------------------------------------------------------- |
  30. ## API
  31. ### flatten(input, shallow)
  32. #### input
  33. Type: `array`
  34. Default: `none`
  35. The array to flatten.
  36. #### shallow
  37. Type: `boolean`
  38. Default: `false`
  39. Whether or not to flatten the array only one level.
  40. ## License
  41. MIT