项目作者: supercharge

项目描述 :
Array utilities for Node.js
高级语言: JavaScript
项目地址: git://github.com/supercharge/arrays.git
创建时间: 2020-10-17T18:31:33Z
项目社区:https://github.com/supercharge/arrays

开源协议:MIT License

下载











Arrays




Array utilities for JavaScript and Node.js





Installation ·
Docs ·
Usage







Latest Version
Monthly downloads



Follow @marcuspoehls and @superchargejs for updates!



Introduction

The @supercharge/arrays package provides chainable array utilities for Node.js and JavaScript. It’s a wrapper around JavaScript arrays providing useful methods like .isEmpty(), .length(), .flatMap(), .contains(), and many more.

Installation

  1. npm i @supercharge/arrays

Docs

Find all the details for @supercharge/arrays in the extensive Supercharge docs.

Usage

Using @supercharge/arrays is pretty straightforward. The package exports a function wrapping an array or individual items as an argument. You can then fluently chain methods interacting with your data:

  1. const { Arr } = require('@supercharge/arrays')
  2. const users = Arr.from([])
  3. users.isEmpty()
  4. // true
  5. users
  6. .push({ id: 1, name: 'Marcus' })
  7. .push({ id: 2, name: 'Norman' })
  8. .push({ id: 3, name: 'Christian' })
  9. users.isNotEmpty()
  10. // true
  11. users.length()
  12. // 3
  13. const usernamesArray = users
  14. .map(user => user.name)
  15. .toArray()
  16. // [ 'Marcus', 'Norman', 'Christian' ]
  17. const marcus = users.find(user => {
  18. return user.name === 'Marcus'
  19. })
  20. // { id: 1, name: 'Marcus' }

Every method in the chain returns a @supercharge/array instance. This way, you can chain further methods without leaving the fluent interface. Call .all() to retrieve the plain JavaScript array.

Contributing

Do you miss a function? We very much appreciate your contribution! Please send in a pull request 😊

  1. Create a fork
  2. Create your feature branch: git checkout -b my-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request 🚀

License

MIT © Supercharge


superchargejs.com ·
GitHub @supercharge ·
Twitter @superchargejs