UNPKG

t-getter

Version:

Library for making texts from objects

1 lines 680 B
const e=["string","number"],t=Object.freeze({not_set:"[t-getter.js] There is no texts objects"});function r(r,{placeholder:n,freeze:o=!0}={}){if(!r?.length)throw new Error(t.not_set);r=r.map((e=>o?Object.freeze(e):e));let f=n;function s(t){return e.includes(typeof t)}function i({index:e,prop:t,args:n}){const o=t.split(".");let f=r[e],s=0;for(;s<o.length;){let e=f[o[s]];if(null==e)break;"function"==typeof e&&(e=e(...n)),f=e,s++}return f}return function(e,...n){if(!r.length)throw new Error(t.not_set);let o,l=0;for(;l<r.length;){const t=i({index:l,prop:e,args:n});if(s(t)){o=t;break}l++}return s(o)?o:(c={prop:e,args:n},"function"==typeof f?f(c):f);var c}}export{r as default};