lakutata
Version:
An IoC-based universal application framework.
65 lines (57 loc) • 1.81 kB
JavaScript
/* Build Date: Mon Jan 05 2026 23:52:23 GMT+0800 (China Standard Time) */
;
Object.defineProperty(exports, Symbol.toStringTag, {
value: "Module"
});
const e = e => e.replace(/&/g, "&").replace(/"/g, """).replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">");
function r(r, ...t) {
if (typeof r === "string") {
return e(r);
}
let n = r[0];
for (const [o, s] of t.entries()) {
n = n + e(String(s)) + r[o + 1];
}
return n;
}
class MissingValueError extends Error {
constructor(e) {
super(`Missing a value for ${e ? `the placeholder: ${e}` : "a placeholder"}`);
this.name = "MissingValueError";
this.key = e;
}
}
function t(e, t, {ignoreMissing: n = false, transform: o = ({value: e}) => e} = {}) {
if (typeof e !== "string") {
throw new TypeError(`Expected a \`string\` in the first argument, got \`${typeof e}\``);
}
if (typeof t !== "object") {
throw new TypeError(`Expected an \`object\` or \`Array\` in the second argument, got \`${typeof t}\``);
}
const s = (e, r) => {
let s = t;
for (const e of r.split(".")) {
s = s ? s[e] : undefined;
}
const i = o({
value: s,
key: r
});
if (i === undefined) {
if (n) {
return e;
}
throw new MissingValueError(r);
}
return String(i);
};
const i = e => (...t) => r(e(...t));
const a = /{{(\d+|[a-z$_][\w\-$]*?(?:\.[\w\-$]*?)*?)}}/gi;
if (a.test(e)) {
e = e.replace(a, i(s));
}
const c = /{(\d+|[a-z$_][\w\-$]*?(?:\.[\w\-$]*?)*?)}/gi;
return e.replace(c, s);
}
exports.MissingValueError = MissingValueError;
exports.Templating = t;