Comparing version 0.1.5 to 0.2.0
{ | ||
"name": "wodge", | ||
"version": "0.1.5", | ||
"version": "0.2.0", | ||
"description": "a wodge of functional dough", | ||
@@ -5,0 +5,0 @@ "main": "wodge.js", |
86
wodge.js
@@ -18,62 +18,2 @@ "use strict"; | ||
var ansi = { | ||
black: 30, | ||
red: 31, | ||
green: 32, | ||
yellow: 33, | ||
blue: 34, | ||
magenta: 35, | ||
cyan: 36, | ||
white: 37, | ||
bold: 1, | ||
underline: 4 | ||
}; | ||
var ansiFormat = "\x1b[%sm%s\x1b[0m"; | ||
exports.black = function(txt){ | ||
return util.format(ansiFormat, ansi.black, txt); | ||
}; | ||
exports.red = function(txt){ | ||
return util.format(ansiFormat, ansi.red, txt); | ||
}; | ||
exports.green = function(txt){ | ||
return util.format(ansiFormat, ansi.green, txt); | ||
}; | ||
exports.yellow = function(txt){ | ||
return util.format(ansiFormat, ansi.yellow, txt); | ||
}; | ||
exports.blue = function(txt){ | ||
return util.format(ansiFormat, ansi.blue, txt); | ||
}; | ||
exports.magenta = function(txt){ | ||
return util.format(ansiFormat, ansi.magenta, txt); | ||
}; | ||
exports.cyan = function(txt){ | ||
return util.format(ansiFormat, ansi.cyan, txt); | ||
}; | ||
exports.white = function(txt){ | ||
return util.format(ansiFormat, ansi.white, txt); | ||
}; | ||
exports.bold = function(txt){ | ||
return util.format(ansiFormat, ansi.bold, txt); | ||
}; | ||
exports.underline = function(txt){ | ||
return util.format(ansiFormat, ansi.underline, txt); | ||
}; | ||
/** | ||
Add multiple ansi formats | ||
@method ansi | ||
@example | ||
ansi("hello", "bold", "underline"); | ||
ansi("success", "green", "bold"); | ||
*/ | ||
exports.ansi = function(){ | ||
var args = exports.array(arguments), | ||
txt = args.shift(), | ||
codes = args.map(function(arg){ return ansi[arg]; }); | ||
return util.format(ansiFormat, codes.join(";"), txt); | ||
}; | ||
exports.pluck = function(object, fn){ | ||
@@ -131,1 +71,27 @@ var output = []; | ||
} | ||
exports.bytesToSize = function(bytes, precision){ | ||
var kilobyte = 1024; | ||
var megabyte = kilobyte * 1024; | ||
var gigabyte = megabyte * 1024; | ||
var terabyte = gigabyte * 1024; | ||
if ((bytes >= 0) && (bytes < kilobyte)) { | ||
return bytes + ' B'; | ||
} else if ((bytes >= kilobyte) && (bytes < megabyte)) { | ||
return (bytes / kilobyte).toFixed(precision) + ' KB'; | ||
} else if ((bytes >= megabyte) && (bytes < gigabyte)) { | ||
return (bytes / megabyte).toFixed(precision) + ' MB'; | ||
} else if ((bytes >= gigabyte) && (bytes < terabyte)) { | ||
return (bytes / gigabyte).toFixed(precision) + ' GB'; | ||
} else if (bytes >= terabyte) { | ||
return (bytes / terabyte).toFixed(precision) + ' TB'; | ||
} else { | ||
return bytes + ' B'; | ||
} | ||
}; |
2851
79