UNPKG

@veracity/vui

Version:

Veracity UI is a React component library crafted for use within Veracity applications and pages. Based on Styled Components and @xstyled.

36 lines (34 loc) 1.17 kB
import { isArray, isObject } from "./assertion.js"; //#region src/utils/object.ts /** Removes keys from an object if their value is undefined. */ function filterUndefined(object) { return objectFilter(object, (val) => val !== null && val !== void 0); } function merge(...sources) { const target = {}; sources.forEach((source) => { if (!isObject(source)) return; Object.keys(source).forEach((key) => { if (key === "__proto__") return; if (isObject(target[key]) && isObject(source[key])) target[key] = merge(target[key], source[key]); else if (isArray(target[key]) && isArray(source[key])) target[key] = target[key].concat(source[key]); else if (source[key] !== void 0) target[key] = source[key]; }); }); return target; } /** * Returns the items of an object that meet the condition specified in a callback function. */ function objectFilter(object, fn) { const result = {}; Object.keys(object).forEach((key) => { const value = object[key]; if (fn(value, key, object)) result[key] = value; }); return result; } //#endregion export { filterUndefined, merge, objectFilter }; globalThis.__vuiVersion__ = "5.3.1" //# sourceMappingURL=object.js.map