nci/lib/utils.js

27 lines
547 B
JavaScript
Raw Normal View History

2014-12-02 21:21:07 +00:00
'use strict';
2015-10-15 22:52:23 +00:00
var _ = require('underscore'),
sharedUtils = require('../static/js/shared/utils');
2015-05-07 19:03:57 +00:00
2015-10-15 22:52:23 +00:00
_(exports).extend(sharedUtils);
2015-10-03 14:14:41 +00:00
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);
};
2016-01-09 13:35:33 +00:00
exports.toPrettyJson = function(data) {
return JSON.stringify(data, function(key, value) {
if (_(value).isRegExp()) {
return 'RegExp ' + String(value);
} else {
return value;
}
}, 4);
};