UNPKG

evolve-ts

Version:

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

2 lines (1 loc) 747 B
const t=class{},e={}.toString,c=t=>"[object Object]"===e.call(t),n=e=>e!=t&&"function"==typeof e,o=t=>(...e)=>e.length<t.length?(...c)=>o(t)(...e,...c):t(...e),l=(e,o)=>e&&c(e)?(o=c(o)?{...o}:{},Object.keys(e).forEach((c=>{o[c]=l(e[c],o[c]),o[c]==t&&delete o[c]})),o):n(e)?e(o):e,s=o(l),a=s,r=o(((e,c)=>(c={...c},Object.keys(e).forEach((o=>{const l=e[o];c[o]=n(l)?l(c[o]):l,c[o]==t&&delete c[o]})),c))),h=t=>(e,c,o)=>{let l;n(c)||(c=t(c));const s=t=>(l=1,c(t));e<0&&(e=o.length+e);const a=o.map(n(e)?t=>e(t)?s(t):t:(t,c)=>c===e?s(t):t);return l?a:o},b=o(h(s)),f=o(h(r)),g=t=>(e,c)=>c.map(n(e)?t=>e(t):t(e)),j=o(g(s)),p=o(g(r));export{b as adjust,s as evolve,a as evolve_,j as map,f as shallowAdjust,r as shallowEvolve,p as shallowMap,t as unset};