@rybr/lenses
Version:
a simple and light package meant to ease data traversal, manipulation, mutation, and transformation
1 lines • 3.96 kB
JavaScript
(()=>{var n={743:n=>{function t(n,t){var r=Object.keys(n);if(Object.getOwnPropertySymbols){var e=Object.getOwnPropertySymbols(n);t&&(e=e.filter((function(t){return Object.getOwnPropertyDescriptor(n,t).enumerable}))),r.push.apply(r,e)}return r}function r(n){for(var r=1;r<arguments.length;r++){var o=null!=arguments[r]?arguments[r]:{};r%2?t(Object(o),!0).forEach((function(t){e(n,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(o)):t(Object(o)).forEach((function(t){Object.defineProperty(n,t,Object.getOwnPropertyDescriptor(o,t))}))}return n}function e(n,t,r){return t in n?Object.defineProperty(n,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):n[t]=r,n}function o(n){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n})(n)}var i=function(n){return null==n?"".concat(n):n.constructor?n.constructor.name:"Unknown"},c=function(n,t,r,e){return n===t||n instanceof e||i(n)===e.name||o(n)===r},u={STRING:{is:function(n){return c(n,u.STRING,"string",String)},toString:function(){return"STRING"}},FUNCTION:{is:function(n){return c(n,u.FUNCTION,"function",Function)},toString:function(){return"FUNCTION"}},NUMBER:{is:function(n){return c(n,u.NUMBER,"number",Number)},toString:function(){return"NUMBER"}},OBJECT:{is:function(n){return c(n,u.OBJECT,"object",Object)},toString:function(){return"OBJECT"}},ARRAY:{is:function(n){return n===u.ARRAY||Array.isArray(n)},toString:function(){return"ARRAY"}},HTML_ELEMENT:{is:function(n){return c(n,u.HTML_ELEMENT,"object",HTMLElement)},toString:function(){return"HTML_ELEMENT"}},INVALID:{is:function(n){return n===u.INVALID},toString:function(){return"INVALID"}}};n.exports={getConstructorName:i,getOperationType:function(n){return u.STRING.is(n)&&n.trim().length>0?u.STRING:u.NUMBER.is(n)&&n>=0?u.NUMBER:u.FUNCTION.is(n)?u.FUNCTION:u.INVALID},TYPES:u,loadGlobal:function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};"undefined"!=typeof window&&(window.L=r(r({},window.L),n))}}},17:(n,t,r)=>{var e=r(743),o=e.loadGlobal,i=e.getConstructorName,c=e.TYPES,u=e.getOperationType,a=function(n,t,r,e){if(c.STRING.is(t)&&!c.OBJECT.is(n))throw new Error("Invalid Set operation at index: ".concat(e,": cannot get key ").concat(t," from ").concat(i(n)));if(c.NUMBER.is(t)&&!c.ARRAY.is(n))throw new Error("Invalid Set operation at index: ".concat(e,": cannot get index ").concat(t," from ").concat(i(n)));return Object.prototype.hasOwnProperty.call(n,t)?n[t]:r},f=function(){for(var n=arguments.length,t=new Array(n),r=0;r<n;r++)t[r]=arguments[r];return function(n){if(!c.OBJECT.is(n)&&!c.ARRAY.is(n)&&null!=n)throw new Error("Invalid Set input: expecting an Object, Array, null, or undefined but received ".concat(i(n)));var r=[].concat(t);if(null==n&&(n=c.STRING.is(u(r[0]))?{}:[]),r.length<2)throw new Error("Invalid Set: expecting a minimum of 3 arguments but received only ".concat(r.length+1));var e=r.pop(),o=n;return r.map((function(n,t){var e=u(n);if(!c.STRING.is(e)&&!c.NUMBER.is(e))throw new Error("Invalid Set operation at index: ".concat(t,": expecting a String or Number but received ").concat(i(n)));var o=u(r[t+1]);return{operation:n,defaultValue:c.STRING.is(o)?{}:[]}})).forEach((function(n,t,r){var i=n.operation,u=n.defaultValue;if(!c.OBJECT.is(o)&&!c.ARRAY.is(o)&&!c.FUNCTION.is(o))throw new Error("Invalid set operation at index: ".concat(t,": cannot set nested value on non-Object, non-Array, and non-Function entities"));o=o[i]=t===r.length-1?c.FUNCTION.is(e)?e(o[i]):e:a(o,i,u,t)})),n}};n.exports._set=f,n.exports.set=function(n){for(var t=arguments.length,r=new Array(t>1?t-1:0),e=1;e<t;e++)r[e-1]=arguments[e];return f.apply(void 0,r)(n)},o(n.exports)}},t={};!function r(e){if(t[e])return t[e].exports;var o=t[e]={exports:{}};return n[e](o,o.exports,r),o.exports}(17)})();