UNPKG

dir_tree

Version:

Creates a Searchable, Sortable & Printable Tree For Stated Directory Path.

34 lines (33 loc) 1.08 kB
var err = module.exports.err = function(msg) { console.log(msg); process.exit(-1); }; var sep_at_thousands = module.exports.sep_at_thousands = function(number) { return number.toLocaleString('en-US'); }; var countify = module.exports.countify = function(number, singular, plural) { return sep_at_thousands(number) + ' ' + (number === 1 ? singular : plural); }; var sizify = module.exports.sizify = function(number) { var str = countify(number, 'Byte', 'Bytes'); var suffixes = [' KB', ' MB', ' GB', ' TB']; while (number /= 1024, Math.floor(number) > 0) str += ' | ' + sep_at_thousands(number) + suffixes.shift(); return str; }; var countify_dirs = module.exports.countify_dirs = function(number) { return countify(number, 'Dir', 'Dirs'); }; var countify_files = module.exports.countify_files = function(number) { return countify(number, 'File', 'Files'); }; var countify_paths = module.exports.countify_paths = function(number) { return countify(number, 'Path', 'Paths'); };