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.

50 lines
1.5 KiB

4 years ago
  1. # Array Flatten
  2. [![NPM version][npm-image]][npm-url]
  3. [![NPM downloads][downloads-image]][downloads-url]
  4. [![Build status][travis-image]][travis-url]
  5. [![Test coverage][coveralls-image]][coveralls-url]
  6. > Flatten nested arrays.
  7. ## Installation
  8. ```
  9. npm install array-flatten --save
  10. ```
  11. ## Usage
  12. ```javascript
  13. var flatten = require('array-flatten')
  14. flatten([1, [2, [3, [4, [5], 6], 7], 8], 9])
  15. //=> [1, 2, 3, 4, 5, 6, 7, 8, 9]
  16. flatten.depth([1, [2, [3, [4, [5], 6], 7], 8], 9], 2)
  17. //=> [1, 2, 3, [4, [5], 6], 7, 8, 9]
  18. (function () {
  19. flatten.from(arguments) //=> [1, 2, 3]
  20. })(1, [2, 3])
  21. ```
  22. ### Methods
  23. * **flatten(array)** Flatten a nested array structure
  24. * **flatten.from(arrayish)** Flatten an array-like structure (E.g. arguments)
  25. * **flatten.depth(array, depth)** Flatten a nested array structure with a specific depth
  26. * **flatten.fromDepth(arrayish, depth)** Flatten an array-like structure with a specific depth
  27. ## License
  28. MIT
  29. [npm-image]: https://img.shields.io/npm/v/array-flatten.svg?style=flat
  30. [npm-url]: https://npmjs.org/package/array-flatten
  31. [downloads-image]: https://img.shields.io/npm/dm/array-flatten.svg?style=flat
  32. [downloads-url]: https://npmjs.org/package/array-flatten
  33. [travis-image]: https://img.shields.io/travis/blakeembrey/array-flatten.svg?style=flat
  34. [travis-url]: https://travis-ci.org/blakeembrey/array-flatten
  35. [coveralls-image]: https://img.shields.io/coveralls/blakeembrey/array-flatten.svg?style=flat
  36. [coveralls-url]: https://coveralls.io/r/blakeembrey/array-flatten?branch=master