Skip to content

Instantly share code, notes, and snippets.

@jbreckmckye
Last active May 16, 2016 14:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbreckmckye/1a46f550ad1209ab00d2da0d0a363933 to your computer and use it in GitHub Desktop.
Save jbreckmckye/1a46f550ad1209ab00d2da0d0a363933 to your computer and use it in GitHub Desktop.
var myFileName = 'commercial.js';
var fs = require('fs');
var input = fs.createReadStream(myFileName);
var text = '';
input.on('data', function (data) {
text += data;
});
input.on('end', function () {
var defineBlock = /define\(["'][^"']*["']/g;
var keys = text.match(defineBlock);
var bodies = text.split(defineBlock);
bodies.shift();
var blocks = keys.map(function (key, index) {
return {
key : key.split('define(')[1],
body : bodies[index],
length : bodies[index].length
};
});
var blocksBySize = blocks.sort(function (a, b) {
if (a.length > b.length) {
return 1;
}
if (a.length < b.length) {
return -1;
}
return 0;
}).reverse();
console.log(blocksBySize.map(function (block) {
return block.length + ' chars in ' + block.key;
}).join('\n'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment