lakutata
Version:
An IoC-based universal application framework.
38 lines (36 loc) • 966 B
JavaScript
/* Build Date: Mon Jan 05 2026 23:52:23 GMT+0800 (China Standard Time) */
class ObjectPath {
static getPathKeys(t) {
return t.replace(/\[(\w+)\]/g, ".$1").split(".");
}
static get(t, e) {
const s = this.getPathKeys(e);
let n = t;
for (const t of s) {
if (n == null) return undefined;
n = n[t];
}
return n;
}
static set(t, e, s) {
if (s === undefined) return;
const n = this.getPathKeys(e);
let r = t;
for (let t = 0; t < n.length - 1; t++) {
const e = n[t];
if (typeof r[e] !== "object") r[e] = {};
r = r[e];
}
r[n[n.length - 1]] = s;
}
static has(t, e) {
const s = this.getPathKeys(e);
let n = t;
for (const t of s) {
if (n == null || !(t in n)) return false;
n = n[t];
}
return true;
}
}
export { ObjectPath };