diff --git a/objix.min.js b/objix.min.js index 82c033b..752a2fb 100644 --- a/objix.min.js +++ b/objix.min.js @@ -1 +1 @@ -const O=Object,K=O.keys,A=O.assign,M={every(t){for(let e in this)if(!t(this[e],e))return!1;return!0},some(t){for(let e in this)if(t(this[e],e))return!0;return!1},map(t,e={}){for(let r in this)e[r]=t(this[r],r);return e},has(t,e){return this.find((e=>e.eq(t)))},filter(t,e={}){for(let r in this)t(this[r],r)&&(e[r]=this[r]);return e},flatMap(t){return O.fromEntries(K(this).flatMap((e=>t(e,this[e]))))},clean(){return this.filter((t=>t))},is(t,e){return t==O?!e&&![Number,String,Boolean,Function].includes(this.constructor):this.constructor==t||!e&&this instanceof t},find(t){for(let e in this)if(t(this[e],e))return e},extend(...t){return A({},...t).map(((t,e)=>this[e]??t),this)},delete(...t){for(let e of t)delete this[e];return this},clone(t){return this.is(O)?this.constructor==Array?this.map((e=>t&&e?e.clone(t-1):e)):this.size()?this.map((e=>t&&e?e.clone(t-1):e),new this.constructor):new this.constructor(this):this.valueOf()},join(...t){let e=A({},this);for(let r of t)K(r).map((t=>e[t]&&=[].concat(e[t],r[t])));return e},split(){let t=[];for(let e in this)this[e].map(((r,i)=>t[i]?t[i][e]=r:t[i]={[e]:r}));return t},same(t){return this.filter(((e,r)=>e.eq(t[r])))},diff(t){return this.filter(((e,r)=>!e.eq(t[r])))},contains(t,e){return t.every(((t,e)=>this[e]?.eq(t)))||e&&this.some((r=>r.contains(t,e-1)))},eq(t,e){return this==t||t&&this.constructor==t.constructor&&this.size()==t.size()&&!(this-t)&&this.every(((r,i)=>r==t[i]||e&&r?.eq(t[i],e-1)))},size(){return K(this).length},keyBy(t,e){return t.map((t=>this[t[e]]=this[t[e]]?[t].concat(this[t[e]]):t)),this},at(t){return t.split(".").reduce(((t,e)=>t[e]),this)},$(t){return t?t.is(String)?t.replace(/\${?([\w\.]+)}?/g,((t,e)=>this.at(e).$())):(t.stringify||t)(this):this.$(JSON).replace(/["\\]/g,"")},memo(t){return t?(...e)=>this[e.$()]??=(setTimeout((()=>delete this[e.$()]),1e3*t),this(...e)):this},bind(t,e,r){return def(this,t,function(...t){return e(...t,this)}.memo(r)),this},log(t="",e,r="log"){return(!e||e(this))&&console[r]((new Date).$().slice(0,-8),t,this.clone()),this},try(t,e){try{return t(this)??this}catch(t){return e&&e(t,this)||this}},new(t){return this._t?new Proxy(this._t.new(t),this._h):A(this.create(),t)},trap(t,e,...r){return new Proxy(this,{set(i,s,n){if((!r[0]||r.has(s))&&!t(n,s,i)&&e)throw e+" "+[s,n].$();return i[s]=n},get(t,e){return{_t:t,_h:this}[e]||t[e]}})}};for(let t of["keys","values","entries","create","assign"])M[t]=function(...e){return O[t](this,...e)};let def=(t,e,r)=>(O.defineProperty(t,e,{writable:!0,value:r}),r);O.prototype[Symbol.iterator]=function(){return this.values()[Symbol.iterator]()};for(let t in M){[t,"__"+t].map((e=>def(O.prototype,e,M[t])));try{module.exports[t]=(e,...r)=>e["__"+t](...r)}catch{}} \ No newline at end of file +const O=Object,K=O.keys,A=O.assign,M={every(t){for(let e in this)if(!t(this[e],e))return!1;return!0},some(t){for(let e in this)if(t(this[e],e))return!0;return!1},map(t,e={}){for(let r in this)e[r]=t(this[r],r);return e},has(t,e){return this.find((e=>e.eq(t)))},filter(t,e={}){for(let r in this)t(this[r],r)&&(e[r]=this[r]);return e},flatMap(t){return O.fromEntries(K(this).flatMap((e=>t(e,this[e]))))},clean(){return this.filter((t=>t))},is(t,e){return t==O?!e&&![Number,String,Boolean,Function].includes(this.constructor):this.constructor==t||!e&&this instanceof t},find(t){for(let e in this)if(t(this[e],e))return e},extend(...t){return A({},...t).map(((t,e)=>this[e]??t),this)},delete(...t){for(let e of t)delete this[e];return this},clone(t){return this.is(O)?this.constructor==Array?this.map((e=>t&&e?e.clone(t-1):e)):this.size()?this.map((e=>t&&e?e.clone(t-1):e),new this.constructor):new this.constructor(this):this.valueOf()},join(...t){let e=A({},this);for(let r of t)K(r).map((t=>e[t]&&=[].concat(e[t],r[t])));return e},split(){let t=[];for(let e in this)this[e].map(((r,i)=>t[i]?t[i][e]=r:t[i]={[e]:r}));return t},same(t){return this.filter(((e,r)=>e.eq(t[r])))},diff(t){return this.filter(((e,r)=>!e.eq(t[r])))},contains(t,e){return t.every(((t,e)=>this[e]?.eq(t)))||e&&this.some((r=>r.contains(t,e-1)))},eq(t,e){return this==t||t&&this.constructor==t.constructor&&this.size()==t.size()&&!(this-t)&&this.every(((r,i)=>r==t[i]||e&&r?.eq(t[i],e-1)))},size(){return K(this).length},keyBy(t,e){return t.map((t=>this[t[e]]=this[t[e]]?[t].concat(this[t[e]]):t)),this},at(t){return t.split(".").reduce(((t,e)=>t[e]),this)},$(t){return t?t.is(String)?t.replace(/\${?([\w\.]+)}?/g,((t,e)=>this.at(e).$())):(t.stringify||t)(this):this.$(JSON).replace(/["\\]/g,"")},memo(t){return t?(...e)=>this[e.$()]??=(setTimeout((()=>delete this[e.$()]),1e3*t),this(...e)):this},bind(t,e,r){return def(this,t,function(...t){return e(...t,this)}.memo(r)),this},log(t="",e,r="log"){return(!e||e(this))&&console[r]((new Date).$().slice(0,-8),t,this.clone()),this},try(t,e){try{return t(this)??this}catch(t){return!e||e(t,this)||this}},new(t){return this._t?new Proxy(this._t.new(t),this._h):A(this.create(),t)},trap(t,e,...r){return new Proxy(this,{set(i,s,n){if((!r[0]||r.has(s))&&!t(n,s,i)&&e)throw e+" "+[s,n].$();return i[s]=n},get(t,e){return{_t:t,_h:this}[e]||t[e]}})}};for(let t of["keys","values","entries","create","assign"])M[t]=function(...e){return O[t](this,...e)};let def=(t,e,r)=>(O.defineProperty(t,e,{writable:!0,value:r}),r);O.prototype[Symbol.iterator]=function(){return this.values()[Symbol.iterator]()};for(let t in M){[t,"__"+t].map((e=>def(O.prototype,e,M[t])));try{module.exports[t]=(e,...r)=>e["__"+t](...r)}catch{}} \ No newline at end of file