@beecode/msh-util 1.2.1 → 2.0.0
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/dist/array-util.d.ts +23 -0
- package/dist/array-util.d.ts.map +1 -0
- package/dist/array-util.js +27 -0
- package/{src/class-factory-pattern.ts → dist/class-factory-pattern.d.ts} +5 -9
- package/dist/class-factory-pattern.d.ts.map +1 -0
- package/dist/class-factory-pattern.js +26 -0
- package/{src/express/error-handler.ts → dist/express/error-handler.d.ts} +2 -10
- package/dist/express/error-handler.d.ts.map +1 -0
- package/dist/express/error-handler.js +26 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/joi-util.d.ts +47 -0
- package/dist/joi-util.d.ts.map +1 -0
- package/dist/joi-util.js +62 -0
- package/{src/memoize-factory.ts → dist/memoize-factory.d.ts} +3 -14
- package/dist/memoize-factory.d.ts.map +1 -0
- package/dist/memoize-factory.js +24 -0
- package/dist/object-util.d.ts +72 -0
- package/dist/object-util.d.ts.map +1 -0
- package/dist/object-util.js +115 -0
- package/dist/regex-util.d.ts +12 -0
- package/dist/regex-util.d.ts.map +1 -0
- package/dist/regex-util.js +12 -0
- package/dist/single-threshold-promise.d.ts +31 -0
- package/dist/single-threshold-promise.d.ts.map +1 -0
- package/dist/single-threshold-promise.js +46 -0
- package/dist/singleton/async.d.ts +50 -0
- package/dist/singleton/async.d.ts.map +1 -0
- package/dist/singleton/async.js +75 -0
- package/{src/singleton/pattern.ts → dist/singleton/pattern.d.ts} +3 -13
- package/dist/singleton/pattern.d.ts.map +1 -0
- package/dist/singleton/pattern.js +41 -0
- package/dist/string-util.d.ts +10 -0
- package/dist/string-util.d.ts.map +1 -0
- package/dist/string-util.js +18 -0
- package/dist/time-util.d.ts +74 -0
- package/dist/time-util.d.ts.map +1 -0
- package/dist/time-util.js +90 -0
- package/dist/time-zone.d.ts +467 -0
- package/dist/time-zone.d.ts.map +1 -0
- package/dist/time-zone.js +468 -0
- package/{src/timeout.ts → dist/timeout.d.ts} +2 -3
- package/dist/timeout.d.ts.map +1 -0
- package/dist/timeout.js +17 -0
- package/dist/type-util.d.ts +50 -0
- package/dist/type-util.d.ts.map +1 -0
- package/dist/type-util.js +54 -0
- package/lib/array-util.d.ts.map +1 -1
- package/lib/array-util.js +30 -28
- package/lib/class-factory-pattern.d.ts.map +1 -1
- package/lib/class-factory-pattern.js +17 -8
- package/lib/express/error-handler.d.ts.map +1 -1
- package/lib/express/error-handler.js +15 -11
- package/lib/index.d.ts +16 -13
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +107 -29
- package/lib/joi-util.d.ts.map +1 -1
- package/lib/joi-util.js +66 -22
- package/lib/memoize-factory.d.ts +1 -1
- package/lib/memoize-factory.d.ts.map +1 -1
- package/lib/memoize-factory.js +19 -13
- package/lib/object-util.d.ts.map +1 -1
- package/lib/object-util.js +110 -55
- package/lib/package.json +1 -0
- package/lib/regex-util.js +15 -13
- package/lib/single-threshold-promise.d.ts +1 -1
- package/lib/single-threshold-promise.d.ts.map +1 -1
- package/lib/single-threshold-promise.js +74 -28
- package/lib/singleton/async.d.ts +1 -1
- package/lib/singleton/async.d.ts.map +1 -1
- package/lib/singleton/async.js +105 -45
- package/lib/singleton/pattern.d.ts +1 -1
- package/lib/singleton/pattern.d.ts.map +1 -1
- package/lib/singleton/pattern.js +13 -12
- package/lib/string-util.js +21 -19
- package/lib/time-util.js +69 -39
- package/lib/time-zone.d.ts +467 -0
- package/lib/time-zone.d.ts.map +1 -0
- package/lib/time-zone.js +473 -0
- package/lib/timeout.js +9 -6
- package/lib/type-util.js +57 -55
- package/lib/types/global.d.js +5 -0
- package/lib/types/types.d.js +3 -0
- package/package.json +188 -134
- package/lib/array-util.js.map +0 -1
- package/lib/class-factory-pattern.js.map +0 -1
- package/lib/express/error-handler.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/joi-util.js.map +0 -1
- package/lib/memoize-factory.js.map +0 -1
- package/lib/object-util.js.map +0 -1
- package/lib/regex-util.js.map +0 -1
- package/lib/single-threshold-promise.js.map +0 -1
- package/lib/singleton/async.js.map +0 -1
- package/lib/singleton/pattern.js.map +0 -1
- package/lib/string-util.js.map +0 -1
- package/lib/time-util.js.map +0 -1
- package/lib/timeout.js.map +0 -1
- package/lib/type-util.js.map +0 -1
- package/lib/types/any-function/index.d.ts +0 -2
- package/lib/types/any-function/index.d.ts.map +0 -1
- package/lib/types/any-function/index.js +0 -3
- package/lib/types/any-function/index.js.map +0 -1
- package/lib/types/any-function/no-params.d.ts +0 -2
- package/lib/types/any-function/no-params.d.ts.map +0 -1
- package/lib/types/any-function/no-params.js +0 -3
- package/lib/types/any-function/no-params.js.map +0 -1
- package/lib/types/any-function/promise-no-params.d.ts +0 -2
- package/lib/types/any-function/promise-no-params.d.ts.map +0 -1
- package/lib/types/any-function/promise-no-params.js +0 -3
- package/lib/types/any-function/promise-no-params.js.map +0 -1
- package/lib/types/any-function/promise.d.ts +0 -2
- package/lib/types/any-function/promise.d.ts.map +0 -1
- package/lib/types/any-function/promise.js +0 -3
- package/lib/types/any-function/promise.js.map +0 -1
- package/src/array-util.test.ts +0 -50
- package/src/array-util.ts +0 -26
- package/src/class-factory-pattern.test.ts +0 -39
- package/src/express/error-handler.test.ts +0 -44
- package/src/index.ts +0 -25
- package/src/joi-util.test.ts +0 -192
- package/src/joi-util.ts +0 -65
- package/src/memoize-factory.test.ts +0 -40
- package/src/object-util.test.ts +0 -360
- package/src/object-util.ts +0 -127
- package/src/regex-util.test.ts +0 -25
- package/src/regex-util.ts +0 -11
- package/src/single-threshold-promise.test.ts +0 -91
- package/src/single-threshold-promise.ts +0 -56
- package/src/singleton/async.test.ts +0 -122
- package/src/singleton/async.ts +0 -90
- package/src/singleton/pattern.test.ts +0 -16
- package/src/string-util.test.ts +0 -18
- package/src/string-util.ts +0 -18
- package/src/time-util.test.ts +0 -89
- package/src/time-util.ts +0 -98
- package/src/timeout.test.ts +0 -65
- package/src/type-util.test.ts +0 -20
- package/src/type-util.ts +0 -54
- package/src/types/any-function/index.ts +0 -1
- package/src/types/any-function/no-params.ts +0 -1
- package/src/types/any-function/promise-no-params.ts +0 -1
- package/src/types/any-function/promise.ts +0 -1
- package/src/types/types.d.ts +0 -2
package/lib/singleton/pattern.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
3
6
|
exports.singletonPattern = void 0;
|
|
4
7
|
/**
|
|
5
8
|
* Singleton patter wrapper function
|
|
@@ -32,14 +35,12 @@ exports.singletonPattern = void 0;
|
|
|
32
35
|
* // using
|
|
33
36
|
* console.log('NODE_ENV: ', config().env) // NODE_ENV: prod
|
|
34
37
|
*/
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
};
|
|
44
|
-
exports.singletonPattern = singletonPattern;
|
|
45
|
-
//# sourceMappingURL=pattern.js.map
|
|
38
|
+
var singletonPattern = exports.singletonPattern = function singletonPattern(factoryFn) {
|
|
39
|
+
var cache = {};
|
|
40
|
+
return function () {
|
|
41
|
+
if ('singleton' in cache) {
|
|
42
|
+
return cache.singleton;
|
|
43
|
+
}
|
|
44
|
+
return cache.singleton = factoryFn();
|
|
45
|
+
};
|
|
46
|
+
};
|
package/lib/string-util.js
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
3
6
|
exports.stringUtil = void 0;
|
|
4
|
-
exports.stringUtil = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
21
|
-
//# sourceMappingURL=string-util.js.map
|
|
7
|
+
var stringUtil = exports.stringUtil = {
|
|
8
|
+
/**
|
|
9
|
+
* Generate random UUID
|
|
10
|
+
* @return {string}
|
|
11
|
+
* @example
|
|
12
|
+
* console.log(stringUtil.uuid()) // "69bfda25-df3f-46b4-8bbb-955cf5193426"
|
|
13
|
+
*/
|
|
14
|
+
generateUUID: function generateUUID() {
|
|
15
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
16
|
+
var r = Math.random() * 16 | 0;
|
|
17
|
+
if (c == 'x') {
|
|
18
|
+
return r.toString(16);
|
|
19
|
+
}
|
|
20
|
+
return (r & 0x3 | 0x8).toString(16);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
};
|
package/lib/time-util.js
CHANGED
|
@@ -1,34 +1,49 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
6
|
exports.TimeUtil = exports.DurationUnit = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
(function (
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
7
|
+
var _index = _interopRequireDefault(require("date-fns/add/index.js"));
|
|
8
|
+
var _index2 = _interopRequireDefault(require("date-fns/addMilliseconds/index.js"));
|
|
9
|
+
var _index3 = _interopRequireDefault(require("date-fns/format/index.js"));
|
|
10
|
+
var _index4 = _interopRequireDefault(require("date-fns/parse/index.js"));
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
12
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
13
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
14
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
15
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
16
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
17
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
18
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
19
|
+
var DurationUnit = exports.DurationUnit = /*#__PURE__*/function (DurationUnit) {
|
|
20
|
+
DurationUnit["MILLISECOND"] = "MILLISECOND";
|
|
21
|
+
DurationUnit["SECOND"] = "SECOND";
|
|
22
|
+
DurationUnit["MINUTE"] = "MINUTE";
|
|
23
|
+
DurationUnit["HOUR"] = "HOUR";
|
|
24
|
+
DurationUnit["DAY"] = "DAY";
|
|
25
|
+
DurationUnit["WEEK"] = "WEEK";
|
|
26
|
+
DurationUnit["MONTH"] = "MONTH";
|
|
27
|
+
DurationUnit["YEAR"] = "YEAR";
|
|
28
|
+
return DurationUnit;
|
|
29
|
+
}({});
|
|
30
|
+
var TimeUtil = exports.TimeUtil = /*#__PURE__*/function () {
|
|
31
|
+
function TimeUtil() {
|
|
32
|
+
_classCallCheck(this, TimeUtil);
|
|
33
|
+
}
|
|
34
|
+
return _createClass(TimeUtil, [{
|
|
35
|
+
key: "now",
|
|
36
|
+
value:
|
|
23
37
|
/**
|
|
24
38
|
* return date object with the current time
|
|
25
39
|
* @return {Date}
|
|
26
40
|
* @example
|
|
27
41
|
* console.log(new TimeUtil().now().toISOString()) // 2023-03-08T19:45:01.991Z
|
|
28
42
|
*/
|
|
29
|
-
now() {
|
|
30
|
-
|
|
43
|
+
function now() {
|
|
44
|
+
return new Date();
|
|
31
45
|
}
|
|
46
|
+
|
|
32
47
|
/**
|
|
33
48
|
* Convert date object to unix timestamp (milliseconds)
|
|
34
49
|
* @param {Date} date
|
|
@@ -38,9 +53,12 @@ class TimeUtil {
|
|
|
38
53
|
* const timeUtil = new TimeUtil()
|
|
39
54
|
* console.log(timeUtil.dateToUnix(timeUtil.now())) // 1678304701991
|
|
40
55
|
*/
|
|
41
|
-
|
|
42
|
-
|
|
56
|
+
}, {
|
|
57
|
+
key: "dateToUnix",
|
|
58
|
+
value: function dateToUnix(date) {
|
|
59
|
+
return +(0, _index3["default"])(date, 'T');
|
|
43
60
|
}
|
|
61
|
+
|
|
44
62
|
/**
|
|
45
63
|
* Convert date object to unix timestamp (seconds)
|
|
46
64
|
* @param {Date} date
|
|
@@ -50,9 +68,12 @@ class TimeUtil {
|
|
|
50
68
|
* const timeUtil = new TimeUtil()
|
|
51
69
|
* console.log(timeUtil.dateToUnix(timeUtil.now())) // 1678304701
|
|
52
70
|
*/
|
|
53
|
-
|
|
54
|
-
|
|
71
|
+
}, {
|
|
72
|
+
key: "dateToUnixSec",
|
|
73
|
+
value: function dateToUnixSec(date) {
|
|
74
|
+
return +(0, _index3["default"])(date, 't');
|
|
55
75
|
}
|
|
76
|
+
|
|
56
77
|
/**
|
|
57
78
|
* Convert unix timestamp (milliseconds) to date object
|
|
58
79
|
* @param {number} unix
|
|
@@ -61,9 +82,12 @@ class TimeUtil {
|
|
|
61
82
|
* const timeUtil = new TimeUtil()
|
|
62
83
|
* console.log(timeUtil.unixToDate(1678304701991).toISOString()) // 2023-03-08T19:45:01.991Z
|
|
63
84
|
*/
|
|
64
|
-
|
|
65
|
-
|
|
85
|
+
}, {
|
|
86
|
+
key: "unixToDate",
|
|
87
|
+
value: function unixToDate(unix) {
|
|
88
|
+
return (0, _index4["default"])(unix.toString(), 'T', this.now());
|
|
66
89
|
}
|
|
90
|
+
|
|
67
91
|
/**
|
|
68
92
|
* Convert unix timestamp (seconds) to date object
|
|
69
93
|
* @param {number} unix
|
|
@@ -72,9 +96,12 @@ class TimeUtil {
|
|
|
72
96
|
* const timeUtil = new TimeUtil()
|
|
73
97
|
* console.log(timeUtil.unixToDate(1678304701).toISOString()) // 2023-03-08T19:45:01.000Z
|
|
74
98
|
*/
|
|
75
|
-
|
|
76
|
-
|
|
99
|
+
}, {
|
|
100
|
+
key: "unixSecToDate",
|
|
101
|
+
value: function unixSecToDate(unix) {
|
|
102
|
+
return (0, _index4["default"])(unix.toString(), 't', this.now());
|
|
77
103
|
}
|
|
104
|
+
|
|
78
105
|
/**
|
|
79
106
|
* Change the value of date by unit/value pare.
|
|
80
107
|
* @param {{units: DurationUnitType, value: number, date: Date}} params
|
|
@@ -85,13 +112,16 @@ class TimeUtil {
|
|
|
85
112
|
* console.log(timeUtil.addToDate({date: timeUtil.now(), unit: 'DAY', value: 1 }).toISOString()) // 2023-03-09T19:45:01.991Z
|
|
86
113
|
* console.log(timeUtil.addToDate({date: timeUtil.now(), unit: DurationUnit.MONTH, value: -1 }).toISOString()) //2023-02-08T19:45:01.991Z
|
|
87
114
|
*/
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
115
|
+
}, {
|
|
116
|
+
key: "addToDate",
|
|
117
|
+
value: function addToDate(params) {
|
|
118
|
+
var date = params.date,
|
|
119
|
+
unit = params.unit,
|
|
120
|
+
value = params.value;
|
|
121
|
+
if ("".concat(unit) === 'MILLISECOND') {
|
|
122
|
+
return (0, _index2["default"])(date, value);
|
|
123
|
+
}
|
|
124
|
+
return (0, _index["default"])(date, _defineProperty({}, "".concat(unit.toLowerCase(), "s"), value));
|
|
94
125
|
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
//# sourceMappingURL=time-util.js.map
|
|
126
|
+
}]);
|
|
127
|
+
}();
|