UNPKG

stonev5-utils

Version:
65 lines 1.69 kB
export function set(obj, path, value) { if (!obj) obj = {}; if (!path) { obj = value; } else { const parts = path.split('.'); let current = obj; for (let i = 0; i < parts.length - 1; i++) { const part = parts[i]; if (typeof current[part] !== 'object' || current[part] === null) { current[part] = {}; } current = current[part]; } current[parts[parts.length - 1]] = value; } return obj; } export function newProxy() { return new Proxy({}, { get(target, prop) { if (!(prop in target)) { target[prop] = new Proxy({}, this); } return target[prop]; } }); } export class RefObj { v; constructor(v) { this.v = v; } } export function isObject(value) { return value != null && typeof value === 'object' && !Array.isArray(value); } export function clone(obj) { return JSON.parse(JSON.stringify(obj)); } export function isBoolean(value) { return typeof value === "boolean"; } export function isValidNumber(num) { return typeof num === "number" && !isNaN(num); } export function isStringNumber(str) { return !isNaN(+str); } export function validateNum(num, v) { if (isValidNumber(num)) { return num; } return v; } export function objOverrideNull(includeNull, defaultValue) { Object.keys(defaultValue).forEach((key) => { const typedKey = key; if (includeNull[typedKey] == null) { includeNull[typedKey] = defaultValue[typedKey]; } }); return includeNull; } //# sourceMappingURL=object.js.map