Skip to content

Instantly share code, notes, and snippets.

@christophercliff
Created December 19, 2013 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christophercliff/8046040 to your computer and use it in GitHub Desktop.
Save christophercliff/8046040 to your computer and use it in GitHub Desktop.
How much code did you write compared to code installed with npm?
#!/usr/bin/env node
var stdin = process.openStdin()
var data = ''
stdin
.on('data', function(chunk) {
data += chunk
})
.on('end', function(){
parse(data)
})
function parse(data) {
var mine = 0
var theirs = 0
var total = 0
var length
data = JSON.parse(data)
for (var key in data) {
length = data[key].source.length
if (data[key].id.indexOf('node_modules') < 0) {
mine += length
} else {
theirs += length
}
total += length
}
console.log('mine: ' + percentify(mine, total) + '%, theirs: ' + percentify(theirs, total) + '%')
}
function percentify(val, total) {
return Math.round(val/total*100)
}
@christophercliff
Copy link
Author

Use with Browserify:

$ browserify ./your-lib.js --deps | ./compare.js

Outputs:

mine: 20%, theirs: 80%

@christophercliff
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment