Skip to content

Instantly share code, notes, and snippets.

@DeadAlready
Last active May 12, 2016 14:29
Show Gist options
  • Save DeadAlready/4ba1f9e1d1ba67838c7f10904a18d18b to your computer and use it in GitHub Desktop.
Save DeadAlready/4ba1f9e1d1ba67838c7f10904a18d18b to your computer and use it in GitHub Desktop.
Mask functions
function maskVersion(version) {
let newVersion = {};
[
'_id',
'name',
'version',
'scripts',
'engines',
'dist',
'main',
'dependencies',
'devDependencies',
'optionalDependencies',
'bundledDependencies'
].forEach(key => {
if(version[key]) {
newVersion[key] = version[key];
}
});
newVersion.dist.tarball = newVersion.dist.tarball.replace('https://registry.npmjs.org', 'http://localhost:3000');
return newVersion;
}
function mask(obj) {
let newObj = {};
['_id','name', 'dist-tags'].forEach(prop => {
newObj[prop] = obj[prop];
});
newObj.versions = {};
Object.keys(obj.versions).forEach(key => {
newObj.versions[key] = maskVersion(obj.versions[key]);
});
return newObj;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment