dynamicsmobile
Version:
Allows development of off-line mobile and web business apps over the Dynamics Mobile platform. More info on https://www.dynamicsmobile.com
57 lines • 2.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Tools = void 0;
class Tools {
static formatString(mask, value) {
var args = arguments;
if (value == undefined || value == null)
return "";
if (!mask)
return value.toString();
return mask.replace(/{(\d+)(:?)(0*)}/g, function (match, number) {
var index = parseInt(number) + 1;
if (match.indexOf(':') >= 0) {
var tokens = match.substring(1, match.length - 1).split(':');
return (typeof args[index] != 'undefined' ? args[index].toString().padStart(tokens[1].length, '0') : '{' + index + '}');
}
else {
return (typeof args[index] != 'undefined' ? args[index] : '{' + index + '}');
}
});
}
static formatDateToSqlite(v) {
return v.getFullYear().toString().padStart(2, '0') +
"-" + (v.getMonth() + 1).toString().padStart(2, '0') +
"-" + v.getDate().toString().padStart(2, '0') +
" " + v.getHours().toString().padStart(2, '0') +
":" + v.getMinutes().toString().padStart(2, '0') +
":" + v.getSeconds().toString().padStart(2, '0');
}
static escapeStringForJson(s) {
if (!s)
return s;
if (typeof (s) !== 'string')
return s;
//s = s.replace(/\u0009/g,' ').replace(/"/g,'\"').replace(//);
return s.replace(/[\\]/g, '\\\\')
.replace(/[\"]/g, '\\\"')
.replace(/[\/]/g, '\\/')
.replace(/[\b]/g, '\\b')
.replace(/[\f]/g, '\\f')
.replace(/[\n]/g, '\\n')
.replace(/[\r]/g, '\\r')
.replace(/[\t]/g, ' ');
}
static asureInt(v) {
let d = v;
if (typeof (v) === 'string') {
d = parseInt(v);
}
if (isFinite(d))
return d;
else
return 0;
}
}
exports.Tools = Tools;
//# sourceMappingURL=tools.js.map