@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.
Files changed (145) hide show
  1. package/dist/array-util.d.ts +23 -0
  2. package/dist/array-util.d.ts.map +1 -0
  3. package/dist/array-util.js +27 -0
  4. package/{src/class-factory-pattern.ts → dist/class-factory-pattern.d.ts} +5 -9
  5. package/dist/class-factory-pattern.d.ts.map +1 -0
  6. package/dist/class-factory-pattern.js +26 -0
  7. package/{src/express/error-handler.ts → dist/express/error-handler.d.ts} +2 -10
  8. package/dist/express/error-handler.d.ts.map +1 -0
  9. package/dist/express/error-handler.js +26 -0
  10. package/dist/index.d.ts +17 -0
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +14 -0
  13. package/dist/joi-util.d.ts +47 -0
  14. package/dist/joi-util.d.ts.map +1 -0
  15. package/dist/joi-util.js +62 -0
  16. package/{src/memoize-factory.ts → dist/memoize-factory.d.ts} +3 -14
  17. package/dist/memoize-factory.d.ts.map +1 -0
  18. package/dist/memoize-factory.js +24 -0
  19. package/dist/object-util.d.ts +72 -0
  20. package/dist/object-util.d.ts.map +1 -0
  21. package/dist/object-util.js +115 -0
  22. package/dist/regex-util.d.ts +12 -0
  23. package/dist/regex-util.d.ts.map +1 -0
  24. package/dist/regex-util.js +12 -0
  25. package/dist/single-threshold-promise.d.ts +31 -0
  26. package/dist/single-threshold-promise.d.ts.map +1 -0
  27. package/dist/single-threshold-promise.js +46 -0
  28. package/dist/singleton/async.d.ts +50 -0
  29. package/dist/singleton/async.d.ts.map +1 -0
  30. package/dist/singleton/async.js +75 -0
  31. package/{src/singleton/pattern.ts → dist/singleton/pattern.d.ts} +3 -13
  32. package/dist/singleton/pattern.d.ts.map +1 -0
  33. package/dist/singleton/pattern.js +41 -0
  34. package/dist/string-util.d.ts +10 -0
  35. package/dist/string-util.d.ts.map +1 -0
  36. package/dist/string-util.js +18 -0
  37. package/dist/time-util.d.ts +74 -0
  38. package/dist/time-util.d.ts.map +1 -0
  39. package/dist/time-util.js +90 -0
  40. package/dist/time-zone.d.ts +467 -0
  41. package/dist/time-zone.d.ts.map +1 -0
  42. package/dist/time-zone.js +468 -0
  43. package/{src/timeout.ts → dist/timeout.d.ts} +2 -3
  44. package/dist/timeout.d.ts.map +1 -0
  45. package/dist/timeout.js +17 -0
  46. package/dist/type-util.d.ts +50 -0
  47. package/dist/type-util.d.ts.map +1 -0
  48. package/dist/type-util.js +54 -0
  49. package/lib/array-util.d.ts.map +1 -1
  50. package/lib/array-util.js +30 -28
  51. package/lib/class-factory-pattern.d.ts.map +1 -1
  52. package/lib/class-factory-pattern.js +17 -8
  53. package/lib/express/error-handler.d.ts.map +1 -1
  54. package/lib/express/error-handler.js +15 -11
  55. package/lib/index.d.ts +16 -13
  56. package/lib/index.d.ts.map +1 -1
  57. package/lib/index.js +107 -29
  58. package/lib/joi-util.d.ts.map +1 -1
  59. package/lib/joi-util.js +66 -22
  60. package/lib/memoize-factory.d.ts +1 -1
  61. package/lib/memoize-factory.d.ts.map +1 -1
  62. package/lib/memoize-factory.js +19 -13
  63. package/lib/object-util.d.ts.map +1 -1
  64. package/lib/object-util.js +110 -55
  65. package/lib/package.json +1 -0
  66. package/lib/regex-util.js +15 -13
  67. package/lib/single-threshold-promise.d.ts +1 -1
  68. package/lib/single-threshold-promise.d.ts.map +1 -1
  69. package/lib/single-threshold-promise.js +74 -28
  70. package/lib/singleton/async.d.ts +1 -1
  71. package/lib/singleton/async.d.ts.map +1 -1
  72. package/lib/singleton/async.js +105 -45
  73. package/lib/singleton/pattern.d.ts +1 -1
  74. package/lib/singleton/pattern.d.ts.map +1 -1
  75. package/lib/singleton/pattern.js +13 -12
  76. package/lib/string-util.js +21 -19
  77. package/lib/time-util.js +69 -39
  78. package/lib/time-zone.d.ts +467 -0
  79. package/lib/time-zone.d.ts.map +1 -0
  80. package/lib/time-zone.js +473 -0
  81. package/lib/timeout.js +9 -6
  82. package/lib/type-util.js +57 -55
  83. package/lib/types/global.d.js +5 -0
  84. package/lib/types/types.d.js +3 -0
  85. package/package.json +188 -134
  86. package/lib/array-util.js.map +0 -1
  87. package/lib/class-factory-pattern.js.map +0 -1
  88. package/lib/express/error-handler.js.map +0 -1
  89. package/lib/index.js.map +0 -1
  90. package/lib/joi-util.js.map +0 -1
  91. package/lib/memoize-factory.js.map +0 -1
  92. package/lib/object-util.js.map +0 -1
  93. package/lib/regex-util.js.map +0 -1
  94. package/lib/single-threshold-promise.js.map +0 -1
  95. package/lib/singleton/async.js.map +0 -1
  96. package/lib/singleton/pattern.js.map +0 -1
  97. package/lib/string-util.js.map +0 -1
  98. package/lib/time-util.js.map +0 -1
  99. package/lib/timeout.js.map +0 -1
  100. package/lib/type-util.js.map +0 -1
  101. package/lib/types/any-function/index.d.ts +0 -2
  102. package/lib/types/any-function/index.d.ts.map +0 -1
  103. package/lib/types/any-function/index.js +0 -3
  104. package/lib/types/any-function/index.js.map +0 -1
  105. package/lib/types/any-function/no-params.d.ts +0 -2
  106. package/lib/types/any-function/no-params.d.ts.map +0 -1
  107. package/lib/types/any-function/no-params.js +0 -3
  108. package/lib/types/any-function/no-params.js.map +0 -1
  109. package/lib/types/any-function/promise-no-params.d.ts +0 -2
  110. package/lib/types/any-function/promise-no-params.d.ts.map +0 -1
  111. package/lib/types/any-function/promise-no-params.js +0 -3
  112. package/lib/types/any-function/promise-no-params.js.map +0 -1
  113. package/lib/types/any-function/promise.d.ts +0 -2
  114. package/lib/types/any-function/promise.d.ts.map +0 -1
  115. package/lib/types/any-function/promise.js +0 -3
  116. package/lib/types/any-function/promise.js.map +0 -1
  117. package/src/array-util.test.ts +0 -50
  118. package/src/array-util.ts +0 -26
  119. package/src/class-factory-pattern.test.ts +0 -39
  120. package/src/express/error-handler.test.ts +0 -44
  121. package/src/index.ts +0 -25
  122. package/src/joi-util.test.ts +0 -192
  123. package/src/joi-util.ts +0 -65
  124. package/src/memoize-factory.test.ts +0 -40
  125. package/src/object-util.test.ts +0 -360
  126. package/src/object-util.ts +0 -127
  127. package/src/regex-util.test.ts +0 -25
  128. package/src/regex-util.ts +0 -11
  129. package/src/single-threshold-promise.test.ts +0 -91
  130. package/src/single-threshold-promise.ts +0 -56
  131. package/src/singleton/async.test.ts +0 -122
  132. package/src/singleton/async.ts +0 -90
  133. package/src/singleton/pattern.test.ts +0 -16
  134. package/src/string-util.test.ts +0 -18
  135. package/src/string-util.ts +0 -18
  136. package/src/time-util.test.ts +0 -89
  137. package/src/time-util.ts +0 -98
  138. package/src/timeout.test.ts +0 -65
  139. package/src/type-util.test.ts +0 -20
  140. package/src/type-util.ts +0 -54
  141. package/src/types/any-function/index.ts +0 -1
  142. package/src/types/any-function/no-params.ts +0 -1
  143. package/src/types/any-function/promise-no-params.ts +0 -1
  144. package/src/types/any-function/promise.ts +0 -1
  145. package/src/types/types.d.ts +0 -2
