UNPKG

array-immutable

Version:
1 lines 1.95 kB
const deepCopy=require("./node_modules/deep-copy-all/index"),copyOptions={goDeep:void 0,includeNonEnumerable:void 0,maxDepth:void 0},aiCopy=r=>deepCopy(r,copyOptions);module.exports=class r extends Array{static deepCopy(r){return"boolean"==typeof r&&(copyOptions.goDeep=r),copyOptions.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 o=new r;return Array.prototype.push.apply(o,aiCopy(t)),o}static from(r,t,o){return this.arrayI(aiCopy(Array.from(r,t,o)))}static of(...r){return this.arrayI(aiCopy(Array.of(...arguments)))}concat(...r){return this.constructor.arrayI(aiCopy(Array.concat(...arguments)))}copyWithin(r,t,o){const a=aiCopy([...this]);return this.constructor.arrayI(a.copyWithin(...arguments))}fill(r,t,o){const a=aiCopy([...this]);return this.constructor.arrayI(a.fill(...arguments))}filter(r,t){const o=aiCopy([...this]);return this.constructor.arrayI(o.filter(...arguments))}flat(r){const t=aiCopy([...this]);return this.constructor.arrayI(t.flat(r))}flatMap(r){const t=aiCopy([...this]).flatMap(...arguments);return this.constructor.arrayI(t)}map(r,t){const o=aiCopy([...this]);return this.constructor.arrayI(o.map(...arguments))}pop(){const r=aiCopy([...this]);return r.pop(),this.constructor.arrayI(r)}push(...r){const t=aiCopy([...this]);return t.push(...arguments),this.constructor.arrayI(t)}reverse(){const r=aiCopy([...this]);return this.constructor.arrayI(r.reverse())}shift(){const r=aiCopy([...this]);return r.shift(),this.constructor.arrayI(r)}slice(r,t){const o=aiCopy([...this]);return this.constructor.arrayI(o.slice(...arguments))}sort(r){const t=aiCopy([...this]);return this.constructor.arrayI(t.sort(r))}splice(r,t,...o){const a=aiCopy([...this]);return a.splice(...arguments),this.constructor.arrayI(a)}unshift(...r){const t=aiCopy([...this]);return t.unshift(...arguments),this.constructor.arrayI(t)}};