mirror of
https://github.com/BorysLevytskyi/BitwiseCmd.git
synced 2025-12-10 06:52:05 +01:00
33 lines
764 B
JavaScript
33 lines
764 B
JavaScript
app.set("formatter", function() {
|
|
"use strict";
|
|
|
|
var should = app.get('should');
|
|
var is = app.get('is');
|
|
|
|
return {
|
|
formatString: function(num, kind) {
|
|
return num.toString(getBase(kind || "bin"));
|
|
},
|
|
padLeft: function (str, length, symbol) {
|
|
var sb = Array.prototype.slice.call(str), symbol = symbol || "0";
|
|
|
|
if(length == null) {
|
|
return str;
|
|
}
|
|
|
|
while(length > sb.length) {
|
|
sb.unshift(symbol);
|
|
}
|
|
|
|
return sb.join('');
|
|
}
|
|
};
|
|
|
|
function getBase(kind) {
|
|
switch (kind){
|
|
case 'bin': return 2;
|
|
case 'hex': return 16;
|
|
case 'dec': return 10;
|
|
}
|
|
}
|
|
}); |