nci/lib/utils.js
2016-01-09 16:35:33 +03:00

27 lines
547 B
JavaScript

'use strict';
var _ = require('underscore'),
sharedUtils = require('../static/js/shared/utils');
_(exports).extend(sharedUtils);
exports.lpad = function(str, length, chr) {
chr = chr || '0';
while (str.length < length) str = chr + str;
return str;
};
exports.toNumberStr = function(number) {
return exports.lpad(String(number), 20);
};
exports.toPrettyJson = function(data) {
return JSON.stringify(data, function(key, value) {
if (_(value).isRegExp()) {
return 'RegExp ' + String(value);
} else {
return value;
}
}, 4);
};