Skip to content

Instantly share code, notes, and snippets.

@robballou
Created November 19, 2015 17:30
Show Gist options
  • Save robballou/9eb01f8a60a14115420f to your computer and use it in GitHub Desktop.
Save robballou/9eb01f8a60a14115420f to your computer and use it in GitHub Desktop.
Output data scratch script (node js)
// 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