Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
explicit-object-mapper-ng
Advanced tools
allows mapping of named fields between javascript objects with optional transforms
Map named fields from one json object to another with optional transforms. Any fields not named in the map will not be copied to the destination object. This is a hard fork from https://github.com/opentable/explicitobjectmap-node which now appears to have no maintainers.
Mappings consist of a simple javascript array containing mapping instructions:
[
'simpleA', //will just copy accross the field
'simpleB',
'simpleC',
'simpleD',
{'oldname':'newname'}, //will rename the field from oldname to newname
{ //will rename the field then run the custom tranform on the result
srcName:'complexoldname',
dstName:'complexnewname',
customTransform: function (srcObj, val){
return val.toUpperCase();
}
},
{ //will rename the field then run the mapper on that value. This allows embedding mappers inside mappers
srcName:'sourceobjectname',
dstName:'newname',
mapper: explicitMapper(['simpleE'])
},
{'deep.childA': 'baby'}, //dot notation is currently only supported when renaming fields
function(srcObj,dstObj){
dstObj.CustomField = 'whatever'; //post mapping function ran after all the other maps are ran
}
]
npm install explicit-object-mapper-ng
const explicitObjectMapper = require('explicit-object-mapper-ng');
const mapObj =
[
'simpleA',
{'oldname':'myVal'},
];
const srcObj = {
simpleA: 'alpha',
oldname: 'changedName'
};
const mapper = explicitObjectMapper.createMapper(mapObj);
const dstObj = mapper.map(srcObj);
The output from the above would be:
{
simpleA: 'alpha',
changedName: 'myVal'
}
If an array of objects is passed in then all objects will be mapped and returned in an array.
There is some overhead to the mapping process depending on map size and the amount of source data; this can be mitigated a little by creating the mappings ahead of time and reusing them. That said, on my machine the benchmark script, when ran on my machine runs the "basic map" benchmark in 369ms, thats 10 million maps.
Now needs node > 4.2 Uses es6 features to clean up codebase
We can now add mappers inside maps, for example:
const objectToMap = { Name: { First: 'Bob', Last: 'Smith' }};
const childMap = ['Firstname'];
const rootMap = [
{
srcName:'Name',
dstName:'IncompleteName',
mapper: childMap
}
];
const mappedObject = rootMap.map(objectToMap); // { IncompleteName: { Firstname: 'Bob' } }
map can be called with an optional options variable:
mapper.map(srcObj, {myVal: true, myOtherVal:'biscuit'});
This object is then passed into any custom mapping functions:
[
'simpleA',
{'oldname':'newname'},
{
srcName:'complexoldname',
dstName:'complexnewname',
customTransform: function (srcObj, val, options){
return val.toUpperCase() + options.myOtherVal;
}
},
function(srcObj,dstObj, options){
dstObj.CustomField = 'whatever'; //post mapping function ran after all the other maps are ran
}
]
Null values were still not handled properly; They will now get mapped
previously if a source value could be evaluated as false (null, 0, false) then the relevant field would not be mapped, now the field is mapped as long as the source field exists
FAQs
allows mapping of named fields between javascript objects with optional transforms
The npm package explicit-object-mapper-ng receives a total of 0 weekly downloads. As such, explicit-object-mapper-ng popularity was classified as not popular.
We found that explicit-object-mapper-ng 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 researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.