lodash-purge

1.0.0 • Public • Published

Lodash purge

Build Status Known Vulnerabilities NPM version

Extend Lodash to take a deep copy of an array, remove all elements that predicate returns truthy for, and return the new array with the elements removed. The original array is left unchanged.
This is similar to remove (and in fact makes use of that function) but is intended to be used in place of that function with Vue.js to overcome problems with remove in that situation.

_.purge(arr, predicate)

Arguments
arr (array): The array of objects to have elements removed. Required.
predicate (string): The function invoked per iteration. Required. purge makes use of the Lodash function remove so predicate must follow the rules and structure documented for that function.

Returns
(array): An new array with the specified elements removed.

Examples

var _ = require('lodash')
require('lodash-purge')

_.purge([{a:12, b:5}, {a: 6}, {a: 12, b:999}], function(obj) {return obj.a === 12 || obj.b === 999;}); // [{a: 6}]
_.purge(['ABC','DEF','GHI','ABC'], function(val) {return val === 'ABC'); // ['DEF','GHI']
_.purge([], function(val) {return val === 'ABC'); // []
_.purge([{a:12, b:5}, {a: 6}, {a: 12, b:999}], function(obj) {return obj.z === 'OK'}); // [{a:12, b:5}, {a: 6}, {a: 12, b:999}]

Version History

Version Release Date Details
1.0.0 1st March, 2018 Initial release.

/lodash-purge/

    Package Sidebar

    Install

    npm i lodash-purge

    Weekly Downloads

    0

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    5.63 kB

    Total Files

    7

    Last publish

    Collaborators

    • davidwaterston