arrayfilter

Array filtering utility.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
arrayfilter
101.1.27 years ago7 years agoMinified + gzip package size for arrayfilter in KB

Readme

arrayfilter


!Build Statusbdtravisshieldurlbdtravisurl !Code Climatebdcodeclimateshieldurlbdcodeclimateurl !Code Coveragebdcodeclimatecoverageshieldurlbdcodeclimateurl !npm Versionbdnpmshieldurlbdnpmurl


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