typed-object-accumulator
Version:
Class capable of accumulation properties and types
3 lines (2 loc) • 1.18 kB
JavaScript
var e,t;e=this,t=function(e){"use strict";class t{constructor(){Object.defineProperty(this,"__size",{value:0,writable:!0,configurable:!1,enumerable:!1})}expand(e){Object.entries(e).forEach(([e,t])=>{Object.defineProperty(this,e,{get:()=>t,set:e=>{t=e},configurable:!0,enumerable:!0})})}accumulate(e){return this.expand(e),this.__size=this.__size+Object.keys(e).length,this}get(e){if(!(e in this))throw Error(`Key ${e} does not exist in accumulator. Available keys: ${this.keys().join(", ")}`);return this[e]}put(e,t){return this.accumulate({[e]:t})}has(e){return!!this[e]}remove(e){return e in this?(delete this[e],this.__size--,this):this}keys(){return Object.keys(this)}values(){return Object.values(this)}size(){return this.__size}clear(){return new t}forEach(e){Object.entries(this).forEach(([t,i],s)=>e(i,t,s))}map(e){return Object.entries(this).map(([t,i],s)=>e(i,t,s))}}e.ObjectAccumulator=t,e.VERSION="1.0.5"},"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).typedObjectAccumulator={});
//# sourceMappingURL=typed-object-accumulator.cjs.map