@andrewcaires/utils.js 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2015-2021 Andrew Caires (https://github.com/andrewcaires)
3
+ Copyright (c) 2015-2022 Andrew Caires (https://github.com/andrewcaires)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/dist/utilsjs.d.ts CHANGED
@@ -27,9 +27,11 @@ declare const mask: (mask: string, text: string) => string;
27
27
  declare const maskMoney: (mask: string, text: string, decimal?: number) => string;
28
28
  declare const maskReverse: (mask: string, text: string) => string;
29
29
 
30
- declare const filterObject: (allowed: string[], raw: {
30
+ declare type objectRaw = {
31
31
  [key: string]: any;
32
- }) => any;
32
+ };
33
+ declare const allowedObject: (allowed: string[], raw: objectRaw) => objectRaw;
34
+ declare const deniedObject: (denied: string[], raw: objectRaw) => objectRaw;
33
35
 
34
36
  declare type forEachCallback<T> = (value: T, index: number, arr: Array<T>) => Promise<void>;
35
37
  declare const forEachAsync: <T>(arr: T[], callback: forEachCallback<T>, thisArg?: any) => Promise<void>;
@@ -52,4 +54,4 @@ declare const isNull: (test: any) => boolean;
52
54
  declare const isUndefined: (test: any) => boolean;
53
55
  declare const type: (test: any) => string;
54
56
 
55
- export { EventCallback, EventDisposable, EventEmitter, EventList, camelCase, chunkArray, dateFormat, filterObject, forEachAsync, forEachSeries, forLoop, isArray, isBoolean, isDef, isFloat, isFunction, isInteger, isNull, isNumber, isObject, isString, isUndefined, mask, maskMoney, maskReverse, noop, shadeColor, sleep, stringReverse, toArray, type };
57
+ export { EventCallback, EventDisposable, EventEmitter, EventList, allowedObject, camelCase, chunkArray, dateFormat, deniedObject, forEachAsync, forEachSeries, forLoop, isArray, isBoolean, isDef, isFloat, isFunction, isInteger, isNull, isNumber, isObject, isString, isUndefined, mask, maskMoney, maskReverse, noop, shadeColor, sleep, stringReverse, toArray, type };
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * @andrewcaires/utils.js v0.0.6
3
- * (c) 2021 Andrew Caires
2
+ * @andrewcaires/utils.js v0.0.7
3
+ * (c) 2022 Andrew Caires
4
4
  * @license: MIT
5
5
  */
6
- var n={},t=function(n){return"array"==p(n)},e=function(n){return"boolean"==p(n)},r=function(n){return"null"!=p(n)},u=function(n){return"function"==p(n)},o=function(n){return"number"==p(n)},c=function(n){return"object"==p(n)},i=function(n){return"string"==p(n)},a=function(n){return o(n)&&!!(n%1)},s=function(n){return o(n)&&!(n%1)},f=function(n){return null===n},l=function(n){return void 0===n},p=function(t){return null==t?"null":n[n.toString.call(t)]||"object"};["Array","Boolean","Function","Number","Object","String"].forEach((function(t){return n["[object "+t+"]"]=t.toLowerCase()}));var h=function(n,t){void 0===t&&(t=1);for(var e=[],r=0;r<n.length;r+=t)e.push(n.slice(r,r+t));return e},v=function(n){return t(n)?n:r(n)?[n]:[]},b=function(n,t){return(e=parseInt(n,16)+t,Math.min(255,Math.max(0,e))).toString(16);var e},g=function(n,t){return"#"+n.replace(/^#/,"").replace(/../g,(function(n){return("0"+b(n,t)).substr(-2)}))},d=function(n,t){return t.replace(/%[yYmdHMS]/g,(function(t){var e;switch(t){case"%y":e=n.getFullYear();break;case"%Y":return n.getFullYear().toString();case"%m":e=n.getMonth()+1;break;case"%d":e=n.getDate();break;case"%H":e=n.getHours();break;case"%M":e=n.getMinutes();break;case"%S":e=n.getSeconds();break;default:return t.slice(1)}return("0"+e.toString()).slice(-2)}))},y=function(){function n(){this.events=new Map}return n.prototype.on=function(n,t){var e=this,r=this.events.get(n);return r?r.push(t):this.events.set(n,[t]),{dispose:function(){return e.off(n,t)}}},n.prototype.once=function(n,t){var e=this,r=function(u){t(u),e.off(n,r)};return this.on(n,r),{dispose:function(){return e.off(n,r)}}},n.prototype.off=function(n,t){var e=this.events.get(n);if(t){if(e){var r=e.indexOf(t);r>=0&&e.splice(r,1)}}else this.events.set(n,[])},n.prototype.emit=function(n,t){var e=this.events.get(n);e&&e.forEach((function(n){return n(t)}))},n}(),m=function(n,t,e){for(var r=1;r<=n;r++)t.call(e||null,r,n);return n},w=function(){},k=function(n){return n.toLowerCase().replace(/\W+/g," ").trim().replace(/ (.)/g,(function(n){return n.toUpperCase()})).replace(/ /g,"")},x=function(n){return n.split("").reverse().join("")},S=function(n){return/^[A-Za-z]$/.test(n)},j=function(n,t,e){e.mask++,e.text++;var r=n[e.mask],u=t[e.text];return l(r)||l(u)?"":function(n,t,e){switch(n.toUpperCase()){case"#":return t;case"0":case"9":return function(n){return/^[0-9]$/.test(n)}(t)?t:(e.mask--,"");case"A":case"Z":return S(t)?t:(e.mask--,"");case"L":return S(t)?t.toLowerCase():(e.mask--,"");case"U":return S(t)?t.toUpperCase():(e.mask--,"");case"S":return function(n){return/^[^A-Za-z0-9]$/.test(n)}(t)?t:(e.mask--,"");default:return n!=t&&e.text--,n}}(r,u,e)+j(n,t,e)},M=function(n,t){return j(n,t,{mask:-1,text:-1})},C=function(n,t,e){return void 0===e&&(e=2),e++,t=parseInt((t||"0").replace(/\W/g,"")).toString(),A(n,t.length<e?("0".repeat(e)+t).slice(-1*e):t)},O=M,A=function(n,t){return x(O(x(n),x(t)))},L=function(){return L=Object.assign||function(n){for(var t,e=1,r=arguments.length;e<r;e++)for(var u in t=arguments[e])Object.prototype.hasOwnProperty.call(t,u)&&(n[u]=t[u]);return n},L.apply(this,arguments)};function P(n,t,e,r){return new(e||(e=Promise))((function(u,o){function c(n){try{a(r.next(n))}catch(n){o(n)}}function i(n){try{a(r.throw(n))}catch(n){o(n)}}function a(n){var t;n.done?u(n.value):(t=n.value,t instanceof e?t:new e((function(n){n(t)}))).then(c,i)}a((r=r.apply(n,t||[])).next())}))}function U(n,t){var e,r,u,o,c={label:0,sent:function(){if(1&u[0])throw u[1];return u[1]},trys:[],ops:[]};return o={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function i(o){return function(i){return function(o){if(e)throw new TypeError("Generator is already executing.");for(;c;)try{if(e=1,r&&(u=2&o[0]?r.return:o[0]?r.throw||((u=r.return)&&u.call(r),0):r.next)&&!(u=u.call(r,o[1])).done)return u;switch(r=0,u&&(o=[2&o[0],u.value]),o[0]){case 0:case 1:u=o;break;case 4:return c.label++,{value:o[1],done:!1};case 5:c.label++,r=o[1],o=[0];continue;case 7:o=c.ops.pop(),c.trys.pop();continue;default:if(!(u=c.trys,(u=u.length>0&&u[u.length-1])||6!==o[0]&&2!==o[0])){c=0;continue}if(3===o[0]&&(!u||o[1]>u[0]&&o[1]<u[3])){c.label=o[1];break}if(6===o[0]&&c.label<u[1]){c.label=u[1],u=o;break}if(u&&c.label<u[2]){c.label=u[2],c.ops.push(o);break}u[2]&&c.ops.pop(),c.trys.pop();continue}o=t.call(n,c)}catch(n){o=[6,n],r=0}finally{e=u=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,i])}}}var Y=function(n,t){return n.reduce((function(n,e){var r;return L(L({},n),((r={})[e]=t[e],r))}),{})},E=function(n,t,e){return P(void 0,void 0,void 0,(function(){return U(this,(function(r){switch(r.label){case 0:return[4,Promise.all(n.map((function(r,u){return t.call(e||null,r,u,n)})))];case 1:return r.sent(),[2]}}))}))},F=function(n,t,e){return P(void 0,void 0,void 0,(function(){var r;return U(this,(function(u){switch(u.label){case 0:r=0,u.label=1;case 1:return r<n.length?[4,t.call(e||null,n[r],r,n)]:[3,4];case 2:u.sent(),u.label=3;case 3:return r++,[3,1];case 4:return[2]}}))}))},H=function(n){return new Promise((function(t){return setTimeout(t,n)}))};export{y as EventEmitter,k as camelCase,h as chunkArray,d as dateFormat,Y as filterObject,E as forEachAsync,F as forEachSeries,m as forLoop,t as isArray,e as isBoolean,r as isDef,a as isFloat,u as isFunction,s as isInteger,f as isNull,o as isNumber,c as isObject,i as isString,l as isUndefined,M as mask,C as maskMoney,A as maskReverse,w as noop,g as shadeColor,H as sleep,x as stringReverse,v as toArray,p as type};
6
+ var n={},t=function(n){return"array"==p(n)},e=function(n){return"boolean"==p(n)},r=function(n){return"null"!=p(n)},u=function(n){return"function"==p(n)},o=function(n){return"number"==p(n)},c=function(n){return"object"==p(n)},i=function(n){return"string"==p(n)},a=function(n){return o(n)&&!!(n%1)},s=function(n){return o(n)&&!(n%1)},f=function(n){return null===n},l=function(n){return void 0===n},p=function(t){return null==t?"null":n[n.toString.call(t)]||"object"};["Array","Boolean","Function","Number","Object","String"].forEach((function(t){return n["[object "+t+"]"]=t.toLowerCase()}));var h=function(n,t){void 0===t&&(t=1);for(var e=[],r=0;r<n.length;r+=t)e.push(n.slice(r,r+t));return e},v=function(n){return t(n)?n:r(n)?[n]:[]},b=function(n,t){return(e=parseInt(n,16)+t,Math.min(255,Math.max(0,e))).toString(16);var e},g=function(n,t){return"#"+n.replace(/^#/,"").replace(/../g,(function(n){return("0"+b(n,t)).substr(-2)}))},d=function(n,t){return t.replace(/%[yYmdHMS]/g,(function(t){var e;switch(t){case"%y":e=n.getFullYear();break;case"%Y":return n.getFullYear().toString();case"%m":e=n.getMonth()+1;break;case"%d":e=n.getDate();break;case"%H":e=n.getHours();break;case"%M":e=n.getMinutes();break;case"%S":e=n.getSeconds();break;default:return t.slice(1)}return("0"+e.toString()).slice(-2)}))},y=function(){function n(){this.events=new Map}return n.prototype.on=function(n,t){var e=this,r=this.events.get(n);return r?r.push(t):this.events.set(n,[t]),{dispose:function(){return e.off(n,t)}}},n.prototype.once=function(n,t){var e=this,r=function(u){t(u),e.off(n,r)};return this.on(n,r),{dispose:function(){return e.off(n,r)}}},n.prototype.off=function(n,t){var e=this.events.get(n);if(t){if(e){var r=e.indexOf(t);r>=0&&e.splice(r,1)}}else this.events.set(n,[])},n.prototype.emit=function(n,t){var e=this.events.get(n);e&&e.forEach((function(n){return n(t)}))},n}(),m=function(n,t,e){for(var r=1;r<=n;r++)t.call(e||null,r,n);return n},w=function(){},k=function(n){return n.toLowerCase().replace(/\W+/g," ").trim().replace(/ (.)/g,(function(n){return n.toUpperCase()})).replace(/ /g,"")},x=function(n){return n.split("").reverse().join("")},S=function(n){return/^[A-Za-z]$/.test(n)},j=function(n,t,e){e.mask++,e.text++;var r=n[e.mask],u=t[e.text];return l(r)||l(u)?"":function(n,t,e){switch(n.toUpperCase()){case"#":return t;case"0":case"9":return function(n){return/^[0-9]$/.test(n)}(t)?t:(e.mask--,"");case"A":case"Z":return S(t)?t:(e.mask--,"");case"L":return S(t)?t.toLowerCase():(e.mask--,"");case"U":return S(t)?t.toUpperCase():(e.mask--,"");case"S":return function(n){return/^[^A-Za-z0-9]$/.test(n)}(t)?t:(e.mask--,"");default:return n!=t&&e.text--,n}}(r,u,e)+j(n,t,e)},M=function(n,t){return j(n,t,{mask:-1,text:-1})},O=function(n,t,e){return void 0===e&&(e=2),e++,t=parseInt((t||"0").replace(/\W/g,"")).toString(),A(n,t.length<e?("0".repeat(e)+t).slice(-1*e):t)},C=M,A=function(n,t){return x(C(x(n),x(t)))},L=function(){return L=Object.assign||function(n){for(var t,e=1,r=arguments.length;e<r;e++)for(var u in t=arguments[e])Object.prototype.hasOwnProperty.call(t,u)&&(n[u]=t[u]);return n},L.apply(this,arguments)};function P(n,t,e,r){return new(e||(e=Promise))((function(u,o){function c(n){try{a(r.next(n))}catch(n){o(n)}}function i(n){try{a(r.throw(n))}catch(n){o(n)}}function a(n){var t;n.done?u(n.value):(t=n.value,t instanceof e?t:new e((function(n){n(t)}))).then(c,i)}a((r=r.apply(n,t||[])).next())}))}function U(n,t){var e,r,u,o,c={label:0,sent:function(){if(1&u[0])throw u[1];return u[1]},trys:[],ops:[]};return o={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function i(o){return function(i){return function(o){if(e)throw new TypeError("Generator is already executing.");for(;c;)try{if(e=1,r&&(u=2&o[0]?r.return:o[0]?r.throw||((u=r.return)&&u.call(r),0):r.next)&&!(u=u.call(r,o[1])).done)return u;switch(r=0,u&&(o=[2&o[0],u.value]),o[0]){case 0:case 1:u=o;break;case 4:return c.label++,{value:o[1],done:!1};case 5:c.label++,r=o[1],o=[0];continue;case 7:o=c.ops.pop(),c.trys.pop();continue;default:if(!(u=c.trys,(u=u.length>0&&u[u.length-1])||6!==o[0]&&2!==o[0])){c=0;continue}if(3===o[0]&&(!u||o[1]>u[0]&&o[1]<u[3])){c.label=o[1];break}if(6===o[0]&&c.label<u[1]){c.label=u[1],u=o;break}if(u&&c.label<u[2]){c.label=u[2],c.ops.push(o);break}u[2]&&c.ops.pop(),c.trys.pop();continue}o=t.call(n,c)}catch(n){o=[6,n],r=0}finally{e=u=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,i])}}}var Y=function(n,t){return n.reduce((function(n,e){var r;return L(L({},n),((r={})[e]=t[e],r))}),{})},E=function(n,t){return Y(Object.keys(t).filter((function(t){return-1==n.indexOf(t)})),t)},F=function(n,t,e){return P(void 0,void 0,void 0,(function(){return U(this,(function(r){switch(r.label){case 0:return[4,Promise.all(n.map((function(r,u){return t.call(e||null,r,u,n)})))];case 1:return r.sent(),[2]}}))}))},H=function(n,t,e){return P(void 0,void 0,void 0,(function(){var r;return U(this,(function(u){switch(u.label){case 0:r=0,u.label=1;case 1:return r<n.length?[4,t.call(e||null,n[r],r,n)]:[3,4];case 2:u.sent(),u.label=3;case 3:return r++,[3,1];case 4:return[2]}}))}))},Z=function(n){return new Promise((function(t){return setTimeout(t,n)}))};export{y as EventEmitter,Y as allowedObject,k as camelCase,h as chunkArray,d as dateFormat,E as deniedObject,F as forEachAsync,H as forEachSeries,m as forLoop,t as isArray,e as isBoolean,r as isDef,a as isFloat,u as isFunction,s as isInteger,f as isNull,o as isNumber,c as isObject,i as isString,l as isUndefined,M as mask,O as maskMoney,A as maskReverse,w as noop,g as shadeColor,Z as sleep,x as stringReverse,v as toArray,p as type};
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * @andrewcaires/utils.js v0.0.6
3
- * (c) 2021 Andrew Caires
2
+ * @andrewcaires/utils.js v0.0.7
3
+ * (c) 2022 Andrew Caires
4
4
  * @license: MIT
5
5
  */
6
- var UtilsJS=function(t){"use strict";var e={},n=function(t){return"array"==i(t)},r=function(t){return"null"!=i(t)},u=function(t){return"number"==i(t)},o=function(t){return void 0===t},i=function(t){return null==t?"null":e[e.toString.call(t)]||"object"};["Array","Boolean","Function","Number","Object","String"].forEach((function(t){return e["[object "+t+"]"]=t.toLowerCase()}));var c=function(t,e){return(n=parseInt(t,16)+e,Math.min(255,Math.max(0,n))).toString(16);var n},a=function(){function t(){this.events=new Map}return t.prototype.on=function(t,e){var n=this,r=this.events.get(t);return r?r.push(e):this.events.set(t,[e]),{dispose:function(){return n.off(t,e)}}},t.prototype.once=function(t,e){var n=this,r=function(u){e(u),n.off(t,r)};return this.on(t,r),{dispose:function(){return n.off(t,r)}}},t.prototype.off=function(t,e){var n=this.events.get(t);if(e){if(n){var r=n.indexOf(e);r>=0&&n.splice(r,1)}}else this.events.set(t,[])},t.prototype.emit=function(t,e){var n=this.events.get(t);n&&n.forEach((function(t){return t(e)}))},t}(),s=function(t){return t.split("").reverse().join("")},f=function(t){return/^[A-Za-z]$/.test(t)},l=function(t,e,n){n.mask++,n.text++;var r=t[n.mask],u=e[n.text];return o(r)||o(u)?"":function(t,e,n){switch(t.toUpperCase()){case"#":return e;case"0":case"9":return function(t){return/^[0-9]$/.test(t)}(e)?e:(n.mask--,"");case"A":case"Z":return f(e)?e:(n.mask--,"");case"L":return f(e)?e.toLowerCase():(n.mask--,"");case"U":return f(e)?e.toUpperCase():(n.mask--,"");case"S":return function(t){return/^[^A-Za-z0-9]$/.test(t)}(e)?e:(n.mask--,"");default:return t!=e&&n.text--,t}}(r,u,n)+l(t,e,n)},p=function(t,e){return l(t,e,{mask:-1,text:-1})},h=p,v=function(t,e){return s(h(s(t),s(e)))},b=function(){return b=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var u in e=arguments[n])Object.prototype.hasOwnProperty.call(e,u)&&(t[u]=e[u]);return t},b.apply(this,arguments)};function g(t,e,n,r){return new(n||(n=Promise))((function(u,o){function i(t){try{a(r.next(t))}catch(t){o(t)}}function c(t){try{a(r.throw(t))}catch(t){o(t)}}function a(t){var e;t.done?u(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(i,c)}a((r=r.apply(t,e||[])).next())}))}function y(t,e){var n,r,u,o,i={label:0,sent:function(){if(1&u[0])throw u[1];return u[1]},trys:[],ops:[]};return o={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function c(o){return function(c){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(u=2&o[0]?r.return:o[0]?r.throw||((u=r.return)&&u.call(r),0):r.next)&&!(u=u.call(r,o[1])).done)return u;switch(r=0,u&&(o=[2&o[0],u.value]),o[0]){case 0:case 1:u=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,r=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!(u=i.trys,(u=u.length>0&&u[u.length-1])||6!==o[0]&&2!==o[0])){i=0;continue}if(3===o[0]&&(!u||o[1]>u[0]&&o[1]<u[3])){i.label=o[1];break}if(6===o[0]&&i.label<u[1]){i.label=u[1],u=o;break}if(u&&i.label<u[2]){i.label=u[2],i.ops.push(o);break}u[2]&&i.ops.pop(),i.trys.pop();continue}o=e.call(t,i)}catch(t){o=[6,t],r=0}finally{n=u=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,c])}}}return t.EventEmitter=a,t.camelCase=function(t){return t.toLowerCase().replace(/\W+/g," ").trim().replace(/ (.)/g,(function(t){return t.toUpperCase()})).replace(/ /g,"")},t.chunkArray=function(t,e){void 0===e&&(e=1);for(var n=[],r=0;r<t.length;r+=e)n.push(t.slice(r,r+e));return n},t.dateFormat=function(t,e){return e.replace(/%[yYmdHMS]/g,(function(e){var n;switch(e){case"%y":n=t.getFullYear();break;case"%Y":return t.getFullYear().toString();case"%m":n=t.getMonth()+1;break;case"%d":n=t.getDate();break;case"%H":n=t.getHours();break;case"%M":n=t.getMinutes();break;case"%S":n=t.getSeconds();break;default:return e.slice(1)}return("0"+n.toString()).slice(-2)}))},t.filterObject=function(t,e){return t.reduce((function(t,n){var r;return b(b({},t),((r={})[n]=e[n],r))}),{})},t.forEachAsync=function(t,e,n){return g(void 0,void 0,void 0,(function(){return y(this,(function(r){switch(r.label){case 0:return[4,Promise.all(t.map((function(r,u){return e.call(n||null,r,u,t)})))];case 1:return r.sent(),[2]}}))}))},t.forEachSeries=function(t,e,n){return g(void 0,void 0,void 0,(function(){var r;return y(this,(function(u){switch(u.label){case 0:r=0,u.label=1;case 1:return r<t.length?[4,e.call(n||null,t[r],r,t)]:[3,4];case 2:u.sent(),u.label=3;case 3:return r++,[3,1];case 4:return[2]}}))}))},t.forLoop=function(t,e,n){for(var r=1;r<=t;r++)e.call(n||null,r,t);return t},t.isArray=n,t.isBoolean=function(t){return"boolean"==i(t)},t.isDef=r,t.isFloat=function(t){return u(t)&&!!(t%1)},t.isFunction=function(t){return"function"==i(t)},t.isInteger=function(t){return u(t)&&!(t%1)},t.isNull=function(t){return null===t},t.isNumber=u,t.isObject=function(t){return"object"==i(t)},t.isString=function(t){return"string"==i(t)},t.isUndefined=o,t.mask=p,t.maskMoney=function(t,e,n){return void 0===n&&(n=2),n++,e=parseInt((e||"0").replace(/\W/g,"")).toString(),v(t,e.length<n?("0".repeat(n)+e).slice(-1*n):e)},t.maskReverse=v,t.noop=function(){},t.shadeColor=function(t,e){return"#"+t.replace(/^#/,"").replace(/../g,(function(t){return("0"+c(t,e)).substr(-2)}))},t.sleep=function(t){return new Promise((function(e){return setTimeout(e,t)}))},t.stringReverse=s,t.toArray=function(t){return n(t)?t:r(t)?[t]:[]},t.type=i,Object.defineProperty(t,"__esModule",{value:!0}),t}({});
6
+ var UtilsJS=function(e){"use strict";var t={},n=function(e){return"array"==i(e)},r=function(e){return"null"!=i(e)},u=function(e){return"number"==i(e)},o=function(e){return void 0===e},i=function(e){return null==e?"null":t[t.toString.call(e)]||"object"};["Array","Boolean","Function","Number","Object","String"].forEach((function(e){return t["[object "+e+"]"]=e.toLowerCase()}));var c=function(e,t){return(n=parseInt(e,16)+t,Math.min(255,Math.max(0,n))).toString(16);var n},a=function(){function e(){this.events=new Map}return e.prototype.on=function(e,t){var n=this,r=this.events.get(e);return r?r.push(t):this.events.set(e,[t]),{dispose:function(){return n.off(e,t)}}},e.prototype.once=function(e,t){var n=this,r=function(u){t(u),n.off(e,r)};return this.on(e,r),{dispose:function(){return n.off(e,r)}}},e.prototype.off=function(e,t){var n=this.events.get(e);if(t){if(n){var r=n.indexOf(t);r>=0&&n.splice(r,1)}}else this.events.set(e,[])},e.prototype.emit=function(e,t){var n=this.events.get(e);n&&n.forEach((function(e){return e(t)}))},e}(),s=function(e){return e.split("").reverse().join("")},f=function(e){return/^[A-Za-z]$/.test(e)},l=function(e,t,n){n.mask++,n.text++;var r=e[n.mask],u=t[n.text];return o(r)||o(u)?"":function(e,t,n){switch(e.toUpperCase()){case"#":return t;case"0":case"9":return function(e){return/^[0-9]$/.test(e)}(t)?t:(n.mask--,"");case"A":case"Z":return f(t)?t:(n.mask--,"");case"L":return f(t)?t.toLowerCase():(n.mask--,"");case"U":return f(t)?t.toUpperCase():(n.mask--,"");case"S":return function(e){return/^[^A-Za-z0-9]$/.test(e)}(t)?t:(n.mask--,"");default:return e!=t&&n.text--,e}}(r,u,n)+l(e,t,n)},p=function(e,t){return l(e,t,{mask:-1,text:-1})},h=p,v=function(e,t){return s(h(s(e),s(t)))},b=function(){return b=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var u in t=arguments[n])Object.prototype.hasOwnProperty.call(t,u)&&(e[u]=t[u]);return e},b.apply(this,arguments)};function d(e,t,n,r){return new(n||(n=Promise))((function(u,o){function i(e){try{a(r.next(e))}catch(e){o(e)}}function c(e){try{a(r.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?u(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,c)}a((r=r.apply(e,t||[])).next())}))}function g(e,t){var n,r,u,o,i={label:0,sent:function(){if(1&u[0])throw u[1];return u[1]},trys:[],ops:[]};return o={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function c(o){return function(c){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(u=2&o[0]?r.return:o[0]?r.throw||((u=r.return)&&u.call(r),0):r.next)&&!(u=u.call(r,o[1])).done)return u;switch(r=0,u&&(o=[2&o[0],u.value]),o[0]){case 0:case 1:u=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,r=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!(u=i.trys,(u=u.length>0&&u[u.length-1])||6!==o[0]&&2!==o[0])){i=0;continue}if(3===o[0]&&(!u||o[1]>u[0]&&o[1]<u[3])){i.label=o[1];break}if(6===o[0]&&i.label<u[1]){i.label=u[1],u=o;break}if(u&&i.label<u[2]){i.label=u[2],i.ops.push(o);break}u[2]&&i.ops.pop(),i.trys.pop();continue}o=t.call(e,i)}catch(e){o=[6,e],r=0}finally{n=u=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,c])}}}var y=function(e,t){return e.reduce((function(e,n){var r;return b(b({},e),((r={})[n]=t[n],r))}),{})};return e.EventEmitter=a,e.allowedObject=y,e.camelCase=function(e){return e.toLowerCase().replace(/\W+/g," ").trim().replace(/ (.)/g,(function(e){return e.toUpperCase()})).replace(/ /g,"")},e.chunkArray=function(e,t){void 0===t&&(t=1);for(var n=[],r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n},e.dateFormat=function(e,t){return t.replace(/%[yYmdHMS]/g,(function(t){var n;switch(t){case"%y":n=e.getFullYear();break;case"%Y":return e.getFullYear().toString();case"%m":n=e.getMonth()+1;break;case"%d":n=e.getDate();break;case"%H":n=e.getHours();break;case"%M":n=e.getMinutes();break;case"%S":n=e.getSeconds();break;default:return t.slice(1)}return("0"+n.toString()).slice(-2)}))},e.deniedObject=function(e,t){return y(Object.keys(t).filter((function(t){return-1==e.indexOf(t)})),t)},e.forEachAsync=function(e,t,n){return d(void 0,void 0,void 0,(function(){return g(this,(function(r){switch(r.label){case 0:return[4,Promise.all(e.map((function(r,u){return t.call(n||null,r,u,e)})))];case 1:return r.sent(),[2]}}))}))},e.forEachSeries=function(e,t,n){return d(void 0,void 0,void 0,(function(){var r;return g(this,(function(u){switch(u.label){case 0:r=0,u.label=1;case 1:return r<e.length?[4,t.call(n||null,e[r],r,e)]:[3,4];case 2:u.sent(),u.label=3;case 3:return r++,[3,1];case 4:return[2]}}))}))},e.forLoop=function(e,t,n){for(var r=1;r<=e;r++)t.call(n||null,r,e);return e},e.isArray=n,e.isBoolean=function(e){return"boolean"==i(e)},e.isDef=r,e.isFloat=function(e){return u(e)&&!!(e%1)},e.isFunction=function(e){return"function"==i(e)},e.isInteger=function(e){return u(e)&&!(e%1)},e.isNull=function(e){return null===e},e.isNumber=u,e.isObject=function(e){return"object"==i(e)},e.isString=function(e){return"string"==i(e)},e.isUndefined=o,e.mask=p,e.maskMoney=function(e,t,n){return void 0===n&&(n=2),n++,t=parseInt((t||"0").replace(/\W/g,"")).toString(),v(e,t.length<n?("0".repeat(n)+t).slice(-1*n):t)},e.maskReverse=v,e.noop=function(){},e.shadeColor=function(e,t){return"#"+e.replace(/^#/,"").replace(/../g,(function(e){return("0"+c(e,t)).substr(-2)}))},e.sleep=function(e){return new Promise((function(t){return setTimeout(t,e)}))},e.stringReverse=s,e.toArray=function(e){return n(e)?e:r(e)?[e]:[]},e.type=i,Object.defineProperty(e,"__esModule",{value:!0}),e}({});
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * @andrewcaires/utils.js v0.0.6
3
- * (c) 2021 Andrew Caires
2
+ * @andrewcaires/utils.js v0.0.7
3
+ * (c) 2022 Andrew Caires
4
4
  * @license: MIT
5
5
  */
6
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e={},t=function(e){return"array"==u(e)},n=function(e){return"null"!=u(e)},r=function(e){return"number"==u(e)},o=function(e){return void 0===e},u=function(t){return null==t?"null":e[e.toString.call(t)]||"object"};["Array","Boolean","Function","Number","Object","String"].forEach((function(t){return e["[object "+t+"]"]=t.toLowerCase()}));var s=function(e,t){return(n=parseInt(e,16)+t,Math.min(255,Math.max(0,n))).toString(16);var n},i=function(){function e(){this.events=new Map}return e.prototype.on=function(e,t){var n=this,r=this.events.get(e);return r?r.push(t):this.events.set(e,[t]),{dispose:function(){return n.off(e,t)}}},e.prototype.once=function(e,t){var n=this,r=function(o){t(o),n.off(e,r)};return this.on(e,r),{dispose:function(){return n.off(e,r)}}},e.prototype.off=function(e,t){var n=this.events.get(e);if(t){if(n){var r=n.indexOf(t);r>=0&&n.splice(r,1)}}else this.events.set(e,[])},e.prototype.emit=function(e,t){var n=this.events.get(e);n&&n.forEach((function(e){return e(t)}))},e}(),c=function(e){return e.split("").reverse().join("")},a=function(e){return/^[A-Za-z]$/.test(e)},f=function(e,t,n){n.mask++,n.text++;var r=e[n.mask],u=t[n.text];return o(r)||o(u)?"":function(e,t,n){switch(e.toUpperCase()){case"#":return t;case"0":case"9":return function(e){return/^[0-9]$/.test(e)}(t)?t:(n.mask--,"");case"A":case"Z":return a(t)?t:(n.mask--,"");case"L":return a(t)?t.toLowerCase():(n.mask--,"");case"U":return a(t)?t.toUpperCase():(n.mask--,"");case"S":return function(e){return/^[^A-Za-z0-9]$/.test(e)}(t)?t:(n.mask--,"");default:return e!=t&&n.text--,e}}(r,u,n)+f(e,t,n)},l=function(e,t){return f(e,t,{mask:-1,text:-1})},p=l,h=function(e,t){return c(p(c(e),c(t)))},v=function(){return v=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},v.apply(this,arguments)};function x(e,t,n,r){return new(n||(n=Promise))((function(o,u){function s(e){try{c(r.next(e))}catch(e){u(e)}}function i(e){try{c(r.throw(e))}catch(e){u(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,i)}c((r=r.apply(e,t||[])).next())}))}function b(e,t){var n,r,o,u,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return u={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function i(u){return function(i){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return s.label++,{value:u[1],done:!1};case 5:s.label++,r=u[1],u=[0];continue;case 7:u=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){s=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){s.label=u[1];break}if(6===u[0]&&s.label<o[1]){s.label=o[1],o=u;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(u);break}o[2]&&s.ops.pop(),s.trys.pop();continue}u=t.call(e,s)}catch(e){u=[6,e],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,i])}}}exports.EventEmitter=i,exports.camelCase=function(e){return e.toLowerCase().replace(/\W+/g," ").trim().replace(/ (.)/g,(function(e){return e.toUpperCase()})).replace(/ /g,"")},exports.chunkArray=function(e,t){void 0===t&&(t=1);for(var n=[],r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n},exports.dateFormat=function(e,t){return t.replace(/%[yYmdHMS]/g,(function(t){var n;switch(t){case"%y":n=e.getFullYear();break;case"%Y":return e.getFullYear().toString();case"%m":n=e.getMonth()+1;break;case"%d":n=e.getDate();break;case"%H":n=e.getHours();break;case"%M":n=e.getMinutes();break;case"%S":n=e.getSeconds();break;default:return t.slice(1)}return("0"+n.toString()).slice(-2)}))},exports.filterObject=function(e,t){return e.reduce((function(e,n){var r;return v(v({},e),((r={})[n]=t[n],r))}),{})},exports.forEachAsync=function(e,t,n){return x(void 0,void 0,void 0,(function(){return b(this,(function(r){switch(r.label){case 0:return[4,Promise.all(e.map((function(r,o){return t.call(n||null,r,o,e)})))];case 1:return r.sent(),[2]}}))}))},exports.forEachSeries=function(e,t,n){return x(void 0,void 0,void 0,(function(){var r;return b(this,(function(o){switch(o.label){case 0:r=0,o.label=1;case 1:return r<e.length?[4,t.call(n||null,e[r],r,e)]:[3,4];case 2:o.sent(),o.label=3;case 3:return r++,[3,1];case 4:return[2]}}))}))},exports.forLoop=function(e,t,n){for(var r=1;r<=e;r++)t.call(n||null,r,e);return e},exports.isArray=t,exports.isBoolean=function(e){return"boolean"==u(e)},exports.isDef=n,exports.isFloat=function(e){return r(e)&&!!(e%1)},exports.isFunction=function(e){return"function"==u(e)},exports.isInteger=function(e){return r(e)&&!(e%1)},exports.isNull=function(e){return null===e},exports.isNumber=r,exports.isObject=function(e){return"object"==u(e)},exports.isString=function(e){return"string"==u(e)},exports.isUndefined=o,exports.mask=l,exports.maskMoney=function(e,t,n){return void 0===n&&(n=2),n++,t=parseInt((t||"0").replace(/\W/g,"")).toString(),h(e,t.length<n?("0".repeat(n)+t).slice(-1*n):t)},exports.maskReverse=h,exports.noop=function(){},exports.shadeColor=function(e,t){return"#"+e.replace(/^#/,"").replace(/../g,(function(e){return("0"+s(e,t)).substr(-2)}))},exports.sleep=function(e){return new Promise((function(t){return setTimeout(t,e)}))},exports.stringReverse=c,exports.toArray=function(e){return t(e)?e:n(e)?[e]:[]},exports.type=u;
6
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e={},t=function(e){return"array"==u(e)},n=function(e){return"null"!=u(e)},r=function(e){return"number"==u(e)},o=function(e){return void 0===e},u=function(t){return null==t?"null":e[e.toString.call(t)]||"object"};["Array","Boolean","Function","Number","Object","String"].forEach((function(t){return e["[object "+t+"]"]=t.toLowerCase()}));var i=function(e,t){return(n=parseInt(e,16)+t,Math.min(255,Math.max(0,n))).toString(16);var n},s=function(){function e(){this.events=new Map}return e.prototype.on=function(e,t){var n=this,r=this.events.get(e);return r?r.push(t):this.events.set(e,[t]),{dispose:function(){return n.off(e,t)}}},e.prototype.once=function(e,t){var n=this,r=function(o){t(o),n.off(e,r)};return this.on(e,r),{dispose:function(){return n.off(e,r)}}},e.prototype.off=function(e,t){var n=this.events.get(e);if(t){if(n){var r=n.indexOf(t);r>=0&&n.splice(r,1)}}else this.events.set(e,[])},e.prototype.emit=function(e,t){var n=this.events.get(e);n&&n.forEach((function(e){return e(t)}))},e}(),c=function(e){return e.split("").reverse().join("")},a=function(e){return/^[A-Za-z]$/.test(e)},f=function(e,t,n){n.mask++,n.text++;var r=e[n.mask],u=t[n.text];return o(r)||o(u)?"":function(e,t,n){switch(e.toUpperCase()){case"#":return t;case"0":case"9":return function(e){return/^[0-9]$/.test(e)}(t)?t:(n.mask--,"");case"A":case"Z":return a(t)?t:(n.mask--,"");case"L":return a(t)?t.toLowerCase():(n.mask--,"");case"U":return a(t)?t.toUpperCase():(n.mask--,"");case"S":return function(e){return/^[^A-Za-z0-9]$/.test(e)}(t)?t:(n.mask--,"");default:return e!=t&&n.text--,e}}(r,u,n)+f(e,t,n)},l=function(e,t){return f(e,t,{mask:-1,text:-1})},p=l,h=function(e,t){return c(p(c(e),c(t)))},v=function(){return v=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},v.apply(this,arguments)};function x(e,t,n,r){return new(n||(n=Promise))((function(o,u){function i(e){try{c(r.next(e))}catch(e){u(e)}}function s(e){try{c(r.throw(e))}catch(e){u(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,s)}c((r=r.apply(e,t||[])).next())}))}function b(e,t){var n,r,o,u,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return u={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function s(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return i.label++,{value:u[1],done:!1};case 5:i.label++,r=u[1],u=[0];continue;case 7:u=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){i=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){i.label=u[1];break}if(6===u[0]&&i.label<o[1]){i.label=o[1],o=u;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(u);break}o[2]&&i.ops.pop(),i.trys.pop();continue}u=t.call(e,i)}catch(e){u=[6,e],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}}var d=function(e,t){return e.reduce((function(e,n){var r;return v(v({},e),((r={})[n]=t[n],r))}),{})};exports.EventEmitter=s,exports.allowedObject=d,exports.camelCase=function(e){return e.toLowerCase().replace(/\W+/g," ").trim().replace(/ (.)/g,(function(e){return e.toUpperCase()})).replace(/ /g,"")},exports.chunkArray=function(e,t){void 0===t&&(t=1);for(var n=[],r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n},exports.dateFormat=function(e,t){return t.replace(/%[yYmdHMS]/g,(function(t){var n;switch(t){case"%y":n=e.getFullYear();break;case"%Y":return e.getFullYear().toString();case"%m":n=e.getMonth()+1;break;case"%d":n=e.getDate();break;case"%H":n=e.getHours();break;case"%M":n=e.getMinutes();break;case"%S":n=e.getSeconds();break;default:return t.slice(1)}return("0"+n.toString()).slice(-2)}))},exports.deniedObject=function(e,t){return d(Object.keys(t).filter((function(t){return-1==e.indexOf(t)})),t)},exports.forEachAsync=function(e,t,n){return x(void 0,void 0,void 0,(function(){return b(this,(function(r){switch(r.label){case 0:return[4,Promise.all(e.map((function(r,o){return t.call(n||null,r,o,e)})))];case 1:return r.sent(),[2]}}))}))},exports.forEachSeries=function(e,t,n){return x(void 0,void 0,void 0,(function(){var r;return b(this,(function(o){switch(o.label){case 0:r=0,o.label=1;case 1:return r<e.length?[4,t.call(n||null,e[r],r,e)]:[3,4];case 2:o.sent(),o.label=3;case 3:return r++,[3,1];case 4:return[2]}}))}))},exports.forLoop=function(e,t,n){for(var r=1;r<=e;r++)t.call(n||null,r,e);return e},exports.isArray=t,exports.isBoolean=function(e){return"boolean"==u(e)},exports.isDef=n,exports.isFloat=function(e){return r(e)&&!!(e%1)},exports.isFunction=function(e){return"function"==u(e)},exports.isInteger=function(e){return r(e)&&!(e%1)},exports.isNull=function(e){return null===e},exports.isNumber=r,exports.isObject=function(e){return"object"==u(e)},exports.isString=function(e){return"string"==u(e)},exports.isUndefined=o,exports.mask=l,exports.maskMoney=function(e,t,n){return void 0===n&&(n=2),n++,t=parseInt((t||"0").replace(/\W/g,"")).toString(),h(e,t.length<n?("0".repeat(n)+t).slice(-1*n):t)},exports.maskReverse=h,exports.noop=function(){},exports.shadeColor=function(e,t){return"#"+e.replace(/^#/,"").replace(/../g,(function(e){return("0"+i(e,t)).substr(-2)}))},exports.sleep=function(e){return new Promise((function(t){return setTimeout(t,e)}))},exports.stringReverse=c,exports.toArray=function(e){return t(e)?e:n(e)?[e]:[]},exports.type=u;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andrewcaires/utils.js",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "JavaScript utility library for web and nodejs development",
5
5
  "main": "dist/utilsjs.umd.js",
6
6
  "module": "dist/utilsjs.esm.js",