Created
November 19, 2015 17:30
-
-
Save robballou/9eb01f8a60a14115420f to your computer and use it in GitHub Desktop.
Output data scratch script (node js)
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
// Reads stdin and divides that into the output trasnform | |
// | |
// Usage: pbpaste | node output_data.js | pbcopy | |
var _ = require('lodash'); | |
process.stdin.setEncoding('utf8'); | |
var data = []; | |
process.stdin.on('readable', function() { | |
var chunk = process.stdin.read(); | |
if (chunk !== null) { | |
var thisData = chunk.split(/\n/); | |
_.each(thisData, function(dataChunk) { | |
data.push(dataChunk); | |
}); | |
} | |
}); | |
process.stdin.on('end', function() { | |
var start = 2005; | |
var output = []; | |
_.each(data, function(chunk) { | |
chunk = chunk.replace('%', ''); | |
if (!chunk) { | |
return; | |
} | |
output.push("'" + start + "': " + chunk) | |
start++; | |
}); | |
var length = output.length; | |
output = output.map(function(current, index, arr) { | |
if (index == (length - 1)) { | |
return current; | |
} | |
return current + ','; | |
}); | |
process.stdout.write(output.join("\n") + "\n"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment