2.0.5 • Published 3 years ago

split-by-property v2.0.5

Weekly downloads
2
License
MIT
Repository
github
Last release
3 years ago

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.

2.0.5

3 years ago

2.0.4

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

4 years ago

2.0.0

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago