Array filtering utility.
npm install arrayfilter --save
- Accepting By Type
- Accepting By Pattern
- Rejecting Empty Entries
- Rejecting Duplicated Entries
- Rejecting By Pattern
- Rejecting 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']
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']
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']
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']
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']
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']
This software is released under the MIT License.