UNPKG

@rybr/lenses

Version:

a simple and light package meant to ease data traversal, manipulation, mutation, and transformation

1 lines 11.7 kB
(()=>{var t={472:(t,r,n)=>{function e(t,r,n){return(e=o()?Reflect.construct:function(t,r,n){var e=[null];e.push.apply(e,r);var o=new(Function.bind.apply(t,e));return n&&i(o,n.prototype),o}).apply(null,arguments)}function o(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}function i(t,r){return(i=Object.setPrototypeOf||function(t,r){return t.__proto__=r,t})(t,r)}var u=n(743),c=u.loadGlobal,a=u.getConstructorName,p=u.TYPES,s=function(t){if(!p.FUNCTION.is(t))throw new Error("func must take a function as an input, received ".concat(a(t)," instead"));return function(r){return null==r?r:t(r)}},f=function(){return function(t){return!!t}},l=function(){for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];return function(t){return parseInt.apply(void 0,[t].concat(r))}},y=function(){for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];return function(t){return parseFloat.apply(void 0,[t].concat(r))}},x=function(){return function(t){return null==t?0:Number(t).valueOf()}},d=function(){for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];return function(t){return JSON.stringify.apply(JSON,[t].concat(r))}},O=function(){for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];return function(t){return JSON.parse.apply(JSON,[t].concat(r))}},b=function(t){for(var r=arguments.length,n=new Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];return function(r){return e(t,[r].concat(n))}};t.exports.func=s,t.exports.log=function(t){var r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return function(n){var e=t?"".concat(t," ").concat(n):n;return console.log(r?JSON.stringify(e,null,2):JSON.stringify(e)),n}},t.exports.parse=function(){return s(O.apply(void 0,arguments))},t.exports.stringify=function(){return s(d.apply(void 0,arguments))},t.exports.tryParse=function(){try{return s(O.apply(void 0,arguments))}catch(t){return null}},t.exports.toBool=function(){return s(f.apply(void 0,arguments))},t.exports.toNum=function(){return s(x.apply(void 0,arguments))},t.exports.toInt=function(){return s(l.apply(void 0,arguments))},t.exports.toFloat=function(){return s(y.apply(void 0,arguments))},t.exports.toType=function(t){for(var r=arguments.length,n=new Array(r>1?r-1:0),e=1;e<r;e++)n[e-1]=arguments[e];return s(b.apply(void 0,[t].concat(n)))},t.exports.forceBool=f,t.exports.forceInt=l,t.exports.forceFloat=y,t.exports.forceNum=x,t.exports.forceString=d,t.exports.forceType=b,c(t.exports)},399:(t,r,n)=>{var e=n(743),o=e.loadGlobal,i=e.getConstructorName,u=e.TYPES,c=e.getOperationType,a=function(t,r,n){if(!u.FUNCTION.is(t))throw new Error("At index ".concat(n,": cannot apply function since it is not a Function"));return t(r)},p=function(t,r,n){var e=t.operation,o=t.type;return null==r?u.FUNCTION.is(o)?a(e,r,n):r:u.STRING.is(o)||u.NUMBER.is(o)?function(t,r){return null==r?r:Object.prototype.hasOwnProperty.call(r,t)?r[t]:void 0}(e,r):u.FUNCTION.is(o)?a(e,r,n):r},s=function(){for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];return function(t){return 0===r.length?t:[].concat(r).map((function(t,r){var n=c(t);if(u.INVALID.is(n))throw new Error("Invalid Get operation at index ".concat(r,": expecting String, Number, or Function but received ").concat(i(t)));return{operation:t,type:n}})).reduce((function(t,r,n){return p(r,t,n)}),t)}};t.exports._get=s,t.exports.defaults=function(t){return function(r){return null==r?t:r}},t.exports.get=function(t){for(var r=arguments.length,n=new Array(r>1?r-1:0),e=1;e<r;e++)n[e-1]=arguments[e];return s.apply(void 0,n)(t)},o(t.exports)},743:t=>{function r(t,r){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var e=Object.getOwnPropertySymbols(t);r&&(e=e.filter((function(r){return Object.getOwnPropertyDescriptor(t,r).enumerable}))),n.push.apply(n,e)}return n}function n(t){for(var n=1;n<arguments.length;n++){var o=null!=arguments[n]?arguments[n]:{};n%2?r(Object(o),!0).forEach((function(r){e(t,r,o[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(o)):r(Object(o)).forEach((function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(o,r))}))}return t}function e(t,r,n){return r in t?Object.defineProperty(t,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[r]=n,t}function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var i=function(t){return null==t?"".concat(t):t.constructor?t.constructor.name:"Unknown"},u=function(t,r,n,e){return t===r||t instanceof e||i(t)===e.name||o(t)===n},c={STRING:{is:function(t){return u(t,c.STRING,"string",String)},toString:function(){return"STRING"}},FUNCTION:{is:function(t){return u(t,c.FUNCTION,"function",Function)},toString:function(){return"FUNCTION"}},NUMBER:{is:function(t){return u(t,c.NUMBER,"number",Number)},toString:function(){return"NUMBER"}},OBJECT:{is:function(t){return u(t,c.OBJECT,"object",Object)},toString:function(){return"OBJECT"}},ARRAY:{is:function(t){return t===c.ARRAY||Array.isArray(t)},toString:function(){return"ARRAY"}},HTML_ELEMENT:{is:function(t){return u(t,c.HTML_ELEMENT,"object",HTMLElement)},toString:function(){return"HTML_ELEMENT"}},INVALID:{is:function(t){return t===c.INVALID},toString:function(){return"INVALID"}}};t.exports={getConstructorName:i,getOperationType:function(t){return c.STRING.is(t)&&t.trim().length>0?c.STRING:c.NUMBER.is(t)&&t>=0?c.NUMBER:c.FUNCTION.is(t)?c.FUNCTION:c.INVALID},TYPES:c,loadGlobal:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};"undefined"!=typeof window&&(window.L=n(n({},window.L),t))}}},891:(t,r,n)=>{function e(t,r){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var e=Object.getOwnPropertySymbols(t);r&&(e=e.filter((function(r){return Object.getOwnPropertyDescriptor(t,r).enumerable}))),n.push.apply(n,e)}return n}function o(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?e(Object(n),!0).forEach((function(r){i(t,r,n[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):e(Object(n)).forEach((function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))}))}return t}function i(t,r,n){return r in t?Object.defineProperty(t,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[r]=n,t}var u=n(743).loadGlobal;t.exports=o(o(o(o({},n(399)),n(17)),n(798)),n(472)),u(t.exports)},798:(t,r,n)=>{var e=n(743),o=e.loadGlobal,i=e.TYPES,u=e.getConstructorName,c=function(t){return function(){for(var r=arguments.length,n=new Array(r),e=0;e<r;e++)n[e]=arguments[e];return function(r){if(null==t||null==t.trim())throw new Error("no prototype function name specified");if(null==r)return r;if(!i.FUNCTION.is(r[t]))throw new Error("The function ".concat(t," does not exist for type ").concat(u(r)));return r[t].apply(r,n)}}},a=function(t){return null==t||(i.STRING.is(t)?!t||""==t||0===t.length:i.ARRAY.is(t)?0===t.length:!!i.OBJECT.is(t)&&0===Object.keys(t).length)};t.exports.call=function(t){for(var r=arguments.length,n=new Array(r>1?r-1:0),e=1;e<r;e++)n[e-1]=arguments[e];return function(r){return c(t).apply(void 0,n)(r)}},t.exports._call=c,t.exports.concat=c("concat"),t.exports.entries=function(){return function(t){return null==t?t:Object.entries(t)}},t.exports.every=c("every"),t.exports.fill=c("fill"),t.exports.filter=c("filter"),t.exports.find=c("find"),t.exports.findIndex=c("findIndex"),t.exports.forEach=c("forEach"),t.exports.includes=c("includes"),t.exports.indexOf=c("indexOf"),t.exports.join=c("join"),t.exports.keys=function(){return function(t){if(null==t)return t;if(i.OBJECT.is(t))return Object.keys(t);if(i.ARRAY.is(t))return Array.keys(t);throw new Error("Input must be of type Object or Array but found ".concat(u(t)))}},t.exports.lastIndexOf=c("lastIndexOf"),t.exports.map=c("map"),t.exports.push=c("push"),t.exports.reduce=c("reduce"),t.exports.reverse=c("reverse"),t.exports.slice=c("slice"),t.exports.some=c("some"),t.exports.sort=c("sort"),t.exports.splice=c("splice"),t.exports.values=function(){return function(t){if(null==t)return t;if(i.OBJECT.is(t))return Object.values(t);if(i.ARRAY.is(t))return Array.values(t);throw new Error("Input must be of type Object or Array but found ".concat(u(t)))}},t.exports.assign=function(){for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];return function(t){return null==t?t:Object.assign.apply(Object,[t].concat(r))}},t.exports.hasOwnProperty=function(t){return function(r){return null==r?r:Object.prototype.hasOwnProperty.call(r,t)}},t.exports.trim=c("trim"),t.exports.toLowerCase=c("toLowerCase"),t.exports.toUpperCase=c("toUpperCase"),t.exports.is=function(t){return function(r){return r===t||Object.is(r,t)}},t.exports.replace=c("replace"),t.exports.replaceAll=c("replaceAll"),t.exports.padEnd=c("padEnd"),t.exports.padStart=c("padStart"),t.exports.repeat=c("repeat"),t.exports.charAt=c("charAt"),t.exports.charCodeAt=c("charCodeAt"),t.exports.endsWith=c("endsWith"),t.exports.startsWith=c("startsWith"),t.exports.match=c("match"),t.exports.matchAll=c("matchAll"),t.exports.normalize=c("normalize"),t.exports.split=c("split"),t.exports.substring=c("substring"),t.exports.toLowerCase=c("toLowerCase"),t.exports.toUpperCase=c("toUpperCase"),t.exports.trim=c("trim"),t.exports.trimStart=c("trimStart"),t.exports.trimEnd=c("trimEnd"),t.exports.isArray=function(t){return null==t?t:Array.isArray(t)},t.exports.isEmpty=function(){return function(t){return a(t)}},t.exports.isNotEmpty=function(){return function(t){return!a(t)}},o(t.exports)},17:(t,r,n)=>{var e=n(743),o=e.loadGlobal,i=e.getConstructorName,u=e.TYPES,c=e.getOperationType,a=function(t,r,n,e){if(u.STRING.is(r)&&!u.OBJECT.is(t))throw new Error("Invalid Set operation at index: ".concat(e,": cannot get key ").concat(r," from ").concat(i(t)));if(u.NUMBER.is(r)&&!u.ARRAY.is(t))throw new Error("Invalid Set operation at index: ".concat(e,": cannot get index ").concat(r," from ").concat(i(t)));return Object.prototype.hasOwnProperty.call(t,r)?t[r]:n},p=function(){for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];return function(t){if(!u.OBJECT.is(t)&&!u.ARRAY.is(t)&&null!=t)throw new Error("Invalid Set input: expecting an Object, Array, null, or undefined but received ".concat(i(t)));var n=[].concat(r);if(null==t&&(t=u.STRING.is(c(n[0]))?{}:[]),n.length<2)throw new Error("Invalid Set: expecting a minimum of 3 arguments but received only ".concat(n.length+1));var e=n.pop(),o=t;return n.map((function(t,r){var e=c(t);if(!u.STRING.is(e)&&!u.NUMBER.is(e))throw new Error("Invalid Set operation at index: ".concat(r,": expecting a String or Number but received ").concat(i(t)));var o=c(n[r+1]);return{operation:t,defaultValue:u.STRING.is(o)?{}:[]}})).forEach((function(t,r,n){var i=t.operation,c=t.defaultValue;if(!u.OBJECT.is(o)&&!u.ARRAY.is(o)&&!u.FUNCTION.is(o))throw new Error("Invalid set operation at index: ".concat(r,": cannot set nested value on non-Object, non-Array, and non-Function entities"));o=o[i]=r===n.length-1?u.FUNCTION.is(e)?e(o[i]):e:a(o,i,c,r)})),t}};t.exports._set=p,t.exports.set=function(t){for(var r=arguments.length,n=new Array(r>1?r-1:0),e=1;e<r;e++)n[e-1]=arguments[e];return p.apply(void 0,n)(t)},o(t.exports)}},r={};!function n(e){if(r[e])return r[e].exports;var o=r[e]={exports:{}};return t[e](o,o.exports,n),o.exports}(891)})();