https://github.com/aliencreations/alien-node-list-utils
Collection of array helpers.
https://github.com/aliencreations/alien-node-list-utils
Last synced: 10 months ago
JSON representation
Collection of array helpers.
- Host: GitHub
- URL: https://github.com/aliencreations/alien-node-list-utils
- Owner: AlienCreations
- License: mit
- Created: 2016-03-30T19:18:06.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2023-09-13T21:25:39.000Z (over 2 years ago)
- Last Synced: 2025-05-09T00:12:53.381Z (10 months ago)
- Language: JavaScript
- Size: 21.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# alien-node-list-utils
Helper functions for arrays on NodeJS. The functions are pure and curried with Ramda.
[](https://travis-ci.org/AlienCreations/alien-node-list-utils) [](https://coveralls.io/github/AlienCreations/alien-node-list-utils?branch=master) [](https://npmjs.org/package/alien-node-list-utils) [](https://david-dm.org/AlienCreations/alien-node-list-utils)
## Install
```
$ npm install alien-node-list-utils --save
```
Run the specs
```
$ npm test
```
## Methods
#### filterOutItem
Given a list and an item, returns a copy of the list absent said item.
```js
var listUtils = require('alien-node-list-utils'),
list = ['a', 'b', 'c', 'd'];
listUtils.filterOutItem('b', list); // ['a', 'c', 'd']
```
#### filterOutObject
Given a key, value, and list, returns a copy of the list absent the object(s) which match said k/v pair.
```js
var listUtils = require('alien-node-list-utils'),
list = [{ foo : 'bar'}, {baz : 'bat'}, {buz : 'but'}];
listUtils.filterOutObject('baz', 'bat', list); // [{ foo : 'bar'}, {buz : 'but'}]
```
#### maybeDropLastItem
Given a qualifying drop length and a list, returns a new list who's last item is dropped if the list
length exceeds or equals provided drop length
```js
var listUtils = require('alien-node-list-utils'),
list1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'],
list2 = ['x', 'y', 'z'];
listUtils.maybeDropLastItem(5, list1); // ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']
listUtils.maybeDropLastItem(5, list2); // ['x', 'y', 'z']
```
#### sortAsc
Simple ascending sorter function
```js
var listUtils = require('alien-node-list-utils'),
list = ['b', 'd', 'a', 'c'];
listUtils.sortAsc(list1); // ['a', 'b', 'c', 'd']
```
#### sortDesc
Simple descending sorter function
```js
var listUtils = require('alien-node-list-utils'),
list = ['b', 'd', 'a', 'c'];
listUtils.sortDesc(list1); // ['d', 'c', 'b', 'a']
```