UNPKG

array-immutable

Version:
1 lines 7.18 kB
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).ArrayI=e()}}(function(){return function(){return function e(t,r,n){function a(i,s){if(!r[i]){if(!t[i]){var y="function"==typeof require&&require;if(!s&&y)return y(i,!0);if(o)return o(i,!0);var p=new Error("Cannot find module '"+i+"'");throw p.code="MODULE_NOT_FOUND",p}var c=r[i]={exports:{}};t[i][0].call(c.exports,function(e){return a(t[i][1][e]||e)},c,c.exports,e,t,r,n)}return r[i].exports}for(var o="function"==typeof require&&require,i=0;i<n.length;i++)a(n[i]);return a}}()({1:[function(e,t,r){const n=e("./node_modules/deep-copy-all/index"),a={goDeep:void 0,includeNonEnumerable:void 0,maxDepth:void 0},o=e=>n(e,a);t.exports=class e extends Array{static deepCopy(e){return"boolean"==typeof e&&(a.goDeep=e),a.goDeep}static arrayI(t=[]){if(!Array.isArray(t))throw console.error("!Array.isArray(array) array:",t),Error("ArrayI.arrayI parameter is not an array");const r=new e;return Array.prototype.push.apply(r,o(t)),r}static from(e,t,r){return this.arrayI(o(Array.from(e,t,r)))}static of(...e){return this.arrayI(o(Array.of(...arguments)))}concat(...e){return this.constructor.arrayI(o(Array.concat(...arguments)))}copyWithin(e,t,r){const n=o([...this]);return this.constructor.arrayI(n.copyWithin(...arguments))}fill(e,t,r){const n=o([...this]);return this.constructor.arrayI(n.fill(...arguments))}filter(e,t){const r=o([...this]);return this.constructor.arrayI(r.filter(...arguments))}flat(e){const t=o([...this]);return this.constructor.arrayI(t.flat(e))}flatMap(e){const t=o([...this]).flatMap(...arguments);return this.constructor.arrayI(t)}map(e,t){const r=o([...this]);return this.constructor.arrayI(r.map(...arguments))}pop(){const e=o([...this]);return e.pop(),this.constructor.arrayI(e)}push(...e){const t=o([...this]);return t.push(...arguments),this.constructor.arrayI(t)}reverse(){const e=o([...this]);return this.constructor.arrayI(e.reverse())}shift(){const e=o([...this]);return e.shift(),this.constructor.arrayI(e)}slice(e,t){const r=o([...this]);return this.constructor.arrayI(r.slice(...arguments))}sort(e){const t=o([...this]);return this.constructor.arrayI(t.sort(e))}splice(e,t,...r){const n=o([...this]);return n.splice(...arguments),this.constructor.arrayI(n)}unshift(...e){const t=o([...this]);return t.unshift(...arguments),this.constructor.arrayI(t)}}},{"./node_modules/deep-copy-all/index":2}],2:[function(e,t,r){"use strict";const[n,a,o]=e("./object-library.js"),i={goDeep:!0,includeNonEnumerable:!1,maxDepth:20};t.exports=function(e,t){if(void 0===(t=t||i).goDeep&&(t.goDeep=i.goDeep),void 0===t.includeNonEnumerable&&(t.includeNonEnumerable=i.includeNonEnumerable),void 0===t.maxDepth&&(t.maxDepth=i.maxDepth),!t.goDeep)return o[a(e)].makeShallow(e);if(!e||n(e))return e;const r=a(e);if(!o[r].mayDeepCopy)return o[r].makeShallow(e);let y=o[r].makeEmpty(e);return s(e,y,r,0,t),y};const s=(e,t,r,n,a)=>{if(++n>=a.maxDepth)return void console.log("copyObject too deep, depth:",n,",obj:",e);const i=o[r];if(!i.mayDeepCopy)return;const y=i.addElement;(0,i.iterate)(e,a.includeNonEnumerable,e=>{const r=e.value,i=e.type;let p,c=o[i].mayDeepCopy;p=c?o[i].makeEmpty(r):o[i].makeShallow(r),y(t,e.key,p,e.descriptor),c&&s(r,p,i,n,a)})}},{"./object-library.js":3}],3:[function(e,t,r){const n=e=>{let t=typeof e;return"number"===t||"string"===t||"boolean"===t||"undefined"===t||"bigint"===t||"symbol"===t||null===e},a=e=>{if(n(e)||!e instanceof Object)return"primitive";const t=e.constructor&&e.constructor.name&&e.constructor.name.toLowerCase();if("string"==typeof t&&t.length&&o[t])return t;let r;for(const t in o)if(!(r=o[t].type)||e instanceof r)return t;return"unknown"},o={array:{type:Array,mayDeepCopy:!0,addElement:(e,t,r)=>Array.prototype.push.call(e,r),makeEmpty:e=>{const t=[];return Object.setPrototypeOf(t,Object.getPrototypeOf(e)),t},makeShallow:e=>{const t=[...e];return Object.setPrototypeOf(t,Object.getPrototypeOf(e)),t},iterate:(e,t,r)=>{const n=e.length;for(let t=0;t<n;t++){const n=e[t];r({key:t,value:n,type:a(n)})}}},date:{type:Date,makeShallow:e=>new Date(e.getTime())},regexp:{type:RegExp,makeShallow:e=>new RegExp(e)},function:{type:Function,makeShallow:e=>e}};"undefined"!=typeof Int8Array&&Object.assign(o,{int8array:{type:Int8Array,makeShallow:e=>Int8Array.from(e)}}),"undefined"!=typeof Uint8Array&&Object.assign(o,{uint8array:{type:Uint8Array,makeShallow:e=>Uint8Array.from(e)}}),"undefined"!=typeof Uint8ClampedArray&&Object.assign(o,{uint8clampedarray:{type:Uint8ClampedArray,makeShallow:e=>Uint8ClampedArray.from(e)}}),"undefined"!=typeof Int16Array&&Object.assign(o,{int16array:{type:Int16Array,makeShallow:e=>Int16Array.from(e)}}),"undefined"!=typeof Uint16Array&&Object.assign(o,{uint16array:{type:Uint16Array,makeShallow:e=>Uint16Array.from(e)}}),"undefined"!=typeof Int32Array&&Object.assign(o,{int32array:{type:Int32Array,makeShallow:e=>Int32Array.from(e)}}),"undefined"!=typeof Uint32Array&&Object.assign(o,{uint32array:{type:Uint32Array,makeShallow:e=>Uint32Array.from(e)}}),"undefined"!=typeof Float32Array&&Object.assign(o,{float32array:{type:Float32Array,makeShallow:e=>Float32Array.from(e)}}),"undefined"!=typeof Float64Array&&Object.assign(o,{float64array:{type:Float64Array,makeShallow:e=>Float64Array.from(e)}}),"undefined"!=typeof BigInt64Array&&Object.assign(o,{bigint64array:{type:BigInt64Array,makeShallow:e=>BigInt64Array.from(e)}}),"undefined"!=typeof BigUint64Array&&Object.assign(o,{biguint64array:{type:BigUint64Array,makeShallow:e=>BigUint64Array.from(e)}}),"undefined"!=typeof ArrayBuffer&&Object.assign(o,{arraybuffer:{type:ArrayBuffer,makeShallow:e=>e.slice(0)}}),"undefined"!=typeof Map&&Object.assign(o,{map:{type:Map,mayDeepCopy:!0,addElement:(e,t,r)=>e.set(t,r),makeEmpty:()=>new Map,makeShallow:e=>new Map(e),iterate:(e,t,r)=>{e.forEach((e,t)=>{const n={key:t,value:e,type:a(e)};r(n)})}}}),"undefined"!=typeof Set&&Object.assign(o,{set:{type:Set,mayDeepCopy:!0,addElement:(e,t,r)=>e.add(r),makeEmpty:()=>new Set,makeShallow:e=>new Set(e),iterate:(e,t,r)=>{e.forEach(e=>{const t={key:null,value:e,type:a(e)};r(t)})}}}),"undefined"!=typeof WeakSet&&Object.assign(o,{weakset:{type:WeakSet,makeShallow:e=>e}}),"undefined"!=typeof WeakMap&&Object.assign(o,{weakmap:{type:WeakMap,makeShallow:e=>e}}),"undefined"!=typeof Buffer&&Object.assign(o,{buffer:{type:Buffer,makeShallow:e=>Buffer.from(e)}}),Object.assign(o,{object:{type:Object,mayDeepCopy:!0,addElement:(e,t,r,n)=>{n?Object.defineProperty(e,t,n):e[t]=r},makeEmpty:e=>{const t={};return Object.setPrototypeOf(t,Object.getPrototypeOf(e)),t},makeShallow:e=>{const t=Object.assign({},e);return Object.setPrototypeOf(t,Object.getPrototypeOf(e)),t},iterate:(e,t,r)=>{const n=t?Object.getOwnPropertyNames(e):Object.keys(e),o=n.length;for(let i=0;i<o;i++){const o=n[i],s=e[o],y={key:o,value:s,type:a(s)};t&&!e.propertyIsEnumerable(o)&&(y.descriptor=Object.getOwnPropertyDescriptor(e,o)),r(y)}}},unknown:{makeShallow:e=>e},primitive:{makeShallow:e=>e}}),t.exports=[n,a,o]},{}]},{},[1])(1)});