funtool
Version:
A modern, efficient, and modular JavaScript utility library designed to enhance developer productivity.
3 lines (2 loc) • 3.77 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).funtool={})}(this,(function(t){"use strict";function e(t){return"function"==typeof Array.isArray?Array.isArray(t):"[object Array]"===Object.prototype.toString.call(t)}function n(t){return"function"==typeof t||"object"==typeof t&&null!==t}function r(t){return"[object Map]"===Object.prototype.toString.call(t)&&t instanceof Map}function o(t){return"[object Set]"===Object.prototype.toString.call(t)&&t instanceof Set}function c(t){return"function"==typeof t}function i(t){return"object"!=typeof t&&"function"!=typeof t||null==t}function u(t,u){if(i(t))return t;if(e(t))return t.map(((t,e)=>{if(c(u)){return u(t,e)}return t}));if(f=t,"[object Date]"===Object.prototype.toString.call(f))return new Date(t.getTime());var f;if(function(t){return"[object RegExp]"===Object.prototype.toString.call(t)}(t))return new RegExp(t.source,t.flags);if(r(t))return new Map(t);if(o(t))return new Set(t);if(function(t){return ArrayBuffer.isView(t)&&!(t instanceof DataView)}(t))return t.slice();if(function(t){return t instanceof DataView&&"[object DataView]"===Object.prototype.toString.call(t)}(t))return new DataView(t.buffer.slice(0));if(n(t)){const e=Object.getPrototypeOf(t),n=Object.create(e);for(const e in t)if(Object.prototype.hasOwnProperty.call(t,e)){const r=t[e],o=u?.(r,e);n[e]=void 0!==o?o:r}return n}return t}const f={Date:t=>new Date(t.getTime()),RegExp:t=>new RegExp(t.source,t.flags),Array:(t,e,n)=>{const r=[];return e.set(t,r),t.forEach(((t,o)=>{r[o]=n(t,e)})),r},Map:(t,e,n)=>{const r=new Map;return e.set(t,r),t.forEach(((t,o)=>{r.set(o,n(t,e))})),r},Set:(t,e,n)=>{const r=new Set;return e.set(t,r),t.forEach((t=>{r.add(n(t,e))})),r}};function a(t,e,n,r){if(o=t,"[object Null]"===Object.prototype.toString.call(o)||!function(t){return null!=t&&"object"==typeof t}(t))return t;var o;if(c(t)||function(t){return"symbol"==typeof t}(t)||function(t){return"[object BigInt]"===Object.prototype.toString.call(t)}(t)||function(t){return"[object WeakMap]"===Object.prototype.toString.call(t)&&t instanceof WeakMap}(t)||function(t){return"[object WeakSet]"===Object.prototype.toString.call(t)&&t instanceof WeakSet}(t)){const e="object"==typeof t&&null!==t&&"constructor"in t&&t.constructor?.name||typeof t;return console.warn(`⚠️ Warning: Unsupported type "${e}" encountered, returning original.`),t}if(e.has(t))return e.get(t);const u=Object.prototype.toString.call(t).slice(8,-1);if(u in f)return f[u](t,e,n);const a={};return e.set(t,a),function(t,e){return i(t)?[]:("undefined"!=typeof Reflect&&"function"==typeof Reflect.ownKeys?Reflect.ownKeys(t):[...Object.getOwnPropertyNames?Object.getOwnPropertyNames(t):[],...Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(t):[]]).filter((n=>{const r=Object.getOwnPropertyDescriptor(t,n);return!!r&&(c(e)?e(n,r):r.enumerable)}))}(t).forEach((o=>{if(function(t,e){return!i(t)&&Object.prototype.hasOwnProperty.call(t,e)}(t,o)){const c=t[o],i=r?.(c,o,t);a[o]=void 0!==i?i:n(c,e)}})),a}t.clone=function(t){return u(t)},t.cloneDeep=function t(e,n=new WeakMap){return a(e,n,t)},t.cloneDeepWith=function(t,e,n=new WeakMap){const r=(t,o=n)=>{const c=e(t);return void 0!==c?c:a(t,o,r,e)};return r(t)},t.cloneWith=function(t,e){return u(t,e)},t.includes=function(t,c,i=0){return e(t)?t.slice(i).includes(c):(u=t,"[object String]"===Object.prototype.toString.call(u)?-1!==t.indexOf(String(c),i):r(t)||o(t)?t.has(c):!!function(t){if(!n(t))return!1;const e=Object.getPrototypeOf(t);return null===e||e===Object.prototype||null===Object.getPrototypeOf(e)}(t)&&Object.values(t).includes(c));var u}}));
//# sourceMappingURL=index.umd.js.map