UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 3.01 kB
import{equals as t}from"./arrayUtils.js";import{isSome as n}from"./maybe.js";import{isInt8Array as e,isUint8Array as r,isUint8ClampedArray as o,isInt16Array as f,isUint16Array as i,isInt32Array as u,isUint32Array as c,isFloat32Array as s,isFloat64Array as a}from"./typedArrayUtil.js";function l(t,n){let e;if(n)for(e in t)t.hasOwnProperty(e)&&(void 0===t[e]?delete t[e]:t[e]instanceof Object&&l(t[e],!0));else for(e in t)t.hasOwnProperty(e)&&void 0===t[e]&&delete t[e];return t}function p(t){if(!t||"object"!=typeof t||"function"==typeof t)return t;const e=j(t);if(n(e))return e;if(m(t))return t.clone();if(b(t))return t.map(p);if(g(t))return t.clone();const r={};for(const n of Object.getOwnPropertyNames(t))r[n]=p(t[n]);return r}function y(t){if(!t||"object"!=typeof t||"function"==typeof t||"HTMLElement"in globalThis&&t instanceof HTMLElement)return t;const e=j(t);if(n(e))return e;if(b(t)){let n=!0;const e=t.map((t=>{const e=y(t);return null!=t&&null==e&&(n=!1),e}));return n?e:null}if(m(t))return t.clone();if(!g(t)){const n=new(0,Object.getPrototypeOf(t).constructor);for(const e of Object.getOwnPropertyNames(t)){const r=t[e],o=y(r);if(null!=r&&null==o)return null;n[e]=o}return n}return null}function m(t){return"function"==typeof t.clone}function b(t){return"function"==typeof t.map&&"function"==typeof t.forEach}function g(t){return"function"==typeof t.notifyChange&&"function"==typeof t.watch}function O(t){if("[object Object]"!==Object.prototype.toString.call(t))return!1;const n=Object.getPrototypeOf(t);return null===n||n===Object.prototype}function j(t){if(e(t)||r(t)||o(t)||f(t)||i(t)||u(t)||c(t)||s(t)||a(t))return t.slice();if(t instanceof Date)return new Date(t.getTime());if(t instanceof ArrayBuffer){return t.slice(0,t.byteLength)}if(t instanceof Map){const n=new Map;for(const[e,r]of t)n.set(e,p(r));return n}if(t instanceof Set){const n=new Set;for(const e of t)n.add(p(e));return n}return null}function h(t,n){return t===n||"number"==typeof t&&isNaN(t)&&"number"==typeof n&&isNaN(n)||"function"==typeof(t||{}).getTime&&"function"==typeof(n||{}).getTime&&t.getTime()===n.getTime()||!1}function w(n,e){return n===e||(null==n||"string"==typeof n?n===e:"number"==typeof n?n===e||"number"==typeof e&&isNaN(n)&&isNaN(e):n instanceof Date?e instanceof Date&&n.getTime()===e.getTime():Array.isArray(n)?Array.isArray(e)&&t(n,e):n instanceof Set?e instanceof Set&&T(n,e):n instanceof Map?e instanceof Map&&d(n,e):!!O(n)&&(O(e)&&N(n,e)))}function N(t,n){if(null===t||null===n)return!1;const e=Object.keys(t);if(null===n||Object.keys(n).length!==e.length)return!1;for(const r of e)if(t[r]!==n[r]||!Object.prototype.hasOwnProperty.call(n,r))return!1;return!0}function T(t,n){if(t.size!==n.size)return!1;for(const e of t)if(!n.has(e))return!1;return!0}function d(t,n){if(t.size!==n.size)return!1;for(const[e,r]of t){const t=n.get(e);if(t!==r||void 0===t&&!n.has(e))return!1}return!0}export{p as clone,h as equals,w as equalsShallow,l as fixJson,g as isAccessorLike,O as isPlainObject,y as tryClone};