svgcanvas/utils.js

29 lines
537 B
JavaScript
Raw Permalink Normal View History

2022-02-04 10:05:16 +08:00
const DEBUG = true;
function toString(obj) {
2022-02-04 10:05:16 +08:00
if (!obj) {
return obj
}
if (typeof obj === 'string') {
return obj
}
2022-02-04 10:05:16 +08:00
return obj + '';
}
function debug(...data) {
if (DEBUG) {
console.debug(...data)
}
}
2022-08-22 16:53:26 -07:00
//helper function to format a string
function format(str, args) {
var keys = Object.keys(args), i;
for (i=0; i<keys.length; i++) {
str = str.replace(new RegExp("\\{" + keys[i] + "\\}", "gi"), args[keys[i]]);
}
return str;
}
export {toString, debug, format};