UNPKG

deep-get-set-ts

Version:

Deeply get and set values via dot-notation strings respecting type information.

2 lines (1 loc) 656 B
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function c(...t){return t.length===2?l(...t):u(...t)}function l(t,r){const s=Array.isArray(r)?r:r.split(".");for(const n of s){if(t==null||!Object.prototype.hasOwnProperty.call(t,n)||f(n))return;const e=t[n];t=e}return t}function u(t,r,s,n=!1){const e=Array.isArray(r)?r.flat(1/0):r.split(".");for(const i of e.slice(0,-1)){if(f(i))return;!Object.hasOwn(t,i)&&!n&&(t[i]={}),t=t[i]}const o=e[e.length-1];if(!f(o))return t[o]=s,s}function f(t){return t==="__proto__"||t==="constructor"||t==="prototype"}exports.default=c;exports.get=l;exports.set=u;