UNPKG

typed-object-accumulator

Version:
3 lines (2 loc) 955 B
class e{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 e}forEach(e){Object.entries(this).forEach(([t,r],s)=>e(r,t,s))}map(e){return Object.entries(this).map(([t,r],s)=>e(r,t,s))}}const t="##VERSION##";export{e as ObjectAccumulator,t as VERSION}; //# sourceMappingURL=typed-object-accumulator.js.map