![Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack](https://cdn.sanity.io/images/cgdhsj6q/production/6af25114feaaac7179b18127c83327568ff592d1-1024x1024.webp?w=800&fit=max&auto=format)
Security News
Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
like-ar
Advanced tools
Readme
Using objects like arrays with map, filter, forEach and others coming soon.
$ npm install like-ar
The function likeAr
wraps an object. The wraped object can be used like an array
with some array functions: forEach
, map
, filter
y join
.
These functions receive a callback in the same way that the array version does.
var likeAr = require('like-ar');
var object={
lastName:'Perez',
firstName:'Diego',
phone:'+45-11-2222-3333'
}
likeAr(object).forEach(function(value, attrName, object){
console.log(attrName,':',value);
});
console.log(
likeAr(object).filter(function(value, attrName){
return attrName.contains('Name');
}).map(function(value,attrName){
return attrName+':'+value
}).join(', ')
);
The callback functions receive these parameters: value
, key
and the original object.
The functions that in the Array case returns Arrays returns a chainable object.
function | returned value |
---|---|
forEach(cb, this) | undefined |
map(cb, this) | chainable object with the same keys and the value mapeds |
filter(db, this) | chainable object with the same keys and values for only that key/value that returns true in the callback function |
join(separator) | string with the join of the values |
array() | array of values |
keys() | array of keys |
plain() | plain object without likeAr functions |
Builds a new object with new keys.
The callback function must return a {key: value}
object to compose the final result.
var pairs=[{field:'lastName', value:'Perez'}, {field:'firstName', value:'Diego'}];
console.log(likeAr(pairs).build(funciton(pair){ return {[pair.field]: pair.value}; ));
// {lastName: "Perez", firstName: "Diego"}
var toJoin=[{lastName:'Perez'}, {firstName:'Diego'}];
console.log(likeAr(toJoin).build(funciton(objectWithOneKey){ return objectWithOneKey; ));
// {lastName: "Perez", firstName: "Diego"}
Returns a plain object from an array of pairs (or a pair of arrays) of key/values.
Default values: 0
and 1
if keyName
is not set. "value"
for valueName
if keyName
is set.
var likeAr = require('like-ar');
var pairs=[['lastName', 'Perez'], ['firstName', 'Diego']];
console.log(likeAr.toPlainObject(pairs));
var pairs=[{field:'lastName', value:'Perez'}, {field:'firstName', value:'Diego'}];
console.log(likeAr.toPlainObject(pairs, 'field'));
Returns a plain object containing the same element indexed by keyName
var likeAr = require('like-ar');
var persons=[{name:'Diego', lastName:'Rivera', age:30}, {name:'Frida', lastName:'Kahlo'}];
var idxPersons=likeAr.createIndex(persons, 'lastName');
idxPersons.Kahlo.age=20;
console.log(persons[1].age); // 20
FAQs
Using objects like arrays with map, filter, forEach and others coming soon.
The npm package like-ar receives a total of 195 weekly downloads. As such, like-ar popularity was classified as not popular.
We found that like-ar demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers 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
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.
Security News
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.