@knighttower/utility
Advanced tools
Comparing version 7.17.0 to 7.18.0
@@ -1,1 +0,1 @@ | ||
(()=>{"use strict";var e={d:(n,r)=>{for(var t in r){e.o(r,t)&&!e.o(n,t)&&Object.defineProperty(n,t,{enumerable:!0,get:r[t]})}},o:(e,n)=>Object.prototype.hasOwnProperty.call(e,n),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},n={};function r(e,n){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=function(e,n){if(e){if("string"==typeof e){return t(e,n)}var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?t(e,n):void 0}}(e))||n&&e&&"number"==typeof e.length){r&&(e=r);var o=0,a=function(){};return{s:a,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,u=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return u=e.done,e},e:function(e){c=!0,i=e},f:function(){try{u||null==r.return||r.return()}finally{if(c){throw i}}}}}function t(e,n){(null==n||n>e.length)&&(n=e.length);for(var r=0,t=Array(n);r<n;r++){t[r]=e[r]}return t}function o(e){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o(e)}function a(e){switch(o(e)){case"boolean":return e;case"string":return"false"!==e&&"0"!==e;case"number":return 0!==e;default:return Boolean(e)}}function i(e){var n=S(e);return null!==n?n:e}function u(e){return Number(e.replace(/[^0-9.-]+/g,""))}function c(e,n){if(!e||isNaN(new Date(e).getTime())){return null}var r=new Date(e),t=new Intl.DateTimeFormat("en-US",{year:"numeric",month:"2-digit",day:"2-digit",timeZone:"UTC"}).format(r);if(n){var o=new Intl.DateTimeFormat("en-US",{hour:"2-digit",minute:"2-digit",hour12:!0,timeZone:"UTC"}).format(r);return"".concat(t," @ ").concat(o)}return t}function l(e){return new Intl.NumberFormat("en-GB",{minimumFractionDigits:2}).format(e)}function s(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return null!==S(e)||"boolean"==typeof e?e:A(e)?n:e}function f(e,n){var r=e.replace(/\D/g,"");if(10!==r.length){throw new Error("Invalid phone number length")}for(var t=[],o=0,a=0;a<n.length;a++){"0"===n[a]?(t.push(r[o]),o++):t.push(n[a])}return t.join("")}e.r(n),e.d(n,{convertToBool:()=>a,convertToNumber:()=>i,currencyToDecimal:()=>u,dateFormat:()=>c,decimalToCurrency:()=>l,dynamicId:()=>p,emptyOrValue:()=>s,formatPhoneNumber:()=>f,getDynamicId:()=>b,getGoogleMapsAddress:()=>v,getRandomId:()=>g,includes:()=>w,instanceOf:()=>M,isEmpty:()=>A,isNumber:()=>S,makeArray:()=>d,openGoogleMapsAddress:()=>j,randomId:()=>h,toCurrency:()=>T,toDollarString:()=>k,typeOf:()=>D,uniqueId:()=>m,uuid:()=>y,validateEmail:()=>I,validatePhone:()=>N});var d=function(e){return Array.isArray(e)?e:[e]},y=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:20;e=e||40;for(var n="",r=0;r<e/3+1;r++){n+=Math.random().toString(36).substring(2,15)}return n.substring(0,e)},m=y;function b(){return"id__"+y(8)+"__"+(new Date).getTime()}var g=b,p=b,h=b;function v(e){if(!e){return!1}var n="";if(D(e,"string")){n=e}else{n=["address","address1","city","state","zip","zipcode"].reduce((function(n,r){var t=Object.keys(e).find((function(n){return n.includes(r)&&e[n]}));return t?"".concat(n," ").concat(e[t]):n}),"")}return n=n.trim().replace(/\s+|,/g,"+"),"https://maps.google.it/maps?q=".concat(n)}function w(e,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;if(Array.isArray(e)||"string"==typeof e){return e.includes(n,r)}if("object"===o(e)){for(var t in e){if(e[t]&&e[t].includes(n,r)){return!0}}}return!1}function A(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"===o(e)&&0===Object.keys(e).length)}function S(e){var n=o(e);switch(e){case null:case void 0:case"":return null;case"0":case 0:return 0;default:if(!("number"!==n&&"string"!==n||"number"!=typeof e&&Number.isNaN(Number(e)))){return+e}}return null}function M(e,n){var r="unknown",t="function"==typeof e||"object"===o(e);if(null===e||!t){return!1}for(var a=[Date,RegExp,Promise,Map,Set,WeakMap,WeakSet,ArrayBuffer,DataView],i=a.length;i--;){if(e instanceof a[i]){r=a[i].name;break}}return n?(n="string"==typeof n?n.toLowerCase():n.name.toLowerCase(),"unknown"===r&&(r=e.name),n===r.toLowerCase()):r}function j(e){if(!D(e,"string")||!D(e,"object")){throw new Error("The input must be a string or an object.")}var n=v(e);if(!A(n)||!D(n,"string")){throw new Error("The address you are trying to open is invalid.")}return window.open(n,"_blank")}function T(e){return l(e)}function k(e){return D(e,"string")&&(e=u(e)),Math.abs(e)>999&&Math.abs(e)<999999?Math.sign(e)*(Math.abs(e)/1e3).toFixed(1)+"K":Math.abs(e)>999999?Math.sign(e)*(Math.abs(e)/1e6).toFixed(1)+"M":Math.sign(e)*Math.abs(e)}function D(e,n){if(null===e){return n?null===n||"null"===n:"null"}var t;switch(o(e)){case"number":case"string":case"boolean":case"undefined":case"bigint":case"symbol":case"function":t=o(e);break;case"object":t=Array.isArray(e)?"array":"object";break;default:t="unknown"}if(n){if(n.includes("|")){var a,i=r(n.split("|"));try{for(i.s();!(a=i.n()).done;){var u=a.value;if(t===u){return u}}}catch(e){i.e(e)}finally{i.f()}return!1}return n===t}return t}function I(e){return/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/.test(e)}function N(e){return/^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/.test(e)}window.utility=n})(); | ||
(()=>{"use strict";var e={d:(n,t)=>{for(var r in t){e.o(t,r)&&!e.o(n,r)&&Object.defineProperty(n,r,{enumerable:!0,get:t[r]})}},o:(e,n)=>Object.prototype.hasOwnProperty.call(e,n),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},n={};function t(e,n){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!t){if(Array.isArray(e)||(t=function(e,n){if(e){if("string"==typeof e){return r(e,n)}var t={}.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?r(e,n):void 0}}(e))||n&&e&&"number"==typeof e.length){t&&(e=t);var o=0,a=function(){};return{s:a,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,u=!0,c=!1;return{s:function(){t=t.call(e)},n:function(){var e=t.next();return u=e.done,e},e:function(e){c=!0,i=e},f:function(){try{u||null==t.return||t.return()}finally{if(c){throw i}}}}}function r(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=Array(n);t<n;t++){r[t]=e[t]}return r}function o(e){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o(e)}function a(e){switch(o(e)){case"boolean":return e;case"string":return"false"!==e&&"0"!==e;case"number":return 0!==e;default:return Boolean(e)}}function i(e){var n=A(e);return null!==n?n:e}function u(e){return Number(e.replace(/[^0-9.-]+/g,""))}function c(e,n){if(!e||isNaN(new Date(e).getTime())){return null}var t=new Date(e),r=new Intl.DateTimeFormat("en-US",{year:"numeric",month:"2-digit",day:"2-digit",timeZone:"UTC"}).format(t);if(n){var o=new Intl.DateTimeFormat("en-US",{hour:"2-digit",minute:"2-digit",hour12:!0,timeZone:"UTC"}).format(t);return"".concat(r," @ ").concat(o)}return r}function s(e){return new Intl.NumberFormat("en-GB",{minimumFractionDigits:2}).format(e)}function l(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return null!==A(e)||"boolean"==typeof e?e:S(e)?n:e}function f(e,n){var t=e.replace(/\D/g,"");if(10!==t.length){throw new Error("Invalid phone number length")}for(var r=[],o=0,a=0;a<n.length;a++){"0"===n[a]?(r.push(t[o]),o++):r.push(n[a])}return r.join("")}e.r(n),e.d(n,{convertToBool:()=>a,convertToNumber:()=>i,currencyToDecimal:()=>u,dateFormat:()=>c,decimalToCurrency:()=>s,dynamicId:()=>p,emptyOrValue:()=>l,formatPhoneNumber:()=>f,getDynamicId:()=>b,getGoogleMapsAddress:()=>v,getRandomId:()=>g,includes:()=>w,instanceOf:()=>M,isEmpty:()=>S,isNumber:()=>A,makeArray:()=>d,openGoogleMapsAddress:()=>j,randomId:()=>h,toCurrency:()=>T,toDollarString:()=>k,typeOf:()=>D,uniqueId:()=>y,uuid:()=>m,validateEmail:()=>I,validatePhone:()=>O});var d=function(e){return Array.isArray(e)?e:[e]},m=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:20;e=e||40;for(var n="",t=0;t<e/3+1;t++){n+=Math.random().toString(36).substring(2,15)}return n.substring(0,e)},y=m;function b(){return"id__"+m(8)+"__"+(new Date).getTime()}var g=b,p=b,h=b;function v(e){if(!e){return!1}var n="";if(D(e,"string")){n=e}else{n=["address","address1","city","state","zip","zipcode"].reduce((function(n,t){var r=Object.keys(e).find((function(n){return n.includes(t)&&e[n]}));return r?"".concat(n," ").concat(e[r]):n}),"")}return n=n.trim().replace(/\s+|,/g,"+"),"https://maps.google.it/maps?q=".concat(n)}function w(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;n="string"==typeof n?n.toLowerCase():n;var r=D(e),o=function(r){var o=D(r);return"object"===o||"array"===o?w(r,n,t):"number"===o||"boolean"===o?e.toString().includes(n.toString(),t):r.includes(n,t)};switch(r){case"array":return e.some((function(e){return o(e)}));case"string":return e.toLowerCase().includes(n,t);case"number":case"boolean":return e.toString().includes(n.toString(),t);case"object":return Object.values(e).some((function(e){return o(e)}))}return e.includes(n,t)}function S(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"===o(e)&&0===Object.keys(e).length)}function A(e){var n=o(e);switch(e){case null:case void 0:case"":return null;case"0":case 0:return 0;default:if(!("number"!==n&&"string"!==n||"number"!=typeof e&&Number.isNaN(Number(e)))){return+e}}return null}function M(e,n){var t="unknown",r="function"==typeof e||"object"===o(e);if(null===e||!r){return!1}for(var a=[Date,RegExp,Promise,Map,Set,WeakMap,WeakSet,ArrayBuffer,DataView],i=a.length;i--;){if(e instanceof a[i]){t=a[i].name;break}}return n?(n="string"==typeof n?n.toLowerCase():n.name.toLowerCase(),"unknown"===t&&(t=e.name),n===t.toLowerCase()):t}function j(e){if(!D(e,"string")||!D(e,"object")){throw new Error("The input must be a string or an object.")}var n=v(e);if(!S(n)||!D(n,"string")){throw new Error("The address you are trying to open is invalid.")}return window.open(n,"_blank")}function T(e){return s(e)}function k(e){return D(e,"string")&&(e=u(e)),Math.abs(e)>999&&Math.abs(e)<999999?Math.sign(e)*(Math.abs(e)/1e3).toFixed(1)+"K":Math.abs(e)>999999?Math.sign(e)*(Math.abs(e)/1e6).toFixed(1)+"M":Math.sign(e)*Math.abs(e)}function D(e,n){if(null===e){return n?null===n||"null"===n:"null"}var r;switch(o(e)){case"number":case"string":case"boolean":case"undefined":case"bigint":case"symbol":case"function":r=o(e);break;case"object":r=Array.isArray(e)?"array":"object";break;default:r="unknown"}if(n){if(n.includes("|")){var a,i=t(n.split("|"));try{for(i.s();!(a=i.n()).done;){var u=a.value;if(r===u){return u}}}catch(e){i.e(e)}finally{i.f()}return!1}return n===r}return r}function I(e){return/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/.test(e)}function O(e){return/^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/.test(e)}window.utility=n})(); |
@@ -209,2 +209,3 @@ // // ----------------------------------------- | ||
* @example typeOf('hello') // returns 'string' | ||
* @example typeOf(123, 'number|int') // returns 'number' | ||
* @example typeOf({}) // returns 'object' | ||
@@ -211,0 +212,0 @@ */ |
@@ -239,2 +239,3 @@ class EventBus { | ||
* @example typeOf('hello') // returns 'string' | ||
* @example typeOf(123, 'number|int') // returns 'number' | ||
* @example typeOf({}) // returns 'object' | ||
@@ -241,0 +242,0 @@ */ |
@@ -271,3 +271,3 @@ // // ----------------------------------------- | ||
/** | ||
* Check if a value is in a collection (array, string, object) | ||
* Check recusively if a value is in a collection (array, string, object) | ||
* @param {collection} collection - The collection to search in | ||
@@ -277,19 +277,34 @@ * @param {value} value - The value to search for | ||
* @return {boolean} - True if the value is in the collection, false otherwise | ||
* @example includes('hello there', 'hello') // true | ||
* @example includes({ hello: 'dos', other: { hello: 'uno' } }, 'uno') // true | ||
* @note This function is case-insensitive and since native includes is not recursive, this function is | ||
*/ | ||
function includes(collection, value, fromIndex = 0) { | ||
if (Array.isArray(collection) || typeof collection === 'string') { | ||
// Use native includes for arrays and strings | ||
return collection.includes(value, fromIndex); | ||
} | ||
if (typeof collection === 'object') { | ||
// Search in object values | ||
for (let key in collection) { | ||
if (collection[key] && collection[key].includes(value, fromIndex)) { | ||
return true; | ||
} | ||
const isString = typeof value === 'string'; | ||
value = isString ? value.toLowerCase() : value; | ||
const collectionType = typeOf(collection); | ||
const find = (target) => { | ||
const isType = typeOf(target); | ||
if (isType === 'object' || isType === 'array') { | ||
return includes(target, value, fromIndex); | ||
} | ||
if (isType === 'number' || isType === 'boolean') { | ||
return collection.toString().includes(value.toString(), fromIndex); | ||
} | ||
// any other case | ||
return target.includes(value, fromIndex); | ||
}; | ||
switch (collectionType) { | ||
case 'array': | ||
return collection.some((item) => find(item)); | ||
case 'string': | ||
return collection.toLowerCase().includes(value, fromIndex); | ||
case 'number': | ||
case 'boolean': | ||
return collection.toString().includes(value.toString(), fromIndex); | ||
case 'object': | ||
return Object.values(collection).some((item) => find(item)); | ||
} | ||
return false; | ||
// any other case | ||
return collection.includes(value, fromIndex); | ||
} | ||
@@ -485,2 +500,3 @@ | ||
* @example typeOf('hello') // returns 'string' | ||
* @example typeOf(123, 'number|int') // returns 'number' | ||
* @example typeOf({}) // returns 'object' | ||
@@ -487,0 +503,0 @@ */ |
@@ -1,1 +0,1 @@ | ||
var e,t;e=this,t=()=>(()=>{"use strict";var e={d:(t,n)=>{for(var r in n){e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})}},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 n(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e){return r(e,t)}var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var o=0,a=function(){};return{s:a,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,u=!0,c=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return u=e.done,e},e:function(e){c=!0,i=e},f:function(){try{u||null==n.return||n.return()}finally{if(c){throw i}}}}}function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++){r[n]=e[n]}return r}function o(e){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o(e)}function a(e){switch(o(e)){case"boolean":return e;case"string":return"false"!==e&&"0"!==e;case"number":return 0!==e;default:return Boolean(e)}}function i(e){var t=S(e);return null!==t?t:e}function u(e){return Number(e.replace(/[^0-9.-]+/g,""))}function c(e,t){if(!e||isNaN(new Date(e).getTime())){return null}var n=new Date(e),r=new Intl.DateTimeFormat("en-US",{year:"numeric",month:"2-digit",day:"2-digit",timeZone:"UTC"}).format(n);if(t){var o=new Intl.DateTimeFormat("en-US",{hour:"2-digit",minute:"2-digit",hour12:!0,timeZone:"UTC"}).format(n);return"".concat(r," @ ").concat(o)}return r}function f(e){return new Intl.NumberFormat("en-GB",{minimumFractionDigits:2}).format(e)}function s(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return null!==S(e)||"boolean"==typeof e?e:A(e)?t:e}function l(e,t){var n=e.replace(/\D/g,"");if(10!==n.length){throw new Error("Invalid phone number length")}for(var r=[],o=0,a=0;a<t.length;a++){"0"===t[a]?(r.push(n[o]),o++):r.push(t[a])}return r.join("")}e.r(t),e.d(t,{convertToBool:()=>a,convertToNumber:()=>i,currencyToDecimal:()=>u,dateFormat:()=>c,decimalToCurrency:()=>f,dynamicId:()=>p,emptyOrValue:()=>s,formatPhoneNumber:()=>l,getDynamicId:()=>b,getGoogleMapsAddress:()=>v,getRandomId:()=>g,includes:()=>w,instanceOf:()=>j,isEmpty:()=>A,isNumber:()=>S,makeArray:()=>d,openGoogleMapsAddress:()=>M,randomId:()=>h,toCurrency:()=>T,toDollarString:()=>k,typeOf:()=>D,uniqueId:()=>m,uuid:()=>y,validateEmail:()=>I,validatePhone:()=>N});var d=function(e){return Array.isArray(e)?e:[e]},y=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:20;e=e||40;for(var t="",n=0;n<e/3+1;n++){t+=Math.random().toString(36).substring(2,15)}return t.substring(0,e)},m=y;function b(){return"id__"+y(8)+"__"+(new Date).getTime()}var g=b,p=b,h=b;function v(e){if(!e){return!1}var t="";return t=(t=D(e,"string")?e:["address","address1","city","state","zip","zipcode"].reduce((function(t,n){var r=Object.keys(e).find((function(t){return t.includes(n)&&e[t]}));return r?"".concat(t," ").concat(e[r]):t}),"")).trim().replace(/\s+|,/g,"+"),"https://maps.google.it/maps?q=".concat(t)}function w(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;if(Array.isArray(e)||"string"==typeof e){return e.includes(t,n)}if("object"===o(e)){for(var r in e){if(e[r]&&e[r].includes(t,n)){return!0}}}return!1}function A(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"===o(e)&&0===Object.keys(e).length)}function S(e){var t=o(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 j(e,t){var n="unknown",r="function"==typeof e||"object"===o(e);if(null===e||!r){return!1}for(var a=[Date,RegExp,Promise,Map,Set,WeakMap,WeakSet,ArrayBuffer,DataView],i=a.length;i--;){if(e instanceof a[i]){n=a[i].name;break}}return t?(t="string"==typeof t?t.toLowerCase():t.name.toLowerCase(),"unknown"===n&&(n=e.name),t===n.toLowerCase()):n}function M(e){if(!D(e,"string")||!D(e,"object")){throw new Error("The input must be a string or an object.")}var t=v(e);if(!A(t)||!D(t,"string")){throw new Error("The address you are trying to open is invalid.")}return window.open(t,"_blank")}function T(e){return f(e)}function k(e){return D(e,"string")&&(e=u(e)),Math.abs(e)>999&&Math.abs(e)<999999?Math.sign(e)*(Math.abs(e)/1e3).toFixed(1)+"K":Math.abs(e)>999999?Math.sign(e)*(Math.abs(e)/1e6).toFixed(1)+"M":Math.sign(e)*Math.abs(e)}function D(e,t){if(null===e){return t?null===t||"null"===t:"null"}var r;switch(o(e)){case"number":case"string":case"boolean":case"undefined":case"bigint":case"symbol":case"function":r=o(e);break;case"object":r=Array.isArray(e)?"array":"object";break;default:r="unknown"}if(t){if(t.includes("|")){var a,i=n(t.split("|"));try{for(i.s();!(a=i.n()).done;){var u=a.value;if(r===u){return u}}}catch(e){i.e(e)}finally{i.f()}return!1}return t===r}return r}function I(e){return/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/.test(e)}function N(e){return/^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/.test(e)}return t})(),"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("utility",[],t):"object"==typeof exports?exports.utility=t():e.utility=t(); | ||
var e,t;e=this,t=()=>(()=>{"use strict";var e={d:(t,n)=>{for(var r in n){e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})}},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 n(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e){return r(e,t)}var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var o=0,a=function(){};return{s:a,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,u=!0,c=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return u=e.done,e},e:function(e){c=!0,i=e},f:function(){try{u||null==n.return||n.return()}finally{if(c){throw i}}}}}function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++){r[n]=e[n]}return r}function o(e){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o(e)}function a(e){switch(o(e)){case"boolean":return e;case"string":return"false"!==e&&"0"!==e;case"number":return 0!==e;default:return Boolean(e)}}function i(e){var t=j(e);return null!==t?t:e}function u(e){return Number(e.replace(/[^0-9.-]+/g,""))}function c(e,t){if(!e||isNaN(new Date(e).getTime())){return null}var n=new Date(e),r=new Intl.DateTimeFormat("en-US",{year:"numeric",month:"2-digit",day:"2-digit",timeZone:"UTC"}).format(n);if(t){var o=new Intl.DateTimeFormat("en-US",{hour:"2-digit",minute:"2-digit",hour12:!0,timeZone:"UTC"}).format(n);return"".concat(r," @ ").concat(o)}return r}function s(e){return new Intl.NumberFormat("en-GB",{minimumFractionDigits:2}).format(e)}function l(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return null!==j(e)||"boolean"==typeof e?e:S(e)?t:e}function f(e,t){var n=e.replace(/\D/g,"");if(10!==n.length){throw new Error("Invalid phone number length")}for(var r=[],o=0,a=0;a<t.length;a++){"0"===t[a]?(r.push(n[o]),o++):r.push(t[a])}return r.join("")}e.r(t),e.d(t,{convertToBool:()=>a,convertToNumber:()=>i,currencyToDecimal:()=>u,dateFormat:()=>c,decimalToCurrency:()=>s,dynamicId:()=>p,emptyOrValue:()=>l,formatPhoneNumber:()=>f,getDynamicId:()=>b,getGoogleMapsAddress:()=>v,getRandomId:()=>g,includes:()=>w,instanceOf:()=>A,isEmpty:()=>S,isNumber:()=>j,makeArray:()=>d,openGoogleMapsAddress:()=>M,randomId:()=>h,toCurrency:()=>T,toDollarString:()=>k,typeOf:()=>D,uniqueId:()=>y,uuid:()=>m,validateEmail:()=>I,validatePhone:()=>O});var d=function(e){return Array.isArray(e)?e:[e]},m=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:20;e=e||40;for(var t="",n=0;n<e/3+1;n++){t+=Math.random().toString(36).substring(2,15)}return t.substring(0,e)},y=m;function b(){return"id__"+m(8)+"__"+(new Date).getTime()}var g=b,p=b,h=b;function v(e){if(!e){return!1}var t="";return t=(t=D(e,"string")?e:["address","address1","city","state","zip","zipcode"].reduce((function(t,n){var r=Object.keys(e).find((function(t){return t.includes(n)&&e[t]}));return r?"".concat(t," ").concat(e[r]):t}),"")).trim().replace(/\s+|,/g,"+"),"https://maps.google.it/maps?q=".concat(t)}function w(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;t="string"==typeof t?t.toLowerCase():t;var r=D(e),o=function(r){var o=D(r);return"object"===o||"array"===o?w(r,t,n):"number"===o||"boolean"===o?e.toString().includes(t.toString(),n):r.includes(t,n)};switch(r){case"array":return e.some((function(e){return o(e)}));case"string":return e.toLowerCase().includes(t,n);case"number":case"boolean":return e.toString().includes(t.toString(),n);case"object":return Object.values(e).some((function(e){return o(e)}))}return e.includes(t,n)}function S(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"===o(e)&&0===Object.keys(e).length)}function j(e){var t=o(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 A(e,t){var n="unknown",r="function"==typeof e||"object"===o(e);if(null===e||!r){return!1}for(var a=[Date,RegExp,Promise,Map,Set,WeakMap,WeakSet,ArrayBuffer,DataView],i=a.length;i--;){if(e instanceof a[i]){n=a[i].name;break}}return t?(t="string"==typeof t?t.toLowerCase():t.name.toLowerCase(),"unknown"===n&&(n=e.name),t===n.toLowerCase()):n}function M(e){if(!D(e,"string")||!D(e,"object")){throw new Error("The input must be a string or an object.")}var t=v(e);if(!S(t)||!D(t,"string")){throw new Error("The address you are trying to open is invalid.")}return window.open(t,"_blank")}function T(e){return s(e)}function k(e){return D(e,"string")&&(e=u(e)),Math.abs(e)>999&&Math.abs(e)<999999?Math.sign(e)*(Math.abs(e)/1e3).toFixed(1)+"K":Math.abs(e)>999999?Math.sign(e)*(Math.abs(e)/1e6).toFixed(1)+"M":Math.sign(e)*Math.abs(e)}function D(e,t){if(null===e){return t?null===t||"null"===t:"null"}var r;switch(o(e)){case"number":case"string":case"boolean":case"undefined":case"bigint":case"symbol":case"function":r=o(e);break;case"object":r=Array.isArray(e)?"array":"object";break;default:r="unknown"}if(t){if(t.includes("|")){var a,i=n(t.split("|"));try{for(i.s();!(a=i.n()).done;){var u=a.value;if(r===u){return u}}}catch(e){i.e(e)}finally{i.f()}return!1}return t===r}return r}function I(e){return/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/.test(e)}function O(e){return/^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/.test(e)}return t})(),"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("utility",[],t):"object"==typeof exports?exports.utility=t():e.utility=t(); |
{ | ||
"name": "@knighttower/utility", | ||
"version": "7.17.0", | ||
"version": "7.18.0", | ||
"main": "index.cjs", | ||
@@ -5,0 +5,0 @@ "module": "index.js", |
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
379886
6997