UNPKG

evolve-ts

Version:

Immutably update nested objects with patches containing values or functions to update values

2 lines (1 loc) 978 B
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["evolve-ts"]={})}(this,(function(e){"use strict";const t=class{},o={}.toString,l=e=>"[object Object]"===o.call(e),n=e=>e!=t&&"function"==typeof e,s=e=>(...t)=>t.length<e.length?(...o)=>s(e)(...t,...o):e(...t),c=(e,o)=>e&&l(e)?(o=l(o)?{...o}:{},Object.keys(e).forEach((l=>{o[l]=c(e[l],o[l]),o[l]==t&&delete o[l]})),o):n(e)?e(o):e,f=s(c),a=f,i=s(((e,o)=>(o={...o},Object.keys(e).forEach((l=>{const s=e[l];o[l]=n(s)?s(o[l]):s,o[l]==t&&delete o[l]})),o))),d=e=>(t,o,l)=>{let s;n(o)||(o=e(o));const c=e=>(s=1,o(e));t<0&&(t=l.length+t);const f=l.map(n(t)?e=>t(e)?c(e):e:(e,o)=>o===t?c(e):e);return s?f:l},p=s(d(f)),u=s(d(i)),h=e=>(t,o)=>o.map(n(t)?e=>t(e):e(t)),r=s(h(f)),v=s(h(i));e.adjust=p,e.evolve=f,e.evolve_=a,e.map=r,e.shallowAdjust=u,e.shallowEvolve=i,e.shallowMap=v,e.unset=t}));