secst
Version:
SECST is a semantic, extensible, computational, styleable tagged markup language. You can use it to joyfully create compelling, interactive documents backed by HTML.
17 lines (15 loc) • 627 B
JavaScript
import JSON5 from "json5";
const formatValue = async (el,value) => {
const template = el.getAttribute("data-format");
if(template) {
return (new Function("value","return `" + template + "`"))(new String((value!=null ? value : await el.rawValue+"").replace(/\$/g,"\$")))
} else if(el.getAttribute("data-mime-type")==="application/json") {
try {
return JSON.stringify(JSON5.parse(value !=null ? value : await el.rawValue), null, 2);
} catch(e) {
//console.error(e);
}
}
return value!=null ? value : el.rawValue;
};
export {formatValue}