Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
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`
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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.