Skip to content

Instantly share code, notes, and snippets.

@realityking
Last active October 24, 2019 13:11
Show Gist options
  • Save realityking/5f29d001ed96f1e9e6a318bb71122508 to your computer and use it in GitHub Desktop.
Save realityking/5f29d001ed96f1e9e6a318bb71122508 to your computer and use it in GitHub Desktop.
node-sass download stats
'use strict';
const json = require('./stats.json');
const table = require('markdown-table');
function getHumanNodeVersion(abi) {
switch (parseInt(abi, 10)) {
case 11: return 'Node 0.10.x';
case 14: return 'Node 0.12.x';
case 42: return 'io.js 1.x';
case 43: return 'io.js 1.1.x';
case 44: return 'io.js 2.x';
case 45: return 'io.js 3.x';
case 46: return 'Node.js 4.x';
case 47: return 'Node.js 5.x';
case 48: return 'Node.js 6.x';
case 49: return 'Electron 1.3.x';
case 50: return 'Electron 1.4.x';
case 51: return 'Node.js 7.x';
case 53: return 'Electron 1.6.x';
case 57: return 'Node.js 8.x';
case 59: return 'Node.js 9.x';
case 63: return 'Node.js 10.x';
default: return false;
}
}
const stats = json.filter(({name}) => name.endsWith('.node')).map(({name, downloadCount}) => {
const [platform, arch, abi] = name.replace('_binding.node', '').split('-');
return {
platform,
arch,
abi,
downloadCount: parseInt(downloadCount, 10)
};
}).reduce((acc, {platform, arch, abi, downloadCount}) => {
if (typeof acc[abi] === 'undefined') {
acc[abi] = 0;
}
acc[abi] += downloadCount;
return acc;
}, {});
const totalDownloads = Object.entries(stats).reduce((acc, [_, count]) => acc += count, 0);
const rows = Object.entries(stats).map(([abi, downloadCount]) => {
return [getHumanNodeVersion(abi), downloadCount.toLocaleString('en'), `${((downloadCount/totalDownloads)*100).toFixed(2)}%`];
});
console.log(table([['Release', 'Download Count', 'Percentage'], ...rows, ['Total', totalDownloads.toLocaleString('en'), '100%']]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment