@knighttower/utility
Advanced tools
Comparing version 4.2.19 to 4.2.20
@@ -411,2 +411,17 @@ define(['exports'], (function (exports) { 'use strict'; | ||
/** | ||
* Get an object from a path | ||
* @function getObjectFromPath | ||
* @param {String} path - The path to the object | ||
* @param {Object} source - The source object to search in | ||
* @return {Object} - The object found at the path | ||
* @example getObjectFromPath('a.b.c', {a: {b: {c: 'value'}}}) // 'value' | ||
* @example getObjectFromPath('a.b.c') // 'value' | ||
* @example getObjectFromPath('a.b.c', window) // value | ||
* @example getObjectFromPath('a.b.c', source) // value | ||
*/ | ||
function getObjectFromPath(path, source = window) { | ||
return path.split('.').reduce((acc, part) => acc && acc[part], source); | ||
} | ||
/** | ||
* Converts strings formats into objects or arrays | ||
@@ -541,3 +556,5 @@ * Note: quoted strings are not supported, use getDirectiveFromString instead | ||
const directive = str.split('(')[0].trim(); | ||
return results('idOrClassWithDirective', { [directive]: getMatchInBetween(str, '(', ')') }); | ||
return results('idOrClassWithDirective', { | ||
[directive]: getMatchInBetween(str, '(', ')'), | ||
}); | ||
case !!str.match(regexDotObjectString): | ||
@@ -708,3 +725,5 @@ // Matches object-style strings: directive.tablet(...values) OR directive[expression](...values) | ||
.map((char) => | ||
['$', '^', '.', '*', '+', '?', '(', ')', '[', ']', '{', '}', '|', '\\'].includes(char) | ||
['$', '^', '.', '*', '+', '?', '(', ')', '[', ']', '{', '}', '|', '\\'].includes( | ||
char | ||
) | ||
? `\\${char}` | ||
@@ -825,2 +844,3 @@ : char | ||
getMatchInBetween, | ||
getObjectFromPath, | ||
removeQuotes, | ||
@@ -847,2 +867,3 @@ startAndEndWith, | ||
exports.getMatchInBetween = getMatchInBetween; | ||
exports.getObjectFromPath = getObjectFromPath; | ||
exports.powerHelper = powerHelper; | ||
@@ -849,0 +870,0 @@ exports.removeQuotes = removeQuotes; |
@@ -1,1 +0,1 @@ | ||
(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function r(e){switch(typeof e){case"boolean":return e;case"string":return"false"!==e&&"0"!==e;case"number":return 0!==e;default:return Boolean(e)}}function n(e,t=null){return null!==u(e)||"boolean"==typeof e?e:i(e)?t:e}e.r(t),e.d(t,{PowerHelper:()=>O,addQuotes:()=>a,cleanStr:()=>s,convertKeysToSymbols:()=>l,default:()=>O,findAndReplaceInArray:()=>f,findNested:()=>g,fixQuotes:()=>p,getArrObjFromString:()=>y,getChunks:()=>b,getDirectivesFromString:()=>d,getMatchBlock:()=>m,getMatchInBetween:()=>h,powerHelper:()=>O,removeQuotes:()=>S,setExpString:()=>A,setLookUpExp:()=>j,setWildCardString:()=>E,startAndEndWith:()=>w,wildCardStringSearch:()=>k});const o=function(){return"kn__"+(new Date).getTime()+"__"+Math.floor(899*Math.random())};function i(e){return null==e||("string"==typeof e||Array.isArray(e)?0===e.length:e instanceof Map||e instanceof Set?0===e.size:ArrayBuffer.isView(e)?0===e.byteLength:"object"==typeof e&&0===Object.keys(e).length)}function u(e){const t=typeof e;switch(e){case null:case void 0:case"":return null;case"0":case 0:return 0;default:if(!("number"!==t&&"string"!==t||"number"!=typeof e&&Number.isNaN(Number(e))))return+e}return null}function c(e,t){if(null===e)return t?null===t||"null"===t:"null";let r;switch(typeof e){case"number":case"string":case"boolean":case"undefined":case"bigint":case"symbol":case"function":r=typeof e;break;case"object":r=Array.isArray(e)?"array":"object";break;default:r="unknown"}if(t){if(t.includes("|")){for(let e of t.split("|"))if(r===e)return e;return!1}return t===r}return r}function a(e,t='"'){return`${t}${e}${t}`}function s(e,...t){if(e)return"string"!=typeof e?e:t.reduce(((e,t)=>{const r=t instanceof RegExp?t:new RegExp(A(t));return e.replace(r,"")}),e).trim()}function l(e){if(null===n(e,null))return{};const t={},r={};for(const n in e){const o=Symbol(n);t[o]=e[n],r[n]=o}return t.keyToSymbolMap=r,t}function f(e,t,r){let n=!1;const o=e.map((e=>{if(Array.isArray(e)){const o=f(e,t,r);return o?(n=!0,o):e}return e===t?(n=!0,Array.isArray(r)?r.map((e=>Array.isArray(e)?e:e.trim())):r):e}));return n?o:null}function g(e,t="[",r="]"){if("string"!=typeof e)return e;const n=e.lastIndexOf(t);if(-1===n)return null;const o=e.substring(n),i=o.indexOf(r);return-1===i?null:o.substring(0,i+1)}function p(e,t='"'){return"string"!=typeof e?e:e.replace(/`|'|"/g,t)}function y(e){if(c(e,"object")||c(e,"array"))return e;const t=w(e,"{","}"),r=w(e,"[","]");if(!t&&!r)return e;const i=t?{}:[],a={};let s=function(e){const t=e.match(/^(\[|\{)(.*?)(\]|\})$/);return t?t[2].trim():e}(e);const l=(e=!1)=>{for(;;){let t=e?g(s,"{","}"):g(s);if(!t)break;let r=`__${o()}__`;a[r]=t,s=s.replace(t,r)}};return l(),l(!0),b(s).forEach(((e,r)=>{const o=e.includes(":")&&t,c=o?b(e,":"):[],s=S(n(c[0],r));(e=o?c[1]:e)in a&&(e=y(a[e])),e=function(e){const t=u(e);return null!==t?t:e}(S(e)),t?i[s]=e:i.push(e)})),i}function d(e){const t=e;if(!n(t))return null;const r=(e=null,t=null)=>({type:e,directive:t}),o=/^\[((.|\n)*?)\]$/gm,i=/^\{((.|\n)*?)\:((.|\n)*?)\}/gm,u=/^([a-zA-Z]+)(\()(\.|\#)(.*)(\))/g,c=/([a-zA-Z]+)\.(.*?)\(((.|\n)*?)\)/gm,a=/([a-zA-Z]+)\[((.|\n)*?)\]\(((.|\n)*?)\)/gm;let s=typeof t;if("object"===s||"array"===s)return r(s,t);switch(!0){case!!t.match(o):s="array";break;case!!t.match(i):s="object";break;case!!t.match(u):return r("idOrClassWithDirective",{[t.split("(")[0].trim()]:h(t,"(",")")});case!!t.match(c):case!!t.match(a):s="dotObject";break;default:return r("string",t)}if("array"===s||"object"===s){let e=p(t);try{return r(s,JSON.parse(e))}catch(e){}return r(s,y(e))}if("dotObject"===s){let e,n,o;const i={};return b(t,"&&").forEach((t=>{t.match(a)?(e=h(t,"](",")"),n=h(t,"[","]"),o=t.split("[")[0].trim()):(e=h(t,"(",")"),t=t.replace(m(t,"(",")"),""),[o,n]=b(t,".")),e=y(e),i[o]||(i[o]={}),b(n,"|").forEach((t=>{i[o][t]=e}))})),r("dotObject",i)}}function m(e,t,r,n=!1){if("string"!=typeof e)return e;t=A(t),r=A(r);let o=new RegExp(j(t,r),"gm");const i=e.match(o);return i?n?i:i[0]:null}function b(e,t=","){if("string"!=typeof e)return e;if(i(e))return[];let r=(e=s(e)).split(t).map((e=>s(e)));return 1===r.length&&""===r[0]?[e]:r}function h(e,t,r,n=!1){if("string"!=typeof e)return e;const o=m(e,t,r,n)??(n?[]:e);return n?o.map((e=>s(e,t,r))):s(o,t,r)}function S(e){return"string"!=typeof e?e:e.replace(/`|'|"/g,"")}function w(e,t=null,r=null){return(!t||e.startsWith(t))&&(!r||e.endsWith(r))}function A(e){return e instanceof RegExp?e:e.split("").map((e=>["$","^",".","*","+","?","(",")","[","]","{","}","|","\\"].includes(e)?`\\${e}`:e)).join("")}function j(...e){if(e.length<2)throw new Error("You need to pass at least two arguments");let t="";return e.forEach(((e,r)=>{e instanceof RegExp&&(e=e.source),0===r?t=e:t+=`((.|\n)*?)${e}`})),t}function E(e,t=!1,n=!1){if("string"!=typeof e)return e;if(!e)return null;t=r(t),n=r(n);let o=e.replace(/([.+?^${}()|\[\]\/\\])/g,"\\$&"),i=t?"^":"",u=n?"$":"";return o=o.replace(/\*\*/g,"[_g_]").replace(/\*/g,"(.*?)").replace(/\[_g_\]/g,".*"),`${i}${o}${u}`}function k(e,t,r=!1,o=!1){if(!e||!t)return null;const i=new RegExp(E(e,r,o));if("string"==typeof t)return n(t.match(i));let u=[];return u=t.filter((e=>i.test(e))),n(u)}const O={addQuotes:a,cleanStr:s,convertKeysToSymbols:l,findAndReplaceInArray:f,findNested:g,fixQuotes:p,getArrObjFromString:y,getChunks:b,getDirectivesFromString:d,getMatchBlock:m,getMatchInBetween:h,removeQuotes:S,startAndEndWith:w,setExpString:A,setLookUpExp:j,setWildCardString:E,wildCardStringSearch:k};window.PowerHelpers=t})(); | ||
(()=>{"use strict";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};function r(t){switch(typeof t){case"boolean":return t;case"string":return"false"!==t&&"0"!==t;case"number":return 0!==t;default:return Boolean(t)}}function n(t,e=null){return null!==u(t)||"boolean"==typeof t?t:i(t)?e:t}t.r(e),t.d(e,{PowerHelper:()=>$,addQuotes:()=>a,cleanStr:()=>s,convertKeysToSymbols:()=>l,default:()=>$,findAndReplaceInArray:()=>f,findNested:()=>g,fixQuotes:()=>p,getArrObjFromString:()=>y,getChunks:()=>h,getDirectivesFromString:()=>m,getMatchBlock:()=>b,getMatchInBetween:()=>w,getObjectFromPath:()=>d,powerHelper:()=>$,removeQuotes:()=>S,setExpString:()=>j,setLookUpExp:()=>E,setWildCardString:()=>O,startAndEndWith:()=>A,wildCardStringSearch:()=>k});const o=function(){return"kn__"+(new Date).getTime()+"__"+Math.floor(899*Math.random())};function i(t){return null==t||("string"==typeof t||Array.isArray(t)?0===t.length:t instanceof Map||t instanceof Set?0===t.size:ArrayBuffer.isView(t)?0===t.byteLength:"object"==typeof t&&0===Object.keys(t).length)}function u(t){const e=typeof t;switch(t){case null:case void 0:case"":return null;case"0":case 0:return 0;default:if(!("number"!==e&&"string"!==e||"number"!=typeof t&&Number.isNaN(Number(t))))return+t}return null}function c(t,e){if(null===t)return e?null===e||"null"===e:"null";let r;switch(typeof t){case"number":case"string":case"boolean":case"undefined":case"bigint":case"symbol":case"function":r=typeof t;break;case"object":r=Array.isArray(t)?"array":"object";break;default:r="unknown"}if(e){if(e.includes("|")){for(let t of e.split("|"))if(r===t)return t;return!1}return e===r}return r}function a(t,e='"'){return`${e}${t}${e}`}function s(t,...e){if(t)return"string"!=typeof t?t:e.reduce(((t,e)=>{const r=e instanceof RegExp?e:new RegExp(j(e));return t.replace(r,"")}),t).trim()}function l(t){if(null===n(t,null))return{};const e={},r={};for(const n in t){const o=Symbol(n);e[o]=t[n],r[n]=o}return e.keyToSymbolMap=r,e}function f(t,e,r){let n=!1;const o=t.map((t=>{if(Array.isArray(t)){const o=f(t,e,r);return o?(n=!0,o):t}return t===e?(n=!0,Array.isArray(r)?r.map((t=>Array.isArray(t)?t:t.trim())):r):t}));return n?o:null}function g(t,e="[",r="]"){if("string"!=typeof t)return t;const n=t.lastIndexOf(e);if(-1===n)return null;const o=t.substring(n),i=o.indexOf(r);return-1===i?null:o.substring(0,i+1)}function p(t,e='"'){return"string"!=typeof t?t:t.replace(/`|'|"/g,e)}function d(t,e=window){return t.split(".").reduce(((t,e)=>t&&t[e]),e)}function y(t){if(c(t,"object")||c(t,"array"))return t;const e=A(t,"{","}"),r=A(t,"[","]");if(!e&&!r)return t;const i=e?{}:[],a={};let s=function(t){const e=t.match(/^(\[|\{)(.*?)(\]|\})$/);return e?e[2].trim():t}(t);const l=(t=!1)=>{for(;;){let e=t?g(s,"{","}"):g(s);if(!e)break;let r=`__${o()}__`;a[r]=e,s=s.replace(e,r)}};return l(),l(!0),h(s).forEach(((t,r)=>{const o=t.includes(":")&&e,c=o?h(t,":"):[],s=S(n(c[0],r));(t=o?c[1]:t)in a&&(t=y(a[t])),t=function(t){const e=u(t);return null!==e?e:t}(S(t)),e?i[s]=t:i.push(t)})),i}function m(t){const e=t;if(!n(e))return null;const r=(t=null,e=null)=>({type:t,directive:e}),o=/^\[((.|\n)*?)\]$/gm,i=/^\{((.|\n)*?)\:((.|\n)*?)\}/gm,u=/^([a-zA-Z]+)(\()(\.|\#)(.*)(\))/g,c=/([a-zA-Z]+)\.(.*?)\(((.|\n)*?)\)/gm,a=/([a-zA-Z]+)\[((.|\n)*?)\]\(((.|\n)*?)\)/gm;let s=typeof e;if("object"===s||"array"===s)return r(s,e);switch(!0){case!!e.match(o):s="array";break;case!!e.match(i):s="object";break;case!!e.match(u):return r("idOrClassWithDirective",{[e.split("(")[0].trim()]:w(e,"(",")")});case!!e.match(c):case!!e.match(a):s="dotObject";break;default:return r("string",e)}if("array"===s||"object"===s){let t=p(e);try{return r(s,JSON.parse(t))}catch(t){}return r(s,y(t))}if("dotObject"===s){let t,n,o;const i={};return h(e,"&&").forEach((e=>{e.match(a)?(t=w(e,"](",")"),n=w(e,"[","]"),o=e.split("[")[0].trim()):(t=w(e,"(",")"),e=e.replace(b(e,"(",")"),""),[o,n]=h(e,".")),t=y(t),i[o]||(i[o]={}),h(n,"|").forEach((e=>{i[o][e]=t}))})),r("dotObject",i)}}function b(t,e,r,n=!1){if("string"!=typeof t)return t;e=j(e),r=j(r);let o=new RegExp(E(e,r),"gm");const i=t.match(o);return i?n?i:i[0]:null}function h(t,e=","){if("string"!=typeof t)return t;if(i(t))return[];let r=(t=s(t)).split(e).map((t=>s(t)));return 1===r.length&&""===r[0]?[t]:r}function w(t,e,r,n=!1){if("string"!=typeof t)return t;const o=b(t,e,r,n)??(n?[]:t);return n?o.map((t=>s(t,e,r))):s(o,e,r)}function S(t){return"string"!=typeof t?t:t.replace(/`|'|"/g,"")}function A(t,e=null,r=null){return(!e||t.startsWith(e))&&(!r||t.endsWith(r))}function j(t){return t instanceof RegExp?t:t.split("").map((t=>["$","^",".","*","+","?","(",")","[","]","{","}","|","\\"].includes(t)?`\\${t}`:t)).join("")}function E(...t){if(t.length<2)throw new Error("You need to pass at least two arguments");let e="";return t.forEach(((t,r)=>{t instanceof RegExp&&(t=t.source),0===r?e=t:e+=`((.|\n)*?)${t}`})),e}function O(t,e=!1,n=!1){if("string"!=typeof t)return t;if(!t)return null;e=r(e),n=r(n);let o=t.replace(/([.+?^${}()|\[\]\/\\])/g,"\\$&"),i=e?"^":"",u=n?"$":"";return o=o.replace(/\*\*/g,"[_g_]").replace(/\*/g,"(.*?)").replace(/\[_g_\]/g,".*"),`${i}${o}${u}`}function k(t,e,r=!1,o=!1){if(!t||!e)return null;const i=new RegExp(O(t,r,o));if("string"==typeof e)return n(e.match(i));let u=[];return u=e.filter((t=>i.test(t))),n(u)}const $={addQuotes:a,cleanStr:s,convertKeysToSymbols:l,findAndReplaceInArray:f,findNested:g,fixQuotes:p,getArrObjFromString:y,getChunks:h,getDirectivesFromString:m,getMatchBlock:b,getMatchInBetween:w,getObjectFromPath:d,removeQuotes:S,startAndEndWith:A,setExpString:j,setLookUpExp:E,setWildCardString:O,wildCardStringSearch:k};window.PowerHelpers=e})(); |
@@ -412,2 +412,17 @@ var PowerHelpers = (function (exports) { | ||
/** | ||
* Get an object from a path | ||
* @function getObjectFromPath | ||
* @param {String} path - The path to the object | ||
* @param {Object} source - The source object to search in | ||
* @return {Object} - The object found at the path | ||
* @example getObjectFromPath('a.b.c', {a: {b: {c: 'value'}}}) // 'value' | ||
* @example getObjectFromPath('a.b.c') // 'value' | ||
* @example getObjectFromPath('a.b.c', window) // value | ||
* @example getObjectFromPath('a.b.c', source) // value | ||
*/ | ||
function getObjectFromPath(path, source = window) { | ||
return path.split('.').reduce((acc, part) => acc && acc[part], source); | ||
} | ||
/** | ||
* Converts strings formats into objects or arrays | ||
@@ -542,3 +557,5 @@ * Note: quoted strings are not supported, use getDirectiveFromString instead | ||
const directive = str.split('(')[0].trim(); | ||
return results('idOrClassWithDirective', { [directive]: getMatchInBetween(str, '(', ')') }); | ||
return results('idOrClassWithDirective', { | ||
[directive]: getMatchInBetween(str, '(', ')'), | ||
}); | ||
case !!str.match(regexDotObjectString): | ||
@@ -709,3 +726,5 @@ // Matches object-style strings: directive.tablet(...values) OR directive[expression](...values) | ||
.map((char) => | ||
['$', '^', '.', '*', '+', '?', '(', ')', '[', ']', '{', '}', '|', '\\'].includes(char) | ||
['$', '^', '.', '*', '+', '?', '(', ')', '[', ']', '{', '}', '|', '\\'].includes( | ||
char | ||
) | ||
? `\\${char}` | ||
@@ -826,2 +845,3 @@ : char | ||
getMatchInBetween, | ||
getObjectFromPath, | ||
removeQuotes, | ||
@@ -848,2 +868,3 @@ startAndEndWith, | ||
exports.getMatchInBetween = getMatchInBetween; | ||
exports.getObjectFromPath = getObjectFromPath; | ||
exports.powerHelper = powerHelper; | ||
@@ -850,0 +871,0 @@ exports.removeQuotes = removeQuotes; |
@@ -18,2 +18,3 @@ System.register('PowerHelpers', [], (function (exports) { | ||
getMatchInBetween: getMatchInBetween, | ||
getObjectFromPath: getObjectFromPath, | ||
removeQuotes: removeQuotes, | ||
@@ -435,2 +436,17 @@ setExpString: setExpString, | ||
/** | ||
* Get an object from a path | ||
* @function getObjectFromPath | ||
* @param {String} path - The path to the object | ||
* @param {Object} source - The source object to search in | ||
* @return {Object} - The object found at the path | ||
* @example getObjectFromPath('a.b.c', {a: {b: {c: 'value'}}}) // 'value' | ||
* @example getObjectFromPath('a.b.c') // 'value' | ||
* @example getObjectFromPath('a.b.c', window) // value | ||
* @example getObjectFromPath('a.b.c', source) // value | ||
*/ | ||
function getObjectFromPath(path, source = window) { | ||
return path.split('.').reduce((acc, part) => acc && acc[part], source); | ||
} | ||
/** | ||
* Converts strings formats into objects or arrays | ||
@@ -565,3 +581,5 @@ * Note: quoted strings are not supported, use getDirectiveFromString instead | ||
const directive = str.split('(')[0].trim(); | ||
return results('idOrClassWithDirective', { [directive]: getMatchInBetween(str, '(', ')') }); | ||
return results('idOrClassWithDirective', { | ||
[directive]: getMatchInBetween(str, '(', ')'), | ||
}); | ||
case !!str.match(regexDotObjectString): | ||
@@ -732,3 +750,5 @@ // Matches object-style strings: directive.tablet(...values) OR directive[expression](...values) | ||
.map((char) => | ||
['$', '^', '.', '*', '+', '?', '(', ')', '[', ']', '{', '}', '|', '\\'].includes(char) | ||
['$', '^', '.', '*', '+', '?', '(', ')', '[', ']', '{', '}', '|', '\\'].includes( | ||
char | ||
) | ||
? `\\${char}` | ||
@@ -849,2 +869,3 @@ : char | ||
getMatchInBetween, | ||
getObjectFromPath, | ||
removeQuotes, | ||
@@ -851,0 +872,0 @@ startAndEndWith, |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("PowerHelpers",[],t):"object"==typeof exports?exports.PowerHelpers=t():e.PowerHelpers=t()}(self,(()=>(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function r(e){switch(typeof e){case"boolean":return e;case"string":return"false"!==e&&"0"!==e;case"number":return 0!==e;default:return Boolean(e)}}function n(e,t=null){return null!==u(e)||"boolean"==typeof e?e:i(e)?t:e}e.r(t),e.d(t,{PowerHelper:()=>k,addQuotes:()=>s,cleanStr:()=>a,convertKeysToSymbols:()=>l,default:()=>k,findAndReplaceInArray:()=>f,findNested:()=>p,fixQuotes:()=>g,getArrObjFromString:()=>d,getChunks:()=>b,getDirectivesFromString:()=>y,getMatchBlock:()=>m,getMatchInBetween:()=>h,powerHelper:()=>k,removeQuotes:()=>S,setExpString:()=>A,setLookUpExp:()=>j,setWildCardString:()=>x,startAndEndWith:()=>w,wildCardStringSearch:()=>E});const o=function(){return"kn__"+(new Date).getTime()+"__"+Math.floor(899*Math.random())};function i(e){return null==e||("string"==typeof e||Array.isArray(e)?0===e.length:e instanceof Map||e instanceof Set?0===e.size:ArrayBuffer.isView(e)?0===e.byteLength:"object"==typeof e&&0===Object.keys(e).length)}function u(e){const t=typeof e;switch(e){case null:case void 0:case"":return null;case"0":case 0:return 0;default:if(!("number"!==t&&"string"!==t||"number"!=typeof e&&Number.isNaN(Number(e))))return+e}return null}function c(e,t){if(null===e)return t?null===t||"null"===t:"null";let r;switch(typeof e){case"number":case"string":case"boolean":case"undefined":case"bigint":case"symbol":case"function":r=typeof e;break;case"object":r=Array.isArray(e)?"array":"object";break;default:r="unknown"}if(t){if(t.includes("|")){for(let e of t.split("|"))if(r===e)return e;return!1}return t===r}return r}function s(e,t='"'){return`${t}${e}${t}`}function a(e,...t){if(e)return"string"!=typeof e?e:t.reduce(((e,t)=>{const r=t instanceof RegExp?t:new RegExp(A(t));return e.replace(r,"")}),e).trim()}function l(e){if(null===n(e,null))return{};const t={},r={};for(const n in e){const o=Symbol(n);t[o]=e[n],r[n]=o}return t.keyToSymbolMap=r,t}function f(e,t,r){let n=!1;const o=e.map((e=>{if(Array.isArray(e)){const o=f(e,t,r);return o?(n=!0,o):e}return e===t?(n=!0,Array.isArray(r)?r.map((e=>Array.isArray(e)?e:e.trim())):r):e}));return n?o:null}function p(e,t="[",r="]"){if("string"!=typeof e)return e;const n=e.lastIndexOf(t);if(-1===n)return null;const o=e.substring(n),i=o.indexOf(r);return-1===i?null:o.substring(0,i+1)}function g(e,t='"'){return"string"!=typeof e?e:e.replace(/`|'|"/g,t)}function d(e){if(c(e,"object")||c(e,"array"))return e;const t=w(e,"{","}"),r=w(e,"[","]");if(!t&&!r)return e;const i=t?{}:[],s={};let a=function(e){const t=e.match(/^(\[|\{)(.*?)(\]|\})$/);return t?t[2].trim():e}(e);const l=(e=!1)=>{for(;;){let t=e?p(a,"{","}"):p(a);if(!t)break;let r=`__${o()}__`;s[r]=t,a=a.replace(t,r)}};return l(),l(!0),b(a).forEach(((e,r)=>{const o=e.includes(":")&&t,c=o?b(e,":"):[],a=S(n(c[0],r));(e=o?c[1]:e)in s&&(e=d(s[e])),e=function(e){const t=u(e);return null!==t?t:e}(S(e)),t?i[a]=e:i.push(e)})),i}function y(e){const t=e;if(!n(t))return null;const r=(e=null,t=null)=>({type:e,directive:t}),o=/^\[((.|\n)*?)\]$/gm,i=/^\{((.|\n)*?)\:((.|\n)*?)\}/gm,u=/^([a-zA-Z]+)(\()(\.|\#)(.*)(\))/g,c=/([a-zA-Z]+)\.(.*?)\(((.|\n)*?)\)/gm,s=/([a-zA-Z]+)\[((.|\n)*?)\]\(((.|\n)*?)\)/gm;let a=typeof t;if("object"===a||"array"===a)return r(a,t);switch(!0){case!!t.match(o):a="array";break;case!!t.match(i):a="object";break;case!!t.match(u):return r("idOrClassWithDirective",{[t.split("(")[0].trim()]:h(t,"(",")")});case!!t.match(c):case!!t.match(s):a="dotObject";break;default:return r("string",t)}if("array"===a||"object"===a){let e=g(t);try{return r(a,JSON.parse(e))}catch(e){}return r(a,d(e))}if("dotObject"===a){let e,n,o;const i={};return b(t,"&&").forEach((t=>{t.match(s)?(e=h(t,"](",")"),n=h(t,"[","]"),o=t.split("[")[0].trim()):(e=h(t,"(",")"),t=t.replace(m(t,"(",")"),""),[o,n]=b(t,".")),e=d(e),i[o]||(i[o]={}),b(n,"|").forEach((t=>{i[o][t]=e}))})),r("dotObject",i)}}function m(e,t,r,n=!1){if("string"!=typeof e)return e;t=A(t),r=A(r);let o=new RegExp(j(t,r),"gm");const i=e.match(o);return i?n?i:i[0]:null}function b(e,t=","){if("string"!=typeof e)return e;if(i(e))return[];let r=(e=a(e)).split(t).map((e=>a(e)));return 1===r.length&&""===r[0]?[e]:r}function h(e,t,r,n=!1){if("string"!=typeof e)return e;const o=m(e,t,r,n)??(n?[]:e);return n?o.map((e=>a(e,t,r))):a(o,t,r)}function S(e){return"string"!=typeof e?e:e.replace(/`|'|"/g,"")}function w(e,t=null,r=null){return(!t||e.startsWith(t))&&(!r||e.endsWith(r))}function A(e){return e instanceof RegExp?e:e.split("").map((e=>["$","^",".","*","+","?","(",")","[","]","{","}","|","\\"].includes(e)?`\\${e}`:e)).join("")}function j(...e){if(e.length<2)throw new Error("You need to pass at least two arguments");let t="";return e.forEach(((e,r)=>{e instanceof RegExp&&(e=e.source),0===r?t=e:t+=`((.|\n)*?)${e}`})),t}function x(e,t=!1,n=!1){if("string"!=typeof e)return e;if(!e)return null;t=r(t),n=r(n);let o=e.replace(/([.+?^${}()|\[\]\/\\])/g,"\\$&"),i=t?"^":"",u=n?"$":"";return o=o.replace(/\*\*/g,"[_g_]").replace(/\*/g,"(.*?)").replace(/\[_g_\]/g,".*"),`${i}${o}${u}`}function E(e,t,r=!1,o=!1){if(!e||!t)return null;const i=new RegExp(x(e,r,o));if("string"==typeof t)return n(t.match(i));let u=[];return u=t.filter((e=>i.test(e))),n(u)}const k={addQuotes:s,cleanStr:a,convertKeysToSymbols:l,findAndReplaceInArray:f,findNested:p,fixQuotes:g,getArrObjFromString:d,getChunks:b,getDirectivesFromString:y,getMatchBlock:m,getMatchInBetween:h,removeQuotes:S,startAndEndWith:w,setExpString:A,setLookUpExp:j,setWildCardString:x,wildCardStringSearch:E};return t})())); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("PowerHelpers",[],t):"object"==typeof exports?exports.PowerHelpers=t():e.PowerHelpers=t()}(self,(()=>(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function r(e){switch(typeof e){case"boolean":return e;case"string":return"false"!==e&&"0"!==e;case"number":return 0!==e;default:return Boolean(e)}}function n(e,t=null){return null!==u(e)||"boolean"==typeof e?e:i(e)?t:e}e.r(t),e.d(t,{PowerHelper:()=>k,addQuotes:()=>a,cleanStr:()=>s,convertKeysToSymbols:()=>l,default:()=>k,findAndReplaceInArray:()=>f,findNested:()=>p,fixQuotes:()=>g,getArrObjFromString:()=>y,getChunks:()=>h,getDirectivesFromString:()=>m,getMatchBlock:()=>b,getMatchInBetween:()=>w,getObjectFromPath:()=>d,powerHelper:()=>k,removeQuotes:()=>S,setExpString:()=>A,setLookUpExp:()=>x,setWildCardString:()=>E,startAndEndWith:()=>j,wildCardStringSearch:()=>O});const o=function(){return"kn__"+(new Date).getTime()+"__"+Math.floor(899*Math.random())};function i(e){return null==e||("string"==typeof e||Array.isArray(e)?0===e.length:e instanceof Map||e instanceof Set?0===e.size:ArrayBuffer.isView(e)?0===e.byteLength:"object"==typeof e&&0===Object.keys(e).length)}function u(e){const t=typeof e;switch(e){case null:case void 0:case"":return null;case"0":case 0:return 0;default:if(!("number"!==t&&"string"!==t||"number"!=typeof e&&Number.isNaN(Number(e))))return+e}return null}function c(e,t){if(null===e)return t?null===t||"null"===t:"null";let r;switch(typeof e){case"number":case"string":case"boolean":case"undefined":case"bigint":case"symbol":case"function":r=typeof e;break;case"object":r=Array.isArray(e)?"array":"object";break;default:r="unknown"}if(t){if(t.includes("|")){for(let e of t.split("|"))if(r===e)return e;return!1}return t===r}return r}function a(e,t='"'){return`${t}${e}${t}`}function s(e,...t){if(e)return"string"!=typeof e?e:t.reduce(((e,t)=>{const r=t instanceof RegExp?t:new RegExp(A(t));return e.replace(r,"")}),e).trim()}function l(e){if(null===n(e,null))return{};const t={},r={};for(const n in e){const o=Symbol(n);t[o]=e[n],r[n]=o}return t.keyToSymbolMap=r,t}function f(e,t,r){let n=!1;const o=e.map((e=>{if(Array.isArray(e)){const o=f(e,t,r);return o?(n=!0,o):e}return e===t?(n=!0,Array.isArray(r)?r.map((e=>Array.isArray(e)?e:e.trim())):r):e}));return n?o:null}function p(e,t="[",r="]"){if("string"!=typeof e)return e;const n=e.lastIndexOf(t);if(-1===n)return null;const o=e.substring(n),i=o.indexOf(r);return-1===i?null:o.substring(0,i+1)}function g(e,t='"'){return"string"!=typeof e?e:e.replace(/`|'|"/g,t)}function d(e,t=window){return e.split(".").reduce(((e,t)=>e&&e[t]),t)}function y(e){if(c(e,"object")||c(e,"array"))return e;const t=j(e,"{","}"),r=j(e,"[","]");if(!t&&!r)return e;const i=t?{}:[],a={};let s=function(e){const t=e.match(/^(\[|\{)(.*?)(\]|\})$/);return t?t[2].trim():e}(e);const l=(e=!1)=>{for(;;){let t=e?p(s,"{","}"):p(s);if(!t)break;let r=`__${o()}__`;a[r]=t,s=s.replace(t,r)}};return l(),l(!0),h(s).forEach(((e,r)=>{const o=e.includes(":")&&t,c=o?h(e,":"):[],s=S(n(c[0],r));(e=o?c[1]:e)in a&&(e=y(a[e])),e=function(e){const t=u(e);return null!==t?t:e}(S(e)),t?i[s]=e:i.push(e)})),i}function m(e){const t=e;if(!n(t))return null;const r=(e=null,t=null)=>({type:e,directive:t}),o=/^\[((.|\n)*?)\]$/gm,i=/^\{((.|\n)*?)\:((.|\n)*?)\}/gm,u=/^([a-zA-Z]+)(\()(\.|\#)(.*)(\))/g,c=/([a-zA-Z]+)\.(.*?)\(((.|\n)*?)\)/gm,a=/([a-zA-Z]+)\[((.|\n)*?)\]\(((.|\n)*?)\)/gm;let s=typeof t;if("object"===s||"array"===s)return r(s,t);switch(!0){case!!t.match(o):s="array";break;case!!t.match(i):s="object";break;case!!t.match(u):return r("idOrClassWithDirective",{[t.split("(")[0].trim()]:w(t,"(",")")});case!!t.match(c):case!!t.match(a):s="dotObject";break;default:return r("string",t)}if("array"===s||"object"===s){let e=g(t);try{return r(s,JSON.parse(e))}catch(e){}return r(s,y(e))}if("dotObject"===s){let e,n,o;const i={};return h(t,"&&").forEach((t=>{t.match(a)?(e=w(t,"](",")"),n=w(t,"[","]"),o=t.split("[")[0].trim()):(e=w(t,"(",")"),t=t.replace(b(t,"(",")"),""),[o,n]=h(t,".")),e=y(e),i[o]||(i[o]={}),h(n,"|").forEach((t=>{i[o][t]=e}))})),r("dotObject",i)}}function b(e,t,r,n=!1){if("string"!=typeof e)return e;t=A(t),r=A(r);let o=new RegExp(x(t,r),"gm");const i=e.match(o);return i?n?i:i[0]:null}function h(e,t=","){if("string"!=typeof e)return e;if(i(e))return[];let r=(e=s(e)).split(t).map((e=>s(e)));return 1===r.length&&""===r[0]?[e]:r}function w(e,t,r,n=!1){if("string"!=typeof e)return e;const o=b(e,t,r,n)??(n?[]:e);return n?o.map((e=>s(e,t,r))):s(o,t,r)}function S(e){return"string"!=typeof e?e:e.replace(/`|'|"/g,"")}function j(e,t=null,r=null){return(!t||e.startsWith(t))&&(!r||e.endsWith(r))}function A(e){return e instanceof RegExp?e:e.split("").map((e=>["$","^",".","*","+","?","(",")","[","]","{","}","|","\\"].includes(e)?`\\${e}`:e)).join("")}function x(...e){if(e.length<2)throw new Error("You need to pass at least two arguments");let t="";return e.forEach(((e,r)=>{e instanceof RegExp&&(e=e.source),0===r?t=e:t+=`((.|\n)*?)${e}`})),t}function E(e,t=!1,n=!1){if("string"!=typeof e)return e;if(!e)return null;t=r(t),n=r(n);let o=e.replace(/([.+?^${}()|\[\]\/\\])/g,"\\$&"),i=t?"^":"",u=n?"$":"";return o=o.replace(/\*\*/g,"[_g_]").replace(/\*/g,"(.*?)").replace(/\[_g_\]/g,".*"),`${i}${o}${u}`}function O(e,t,r=!1,o=!1){if(!e||!t)return null;const i=new RegExp(E(e,r,o));if("string"==typeof t)return n(t.match(i));let u=[];return u=t.filter((e=>i.test(e))),n(u)}const k={addQuotes:a,cleanStr:s,convertKeysToSymbols:l,findAndReplaceInArray:f,findNested:p,fixQuotes:g,getArrObjFromString:y,getChunks:h,getDirectivesFromString:m,getMatchBlock:b,getMatchInBetween:w,getObjectFromPath:d,removeQuotes:S,startAndEndWith:j,setExpString:A,setLookUpExp:x,setWildCardString:E,wildCardStringSearch:O};return t})())); |
@@ -27,2 +27,3 @@ // Single Modules and Aliases from: DomObserver | ||
getMatchInBetween, | ||
getObjectFromPath, | ||
removeQuotes, | ||
@@ -109,2 +110,3 @@ setExpString, | ||
getMatchInBetween, | ||
getObjectFromPath, | ||
removeQuotes, | ||
@@ -111,0 +113,0 @@ setExpString, |
{ | ||
"name": "@knighttower/utility", | ||
"version": "4.2.19", | ||
"version": "4.2.20", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "main": "index.cjs", |
@@ -60,2 +60,3 @@ # JS Utility Library Documentation | ||
wildCardStringSearch: "searches for a string using wildcards" | ||
getObjectFromPath: "gets an object from a path", | ||
} | ||
@@ -62,0 +63,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
631805
14276
593