@andrewcaires/utils.js 0.0.4 → 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 +1 -1
- package/dist/utilsjs.d.ts +57 -0
- package/dist/utilsjs.esm.js +3 -3
- package/dist/utilsjs.min.js +3 -3
- package/dist/utilsjs.umd.js +3 -3
- package/package.json +4 -2
- package/dist/types/EventEmitter.d.ts +0 -13
- package/dist/types/UtilsJS.d.ts +0 -5
- package/dist/types/array.d.ts +0 -1
- package/dist/types/mask.d.ts +0 -1
- package/dist/types/promise.d.ts +0 -5
- package/dist/types/type.d.ts +0 -12
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2015-
|
|
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
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
declare const chunkArray: <T>(array: T[], length?: number) => T[][];
|
|
2
|
+
declare const toArray: (value: any) => Array<any>;
|
|
3
|
+
|
|
4
|
+
declare const shadeColor: (color: string, percent: number) => string;
|
|
5
|
+
|
|
6
|
+
declare const dateFormat: (date: Date, format: string) => string;
|
|
7
|
+
|
|
8
|
+
declare type EventCallback = (data?: any) => void;
|
|
9
|
+
interface EventDisposable {
|
|
10
|
+
dispose: () => void;
|
|
11
|
+
}
|
|
12
|
+
declare type EventList = Array<EventCallback>;
|
|
13
|
+
declare class EventEmitter {
|
|
14
|
+
private events;
|
|
15
|
+
constructor();
|
|
16
|
+
on(event: string, callback: EventCallback): EventDisposable;
|
|
17
|
+
once(event: string, callback: EventCallback): EventDisposable;
|
|
18
|
+
off(event: string, callback?: EventCallback): void;
|
|
19
|
+
emit(event: string, data?: any): void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
declare type forLoopCallback = (index: number, count: number) => any;
|
|
23
|
+
declare const forLoop: (count: number, callback: forLoopCallback, thisArg?: any) => number;
|
|
24
|
+
declare const noop: () => void;
|
|
25
|
+
|
|
26
|
+
declare const mask: (mask: string, text: string) => string;
|
|
27
|
+
declare const maskMoney: (mask: string, text: string, decimal?: number) => string;
|
|
28
|
+
declare const maskReverse: (mask: string, text: string) => string;
|
|
29
|
+
|
|
30
|
+
declare type objectRaw = {
|
|
31
|
+
[key: string]: any;
|
|
32
|
+
};
|
|
33
|
+
declare const allowedObject: (allowed: string[], raw: objectRaw) => objectRaw;
|
|
34
|
+
declare const deniedObject: (denied: string[], raw: objectRaw) => objectRaw;
|
|
35
|
+
|
|
36
|
+
declare type forEachCallback<T> = (value: T, index: number, arr: Array<T>) => Promise<void>;
|
|
37
|
+
declare const forEachAsync: <T>(arr: T[], callback: forEachCallback<T>, thisArg?: any) => Promise<void>;
|
|
38
|
+
declare const forEachSeries: <T>(arr: T[], callback: forEachCallback<T>, thisArg?: any) => Promise<void>;
|
|
39
|
+
declare const sleep: (ms: number) => Promise<void>;
|
|
40
|
+
|
|
41
|
+
declare const camelCase: (str: string) => string;
|
|
42
|
+
declare const stringReverse: (str: string) => string;
|
|
43
|
+
|
|
44
|
+
declare const isArray: (test: any) => boolean;
|
|
45
|
+
declare const isBoolean: (test: any) => boolean;
|
|
46
|
+
declare const isDef: (test: any) => boolean;
|
|
47
|
+
declare const isFunction: (test: any) => boolean;
|
|
48
|
+
declare const isNumber: (test: any) => boolean;
|
|
49
|
+
declare const isObject: (test: any) => boolean;
|
|
50
|
+
declare const isString: (test: any) => boolean;
|
|
51
|
+
declare const isFloat: (test: any) => boolean;
|
|
52
|
+
declare const isInteger: (test: any) => boolean;
|
|
53
|
+
declare const isNull: (test: any) => boolean;
|
|
54
|
+
declare const isUndefined: (test: any) => boolean;
|
|
55
|
+
declare const type: (test: any) => string;
|
|
56
|
+
|
|
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 };
|
package/dist/utilsjs.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @andrewcaires/utils.js v0.0.
|
|
3
|
-
* (c)
|
|
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)},
|
|
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};
|
package/dist/utilsjs.min.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @andrewcaires/utils.js v0.0.
|
|
3
|
-
* (c)
|
|
2
|
+
* @andrewcaires/utils.js v0.0.7
|
|
3
|
+
* (c) 2022 Andrew Caires
|
|
4
4
|
* @license: MIT
|
|
5
5
|
*/
|
|
6
|
-
var UtilsJS=function(
|
|
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}({});
|
package/dist/utilsjs.umd.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @andrewcaires/utils.js v0.0.
|
|
3
|
-
* (c)
|
|
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
|
|
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,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@andrewcaires/utils.js",
|
|
3
|
-
"version": "0.0.
|
|
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",
|
|
7
7
|
"unpkg": "dist/utilsjs.min.js",
|
|
8
|
-
"types": "dist/
|
|
8
|
+
"types": "dist/utilsjs.d.ts",
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "rollup -c build/rollup.config.js"
|
|
11
11
|
},
|
|
@@ -31,7 +31,9 @@
|
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@rollup/plugin-commonjs": "^21.0.1",
|
|
33
33
|
"@rollup/plugin-typescript": "^8.3.0",
|
|
34
|
+
"fs": "^0.0.1-security",
|
|
34
35
|
"rollup": "^2.58.3",
|
|
36
|
+
"rollup-plugin-dts": "^4.0.0",
|
|
35
37
|
"rollup-plugin-terser": "^7.0.2"
|
|
36
38
|
}
|
|
37
39
|
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare type EventCallback = (data?: any) => void;
|
|
2
|
-
export interface EventDisposable {
|
|
3
|
-
dispose: () => void;
|
|
4
|
-
}
|
|
5
|
-
export declare type EventList = Array<EventCallback>;
|
|
6
|
-
export declare class EventEmitter {
|
|
7
|
-
private events;
|
|
8
|
-
constructor();
|
|
9
|
-
on(event: string, callback: EventCallback): EventDisposable;
|
|
10
|
-
once(event: string, callback: EventCallback): EventDisposable;
|
|
11
|
-
off(event: string, callback?: EventCallback): void;
|
|
12
|
-
emit(event: string, data?: any): void;
|
|
13
|
-
}
|
package/dist/types/UtilsJS.d.ts
DELETED
package/dist/types/array.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const toArray: (value: any) => Array<any>;
|
package/dist/types/mask.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const mask: (mask: string, text: string) => string;
|
package/dist/types/promise.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
declare type forEachCallback<T> = (value: T, index: number, array: Array<T>) => Promise<void>;
|
|
2
|
-
export declare const forEachAsync: <T>(array: T[], callback: forEachCallback<T>, thisArg?: any) => Promise<void>;
|
|
3
|
-
export declare const forEachSeries: <T>(array: T[], callback: forEachCallback<T>, thisArg?: any) => Promise<void>;
|
|
4
|
-
export declare const sleep: (ms: number) => Promise<void>;
|
|
5
|
-
export {};
|
package/dist/types/type.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export declare const isArray: (test: any) => boolean;
|
|
2
|
-
export declare const isBoolean: (test: any) => boolean;
|
|
3
|
-
export declare const isDef: (test: any) => boolean;
|
|
4
|
-
export declare const isFunction: (test: any) => boolean;
|
|
5
|
-
export declare const isNumber: (test: any) => boolean;
|
|
6
|
-
export declare const isObject: (test: any) => boolean;
|
|
7
|
-
export declare const isString: (test: any) => boolean;
|
|
8
|
-
export declare const isFloat: (test: any) => boolean;
|
|
9
|
-
export declare const isInteger: (test: any) => boolean;
|
|
10
|
-
export declare const isNull: (test: any) => boolean;
|
|
11
|
-
export declare const isUndefined: (test: any) => boolean;
|
|
12
|
-
export declare const type: (test: any) => string;
|