UNPKG

@mlightcad/common

Version:

The common package provides shared utilities and base classes that are used across the RealDWG-Web ecosystem. This package contains fundamental components for color management, event handling, logging, performance monitoring, and file loading operations.

186 lines 6.03 kB
/** * Utility functions extracted from lodash-es to reduce bundle size * These are simplified implementations of commonly used lodash functions */ var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; var __values = (this && this.__values) || function(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); }; /** * Creates a shallow clone of an object * @param obj The object to clone * @returns A shallow clone of the object */ export function clone(obj) { if (obj === null || typeof obj !== 'object') { return obj; } if (Array.isArray(obj)) { return __spreadArray([], __read(obj), false); } return __assign({}, obj); } /** * Assigns own enumerable properties of source objects to the destination object for all destination properties that resolve to undefined. * @param obj The destination object * @param sources The source objects * @returns The destination object */ export function defaults(obj) { var e_1, _a; var sources = []; for (var _i = 1; _i < arguments.length; _i++) { sources[_i - 1] = arguments[_i]; } try { for (var sources_1 = __values(sources), sources_1_1 = sources_1.next(); !sources_1_1.done; sources_1_1 = sources_1.next()) { var source = sources_1_1.value; if (source) { for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key) && obj[key] === undefined) { obj[key] = source[key]; } } } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (sources_1_1 && !sources_1_1.done && (_a = sources_1.return)) _a.call(sources_1); } finally { if (e_1) throw e_1.error; } } return obj; } /** * Checks if path is a direct property of object * @param obj The object to query * @param path The path to check * @returns Returns true if path exists, else false */ export function has(obj, path) { return obj != null && Object.prototype.hasOwnProperty.call(obj, path); } /** * Checks if value is an empty object, collection, map, or set * @param value The value to check * @returns Returns true if value is empty, else false */ export function isEmpty(value) { if (value == null) { return true; } if (Array.isArray(value) || typeof value === 'string') { return value.length === 0; } if (value instanceof Map || value instanceof Set) { return value.size === 0; } if (typeof value === 'object') { return Object.keys(value).length === 0; } return false; } /** * Performs a deep comparison between two values to determine if they are equivalent * @param value The value to compare * @param other The other value to compare * @returns Returns true if the values are equivalent, else false */ export function isEqual(value, other) { var e_2, _a; if (value === other) { return true; } if (value == null || other == null) { return value === other; } if (typeof value !== typeof other) { return false; } if (typeof value !== 'object') { return value === other; } if (Array.isArray(value) !== Array.isArray(other)) { return false; } if (Array.isArray(value)) { if (value.length !== other.length) { return false; } for (var i = 0; i < value.length; i++) { if (!isEqual(value[i], other[i])) { return false; } } return true; } var valueKeys = Object.keys(value); var otherKeys = Object.keys(other); if (valueKeys.length !== otherKeys.length) { return false; } try { for (var valueKeys_1 = __values(valueKeys), valueKeys_1_1 = valueKeys_1.next(); !valueKeys_1_1.done; valueKeys_1_1 = valueKeys_1.next()) { var key = valueKeys_1_1.value; if (!Object.prototype.hasOwnProperty.call(other, key) || !isEqual(value[key], other[key])) { return false; } } } catch (e_2_1) { e_2 = { error: e_2_1 }; } finally { try { if (valueKeys_1_1 && !valueKeys_1_1.done && (_a = valueKeys_1.return)) _a.call(valueKeys_1); } finally { if (e_2) throw e_2.error; } } return true; } //# sourceMappingURL=AcCmLodashUtils.js.map