@@ -1,5 +1,8 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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
- const singletonPattern = (factoryFn) => {
36
- const cache = {};
37
- return () => {
38
- if ('singleton' in cache) {
39
- return cache.singleton;
40
- }
41
- return (cache.singleton = factoryFn());
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
+ };
@@ -1,21 +1,23 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  exports.stringUtil = void 0;
4
- exports.stringUtil = {
5
- /**
6
- * Generate random UUID
7
- * @return {string}
8
- * @example
9
- * console.log(stringUtil.uuid()) // "69bfda25-df3f-46b4-8bbb-955cf5193426"
10
- */
11
- generateUUID: () => {
12
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
13
- const r = (Math.random() * 16) | 0;
14
- if (c == 'x') {
15
- return r.toString(16);
16
- }
17
- return ((r & 0x3) | 0x8).toString(16);
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
6
  exports.TimeUtil = exports.DurationUnit = void 0;
7
- const add_1 = __importDefault(require("date-fns/add"));
8
- const addMilliseconds_1 = __importDefault(require("date-fns/addMilliseconds"));
9
- const format_1 = __importDefault(require("date-fns/format"));
10
- const parse_1 = __importDefault(require("date-fns/parse"));
11
- var DurationUnit;
12
- (function (DurationUnit) {
13
- DurationUnit["MILLISECOND"] = "MILLISECOND";
14
- DurationUnit["SECOND"] = "SECOND";
15
- DurationUnit["MINUTE"] = "MINUTE";
16
- DurationUnit["HOUR"] = "HOUR";
17
- DurationUnit["DAY"] = "DAY";
18
- DurationUnit["WEEK"] = "WEEK";
19
- DurationUnit["MONTH"] = "MONTH";
20
- DurationUnit["YEAR"] = "YEAR";
21
- })(DurationUnit = exports.DurationUnit || (exports.DurationUnit = {}));
22
- class TimeUtil {
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
- return new Date();
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
- dateToUnix(date) {
42
- return +(0, format_1.default)(date, 'T');
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
- dateToUnixSec(date) {
54
- return +(0, format_1.default)(date, 't');
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
- unixToDate(unix) {
65
- return (0, parse_1.default)(unix.toString(), 'T', this.now());
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
- unixSecToDate(unix) {
76
- return (0, parse_1.default)(unix.toString(), 't', this.now());
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
- addToDate(params) {
89
- const { date, unit, value } = params;
90
- if (`${unit}` === 'MILLISECOND') {
91
- return (0, addMilliseconds_1.default)(date, value);
92
- }
93
- return (0, add_1.default)(date, { [`${unit.toLowerCase()}s`]: value });
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
- exports.TimeUtil = TimeUtil;
97
- //# sourceMappingURL=time-util.js.map
126
+ }]);
127
+ }();