Skip to content

okunishinishi/node-arrayfilter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

arrayfilter

Build Status Code Climate Code Coverage npm Version

Array filtering utility.

Installation

npm install arrayfilter --save

Usage

Accepting By Type

arrayfilter.typeAccept(type) create a function which accepts entries by type matching.

"use strict";

const arrayfilter = require('arrayfilter');

// Define a filter function.
let acceptString = arrayfilter.typeAccept('string');

// Execute filtering.
let values = ['foo', {}, 123].filter(acceptString);
console.log(values); // -> ['foo']

Accepting By Pattern

arrayfilter.patternAccept(pattern) create a function which accepts entries by regex (or string) matching.

"use strict";

const arrayfilter = require('arrayfilter');

// Define a filter function.
let acceptFo = arrayfilter.patternAccept(/^fo/);

// Execute filtering.
let values = ['foo', 'bar', 'baz'].filter(acceptFo);
console.log(values); // -> ['foo']

Rejecting Empty Entries

arrayfilter.emptyReject() create a function which rejects empty with rejects null, undefined and empty string.

"use strict";

const arrayfilter = require('arrayfilter');

// Define a filter function.
let rejectEmpty = arrayfilter.emptyReject();

// Execute filtering.
let values = ['foo', '', null, 'bar', undefined].filter(rejectEmpty);
console.log(values); // -> ['foo', 'bar']

Rejecting Duplicated Entries

arrayfilter.duplicateReject() create a function which rejects empty with rejects null, undefined and empty string.

"use strict";

const arrayfilter = require('arrayfilter');

// Define a filter function.
let duplicateReject = arrayfilter.duplicateReject();

// Execute filtering.
let values = ['foo', 'bar', 'foo'].filter(duplicateReject);
console.log(values); // -> ['foo', 'bar']

Rejecting By Pattern

arrayfilter.patternReject(pattern) create a function which rejects entries by regex (or string) matching.

"use strict";

const arrayfilter = require('arrayfilter');

// Define a filter function.
let rejectFo = arrayfilter.patternReject(/^fo/);

// Execute filtering.
let values = ['foo', 'bar', 'baz'].filter(rejectFo);
console.log(values); // -> ['bar', 'baz']

Rejecting By Type

arrayfilter.typeReject(type) create a function which rejects entries by type matching.

"use strict";

const arrayfilter = require('arrayfilter');

// Define a filter function.
let rejectString = arrayfilter.typeReject('object');

// Execute filtering.
let values = ['foo', {}, {}].filter(rejectString);
console.log(values); // -> ['foo']

License

This software is released under the MIT License.

Links