Last active
May 12, 2016 14:29
-
-
Save DeadAlready/4ba1f9e1d1ba67838c7f10904a18d18b to your computer and use it in GitHub Desktop.
Mask functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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