Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
callback-pluck
Advanced tools
Use callback-pluck instead of
_.pluck
Callback pluck is a callback generator with clean API for ES5 iterations methods.
It allows you to use _.pluck
idea in more clean way via generating required
callbacks for iteration methods (map
, filter
, every
and some
).
Use es6 arrow functions instead, they are native and simpler solution.
arr.map(p('age')); // [36, 40, 22, 22]
arr.map(i => i.age); // [36, 40, 22, 22]
npm install --save-dev callback-pluck
var p = require('callback-pluck');
var arr = [
{ 'name': 'Barney', 'age': 36, sex: 'male', married: true },
{ 'name': 'Fred', 'age': 40, sex: 'male', married: true },
{ 'name': 'Glenn', 'age': 22, sex: 'male', married: false },
{ 'name': 'Stephen', 'age': 22, sex: 'male', married: true }
];
[ ].map
arr.map(p('name')); // ['Barney', 'Fred', 'Glenn', 'Stephen']
arr.map(p('age')); // [36, 40, 22, 22]
[ ].filter
Simple filtering with string parameter:
arr.filter(p('married')); // [{ 'name': 'Barney', …, married: true },
// { 'name': 'Fred', ¬, married: true },
// { 'name': 'Stephen', …, married: true }]
Simple filtering with string parameter and additional false
parameter:
arr.filter(p('married', false)); // { 'name': 'Glenn', …, married: false },
Advanced filtering via property value:
arr.filter(p({ age: 22 })); // [{ 'name': 'Glenn', 'age': 22, … },
// { 'name': 'Stephen', 'age': 22, … }]
Advanced negative filtering via property value and additional false
parameter:
arr.filter(p({ age: 22 }, false)); // [{ 'name': 'Barney', 'age': 36, … },
// { 'name': 'Fred', 'age': 40, … }]
[ ].every
arr.every(p('married')); // false
arr.every(p({ sex: 'male' })); // true
arr.every(p({ married: true })); // false
[ ].some
arr.some(p('married')); // true
arr.some(p({ married: true })); // true
arr.some(p({ name: 'Barney' })); // true
arr.some(p({ sex: 'female' })); // false
Advanced filtering via property value doesn't do deep equal, It take only
first property from Object.keys(inputObject)
to keep logic clean and simple.
MIT © Vladimir Starkov
FAQs
Use callback-pluck instead of `_.pluck`
The npm package callback-pluck receives a total of 1 weekly downloads. As such, callback-pluck popularity was classified as not popular.
We found that callback-pluck demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.