This package has been deprecated

Author message:

Array grouping will become native in ECMAScript soon

split-by-property

2.0.5 • Public • Published

split-by-property

npm license npm downloads total npm license

Split your arrays by a set of given property checks. It runs through your array just once! 🙃

Getting Started

After installing the package:

npm install split-by-property

You can require it like so:

import splitByProperty from 'split-by-property';

And use it this way:

const splitNumbers = splitByProperty((value, i) => ({
  lessThanZero: value < 0,
  equalToZero: value === 0,
  moreThanZero: value > 0,
  evenPosition: (i % 2) === 0,
}));

const splittedNumbers = splitNumbers([4, 0.3, 5, -3.1, 0, 5, 10, -1]);

console.log(splittedNumbers);
// {
//   lessThanZero: [-3.1, -1],
//   equalToZero: [0],
//   moreThanZero: [4, 0.3, 5, 5, 10],
//   evenPosition: [4, 5, 0, 10],
// }

Upgrade from 1.x to 2.x

The package uses now a curried model. Instead of passing the array and the discriminator function directly into the package, you should now pass the discriminator function in to create a function that can receive your array.

Before:

splitByProperty([], () => {});

Now:

splitByProperty(() => {})([]);

License

This project is licensed under the MIT License - see the LICENSE file for details.

Package Sidebar

Install

npm i split-by-property

Weekly Downloads

0

Version

2.0.5

License

MIT

Unpacked Size

4.33 kB

Total Files

4

Last publish

Collaborators

  • oleblaesing