UNPKG

optix

Version:

Optix is a data manipulation library that provides optics-like capabilites with a simpler syntax. It features robust Typescript support with minimal type annotations and is smaller and faster than true optics libraries.

2 lines (1 loc) 2.19 kB
!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).optix={})}(this,(function(e){"use strict";const t=(e,r)=>{if(!r.length)return e;const n=r.slice(1),o="function"==typeof r[0]?r[0](e):r[0];return Array.isArray(o)?o.map((r=>null!=e?t(e[r],n):void 0)):null!=e?t(e[o],n):void 0},r=(e,t,n)=>{if(!t.length)return n(e);const o=t.slice(1),l="function"==typeof t[0]?t[0](e):t[0],s="string"==typeof l||"number"==typeof l?[l]:Array.isArray(l)?l:[],f=typeof s[0];if("string"!==f&&"number"!==f||s[0]<0)return e;const i="number"===f,y=e&&"object"==typeof e?i?e.slice(0):Object.assign({},e):i?[]:{};for(let e=0;e<s.length;e++)y[s[e]]=r(y[s[e]],o,n);return y},n=(e,t,n)=>r(e,t,(()=>n)),o=(e,t)=>{if(!t.length||!e||"object"!=typeof e)return e;const r="function"==typeof t[0]?t[0](e):t[0],n="string"==typeof r||"number"==typeof r?[r]:Array.isArray(r)?r:[],l=typeof n[0];if("string"!==l&&"number"!==l||n[0]<0)return e;if(1===t.length){let t;if(Array.isArray(e)){const r=new Set(n);t=[];for(let n=0;n<e.length;n++)r.has(n)||t.push(e[n])}else{t=Object.assign({},e);for(let e=0;e<n.length;e++)delete t[n[e]]}return t}{const r=t.slice(1),l=Array.isArray(e)?e.slice(0):Object.assign({},e);for(let e=0;e<n.length;e++){const t=n[e];({}).hasOwnProperty.call(l,t)&&(l[t]=o(l[t],r))}return l}},l=Object.keys,s=e=>t=>{for(let r=0,n=Object.keys(t);r<n.length;r++)if(e(n[r]))return n[r]},f=e=>t=>{const r=[],n=Object.keys(t);for(let t=0;t<n.length;t++)e(n[t])&&r.push(n[t]);return r},i=(...e)=>t=>r=>n(r,e,t),y=(...e)=>t=>n=>r(n,e,t),u=(...e)=>t=>o(t,e),c=i,p=y,a=u;e._get=t,e._remove=o,e._set=n,e._update=r,e.all=e=>e.map(((e,t)=>t)),e.filter=e=>t=>{const r=[];for(let n=0;n<t.length;n++)e(t[n])&&r.push(n);return r},e.filterByKey=f,e.filterByVal=e=>t=>f((r=>e(t[r])))(t),e.find=e=>t=>{for(let r=0;r<t.length;r++)if(e(t[r]))return r;return-1},e.findByKey=s,e.findByVal=e=>t=>s((r=>e(t[r])))(t),e.get=(...e)=>r=>t(r,e),e.keys=l,e.last=e=>e.length-1,e.polyRemove=a,e.polySet=c,e.polyUpdate=p,e.remove=u,e.set=i,e.update=y,Object.defineProperty(e,"__esModule",{value:!0})}));