@powfix/core-js 0.18.2 → 0.19.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 (99) hide show
  1. package/dist/browser/cjs/browser/utils/UUID.js +95 -30
  2. package/dist/browser/cjs/shared/managers/SessionManager.js +0 -10
  3. package/dist/browser/cjs/shared/services/time/TimeService.js +0 -16
  4. package/dist/browser/cjs/shared/utils/ArrayUtils.js +0 -5
  5. package/dist/browser/cjs/shared/utils/AxiosUtils.js +0 -2
  6. package/dist/browser/cjs/shared/utils/Calc.js +1 -1
  7. package/dist/browser/cjs/shared/utils/DateUtils.js +0 -1
  8. package/dist/browser/cjs/shared/utils/Enum.js +36 -0
  9. package/dist/browser/cjs/shared/utils/Enum.types.js +2 -0
  10. package/dist/browser/cjs/shared/utils/JuminNumberUtils.js +1 -4
  11. package/dist/browser/cjs/shared/utils/Sequencer.js +0 -6
  12. package/dist/browser/cjs/shared/utils/StringUtils.js +1 -3
  13. package/dist/browser/cjs/shared/utils/UuidUtils.js +0 -3
  14. package/dist/browser/cjs/shared/utils/Validator.js +0 -11
  15. package/dist/browser/cjs/shared/utils/global/firstNonNullish.js +0 -1
  16. package/dist/browser/cjs/shared/utils/global/flat.js +0 -1
  17. package/dist/browser/cjs/shared/utils/index.js +2 -0
  18. package/dist/browser/cjs/shared/utils/try-catch/TryCatch.js +0 -20
  19. package/dist/browser/esm/browser/utils/UUID.mjs +94 -29
  20. package/dist/browser/esm/shared/managers/SessionManager.mjs +0 -10
  21. package/dist/browser/esm/shared/services/time/TimeService.mjs +0 -16
  22. package/dist/browser/esm/shared/utils/ArrayUtils.mjs +0 -5
  23. package/dist/browser/esm/shared/utils/AxiosUtils.mjs +0 -2
  24. package/dist/browser/esm/shared/utils/Calc.mjs +1 -1
  25. package/dist/browser/esm/shared/utils/DateUtils.mjs +0 -1
  26. package/dist/browser/esm/shared/utils/Enum.mjs +32 -0
  27. package/dist/browser/esm/shared/utils/Enum.types.mjs +1 -0
  28. package/dist/browser/esm/shared/utils/JuminNumberUtils.mjs +1 -4
  29. package/dist/browser/esm/shared/utils/Sequencer.mjs +0 -6
  30. package/dist/browser/esm/shared/utils/StringUtils.mjs +1 -3
  31. package/dist/browser/esm/shared/utils/UuidUtils.mjs +0 -3
  32. package/dist/browser/esm/shared/utils/Validator.mjs +0 -11
  33. package/dist/browser/esm/shared/utils/global/firstNonNullish.mjs +0 -1
  34. package/dist/browser/esm/shared/utils/global/flat.mjs +0 -1
  35. package/dist/browser/esm/shared/utils/index.mjs +2 -0
  36. package/dist/browser/esm/shared/utils/try-catch/TryCatch.mjs +0 -20
  37. package/dist/browser/types/browser/utils/UUID.d.ts +14 -2
  38. package/dist/browser/types/shared/utils/ArrayUtils.d.ts +0 -5
  39. package/dist/browser/types/shared/utils/Enum.d.ts +16 -0
  40. package/dist/browser/types/shared/utils/Enum.types.d.ts +6 -0
  41. package/dist/browser/types/shared/utils/UuidUtils.d.ts +0 -6
  42. package/dist/browser/types/shared/utils/index.d.ts +2 -0
  43. package/dist/browser/types/shared/utils/try-catch/TryCatch.d.ts +0 -20
  44. package/dist/node/cjs/browser/utils/UUID.js +95 -30
  45. package/dist/node/cjs/nodejs/managers/TransactionManager.js +0 -3
  46. package/dist/node/cjs/nodejs/services/redis/RedisClient.js +0 -2
  47. package/dist/node/cjs/nodejs/services/redis/RedisPublisher.js +0 -1
  48. package/dist/node/cjs/nodejs/services/redis/index.js +0 -1
  49. package/dist/node/cjs/nodejs/utils/UUID.js +3 -0
  50. package/dist/node/cjs/shared/managers/SessionManager.js +0 -10
  51. package/dist/node/cjs/shared/services/time/TimeService.js +0 -16
  52. package/dist/node/cjs/shared/utils/ArrayUtils.js +0 -5
  53. package/dist/node/cjs/shared/utils/AxiosUtils.js +0 -2
  54. package/dist/node/cjs/shared/utils/Calc.js +1 -1
  55. package/dist/node/cjs/shared/utils/DateUtils.js +0 -1
  56. package/dist/node/cjs/shared/utils/Enum.js +36 -0
  57. package/dist/node/cjs/shared/utils/Enum.types.js +2 -0
  58. package/dist/node/cjs/shared/utils/JuminNumberUtils.js +1 -4
  59. package/dist/node/cjs/shared/utils/Sequencer.js +0 -6
  60. package/dist/node/cjs/shared/utils/StringUtils.js +1 -3
  61. package/dist/node/cjs/shared/utils/UuidUtils.js +0 -3
  62. package/dist/node/cjs/shared/utils/Validator.js +0 -11
  63. package/dist/node/cjs/shared/utils/global/firstNonNullish.js +0 -1
  64. package/dist/node/cjs/shared/utils/global/flat.js +0 -1
  65. package/dist/node/cjs/shared/utils/index.js +2 -0
  66. package/dist/node/cjs/shared/utils/try-catch/TryCatch.js +0 -20
  67. package/dist/node/esm/browser/utils/UUID.mjs +94 -29
  68. package/dist/node/esm/nodejs/managers/TransactionManager.mjs +0 -3
  69. package/dist/node/esm/nodejs/services/redis/RedisClient.mjs +0 -2
  70. package/dist/node/esm/nodejs/services/redis/RedisPublisher.mjs +0 -1
  71. package/dist/node/esm/nodejs/services/redis/index.mjs +0 -1
  72. package/dist/node/esm/nodejs/utils/UUID.mjs +3 -0
  73. package/dist/node/esm/shared/managers/SessionManager.mjs +0 -10
  74. package/dist/node/esm/shared/services/time/TimeService.mjs +0 -16
  75. package/dist/node/esm/shared/utils/ArrayUtils.mjs +0 -5
  76. package/dist/node/esm/shared/utils/AxiosUtils.mjs +0 -2
  77. package/dist/node/esm/shared/utils/Calc.mjs +1 -1
  78. package/dist/node/esm/shared/utils/DateUtils.mjs +0 -1
  79. package/dist/node/esm/shared/utils/Enum.mjs +32 -0
  80. package/dist/node/esm/shared/utils/Enum.types.mjs +1 -0
  81. package/dist/node/esm/shared/utils/JuminNumberUtils.mjs +1 -4
  82. package/dist/node/esm/shared/utils/Sequencer.mjs +0 -6
  83. package/dist/node/esm/shared/utils/StringUtils.mjs +1 -3
  84. package/dist/node/esm/shared/utils/UuidUtils.mjs +0 -3
  85. package/dist/node/esm/shared/utils/Validator.mjs +0 -11
  86. package/dist/node/esm/shared/utils/global/firstNonNullish.mjs +0 -1
  87. package/dist/node/esm/shared/utils/global/flat.mjs +0 -1
  88. package/dist/node/esm/shared/utils/index.mjs +2 -0
  89. package/dist/node/esm/shared/utils/try-catch/TryCatch.mjs +0 -20
  90. package/dist/node/types/browser/utils/UUID.d.ts +14 -2
  91. package/dist/node/types/nodejs/services/redis/RedisClient.d.ts +2 -2
  92. package/dist/node/types/nodejs/utils/UUID.d.ts +1 -0
  93. package/dist/node/types/shared/utils/ArrayUtils.d.ts +0 -5
  94. package/dist/node/types/shared/utils/Enum.d.ts +16 -0
  95. package/dist/node/types/shared/utils/Enum.types.d.ts +6 -0
  96. package/dist/node/types/shared/utils/UuidUtils.d.ts +0 -6
  97. package/dist/node/types/shared/utils/index.d.ts +2 -0
  98. package/dist/node/types/shared/utils/try-catch/TryCatch.d.ts +0 -20
  99. package/package.json +2 -2
@@ -1,8 +1,42 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UUID = void 0;
4
- const Uint8ArrayUtils_1 = require("../../shared/utils/Uint8ArrayUtils");
4
+ const shared_1 = require("../../shared");
5
5
  class UUID {
6
+ static isValidHex(hex) {
7
+ if (typeof hex !== 'string') {
8
+ return false;
9
+ }
10
+ return UUID.REGEX_HEX.test(hex);
11
+ }
12
+ static isValidString(str) {
13
+ if (typeof str !== 'string') {
14
+ return false;
15
+ }
16
+ return UUID.REGEX_RFC4122.test(str);
17
+ }
18
+ static isValidBytes(bytes) {
19
+ return bytes.byteLength === UUID.BYTE_LENGTH;
20
+ }
21
+ static isValid(input) {
22
+ if (typeof input === 'string') {
23
+ const length = input.length;
24
+ switch (length) {
25
+ case UUID.STR_LENGTH:
26
+ return UUID.isValidString(input);
27
+ case UUID.HEX_STR_LENGTH:
28
+ return UUID.isValidHex(input);
29
+ default:
30
+ return false;
31
+ }
32
+ }
33
+ else if (ArrayBuffer.isView(input)) {
34
+ return UUID.isValidBytes(input);
35
+ }
36
+ else {
37
+ return false;
38
+ }
39
+ }
6
40
  static formatHex(hex) {
7
41
  if (hex.length !== UUID.HEX_STR_LENGTH) {
8
42
  throw new Error(`hex length should be ${UUID.HEX_STR_LENGTH}`);
@@ -16,34 +50,74 @@ class UUID {
16
50
  static stripHyphens(str) {
17
51
  return str.replace(/-/g, "");
18
52
  }
53
+ static parseHex(hex) {
54
+ if (hex.length !== UUID.HEX_STR_LENGTH) {
55
+ throw new Error(`Invalid hex string, length should be ${UUID.HEX_STR_LENGTH}`);
56
+ }
57
+ return shared_1.Uint8ArrayUtils.fromHex(hex);
58
+ }
19
59
  static parseString(str) {
60
+ if (str.length !== UUID.STR_LENGTH) {
61
+ throw new Error(`Invalid UUID string, invalid character length should be ${UUID.STR_LENGTH}`);
62
+ }
63
+ if (!UUID.isValid(str)) {
64
+ throw new Error('Invalid UUID string, should be RFC 4122 format');
65
+ }
20
66
  const hex = UUID.stripHyphens(str);
21
67
  if (hex.length !== UUID.HEX_STR_LENGTH) {
22
- throw new Error('Invalid UUID string');
68
+ throw new Error('Invalid UUID string, invalid character length after strip hyphens');
69
+ }
70
+ return shared_1.Uint8ArrayUtils.fromHex(hex);
71
+ }
72
+ static parseBytes(bytes) {
73
+ const view = new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
74
+ if (view.length !== UUID.BYTE_LENGTH) {
75
+ throw new Error(`Expected ${UUID.BYTE_LENGTH} bytes`);
23
76
  }
24
- return Uint8ArrayUtils_1.Uint8ArrayUtils.fromHex(hex);
77
+ return new Uint8Array(view);
78
+ }
79
+ static fromHex(hex) {
80
+ return new UUID(UUID.parseHex(hex));
25
81
  }
26
82
  static fromString(str) {
27
- return new UUID(str);
83
+ return new UUID(UUID.parseString(str));
28
84
  }
29
- static parseBytes(bytes) {
30
- if (bytes instanceof Uint8Array) {
31
- return new Uint8Array(bytes);
85
+ static fromBytes(bytes) {
86
+ return new UUID(UUID.parseBytes(bytes));
87
+ }
88
+ static parse(input) {
89
+ if (typeof input === 'string') {
90
+ const length = input.length;
91
+ switch (length) {
92
+ case UUID.STR_LENGTH:
93
+ return UUID.parseString(input);
94
+ case UUID.HEX_STR_LENGTH:
95
+ return UUID.parseHex(input);
96
+ default:
97
+ throw new Error(`Invalid input string, length should be ${UUID.STR_LENGTH} or ${UUID.HEX_STR_LENGTH}`);
98
+ }
99
+ }
100
+ else if (ArrayBuffer.isView(input)) {
101
+ return UUID.parseBytes(input);
32
102
  }
33
103
  else {
34
- return new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
104
+ throw new Error("Invalid input, Expected string or ArrayBufferView");
35
105
  }
36
106
  }
37
- static fromBytes(bytes) {
38
- return new UUID(UUID.parseBytes(bytes));
107
+ static from(input) {
108
+ return UUID.fromBytes(UUID.parse(input));
39
109
  }
40
110
  static nil() {
41
- return new UUID(new Uint8Array(UUID.BYTE_LENGTH));
111
+ return UUID.fromBytes(new Uint8Array(UUID.BYTE_LENGTH));
112
+ }
113
+ static max() {
114
+ return UUID.fromBytes((new Uint8Array(UUID.BYTE_LENGTH)).fill(0xFF));
42
115
  }
43
116
  static equals(...uuids) {
44
117
  const n = uuids.length;
45
- if (n <= 1)
46
- return true;
118
+ if (n < 2) {
119
+ throw new Error('At least two UUIDs required for comparison');
120
+ }
47
121
  const ref = uuids[0].bytes;
48
122
  for (let i = 1; i < n; ++i) {
49
123
  const b = uuids[i].bytes;
@@ -64,21 +138,7 @@ class UUID {
64
138
  return 0;
65
139
  }
66
140
  constructor(input) {
67
- if (input == null) {
68
- throw new Error('Input cannot be null');
69
- }
70
- if (typeof input === 'string') {
71
- this.bytes = UUID.parseString(input);
72
- }
73
- else if (ArrayBuffer.isView(input)) {
74
- this.bytes = UUID.parseBytes(input);
75
- }
76
- else {
77
- throw new Error("Expected string or ArrayBufferView");
78
- }
79
- if (this.bytes.byteLength !== UUID.BYTE_LENGTH) {
80
- throw new Error(`UUID must be ${UUID.BYTE_LENGTH} bytes`);
81
- }
141
+ this.bytes = UUID.parse(input);
82
142
  }
83
143
  equals(...uuids) {
84
144
  return UUID.equals(this, ...uuids);
@@ -91,13 +151,15 @@ class UUID {
91
151
  return this._str;
92
152
  }
93
153
  const hex = this.toHex();
94
- return UUID.formatHex(hex);
154
+ this._str = UUID.formatHex(hex);
155
+ return this._str;
95
156
  }
96
157
  toHex() {
97
158
  if (this._hex != null) {
98
159
  return this._hex;
99
160
  }
100
- return Uint8ArrayUtils_1.Uint8ArrayUtils.toHex(this.bytes);
161
+ this._hex = shared_1.Uint8ArrayUtils.toHex(this.bytes);
162
+ return this._hex;
101
163
  }
102
164
  toBytes() {
103
165
  return new Uint8Array(this.bytes);
@@ -107,5 +169,8 @@ class UUID {
107
169
  }
108
170
  }
109
171
  exports.UUID = UUID;
172
+ UUID.REGEX_HEX = /^[0-9a-fA-F]{8}[0-9a-fA-F]{4}[1-5][0-9a-fA-F]{3}[89abAB][0-9a-fA-F]{3}[0-9a-fA-F]{12}$/;
173
+ UUID.REGEX_RFC4122 = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/;
110
174
  UUID.BYTE_LENGTH = 16;
175
+ UUID.STR_LENGTH = 36;
111
176
  UUID.HEX_STR_LENGTH = 32;
@@ -19,10 +19,8 @@ const eventemitter3_1 = __importDefault(require("eventemitter3"));
19
19
  class SessionManager extends eventemitter3_1.default {
20
20
  constructor(options) {
21
21
  super();
22
- // Init service parameters
23
22
  this.api = options.api;
24
23
  this.storageProvider = options.storageProvider;
25
- // Logging
26
24
  console.log('SessionManager initialized', Date.now(), options.api);
27
25
  }
28
26
  get key() {
@@ -63,7 +61,6 @@ class SessionManager extends eventemitter3_1.default {
63
61
  return null;
64
62
  }
65
63
  try {
66
- // Replace Bearer prefix
67
64
  nextAuthorization = nextAuthorization.replace(/^Bearer\s+/, '');
68
65
  const decoded = (0, jwt_decode_1.jwtDecode)(nextAuthorization);
69
66
  if (!decoded) {
@@ -104,13 +101,9 @@ class SessionManager extends eventemitter3_1.default {
104
101
  return [decoded.exp, exp.format(), exp.diff(Date.now(), 'days'), 'days left'];
105
102
  })());
106
103
  })();
107
- // AsyncStorage 에 토큰 저장
108
104
  yield this.storageProvider.set(this.key, nextAuthorization);
109
- // API Instance header 설정
110
105
  this.api.defaults.headers.common.Authorization = `Bearer ${nextAuthorization}`;
111
- // Emit
112
106
  this.emit('AUTHORIZATION_CHANGED', nextAuthorization);
113
- // Return
114
107
  return nextAuthorization;
115
108
  }
116
109
  catch (e) {
@@ -121,11 +114,8 @@ class SessionManager extends eventemitter3_1.default {
121
114
  }
122
115
  removeAuthorization() {
123
116
  return __awaiter(this, void 0, void 0, function* () {
124
- // API Instance header 에서 토큰 제거
125
117
  delete this.api.defaults.headers.common.Authorization;
126
- // 스토리지에서 authorization 제거
127
118
  yield this.storageProvider.remove(this.key);
128
- // Emit
129
119
  this.emit('AUTHORIZATION_CHANGED', null);
130
120
  });
131
121
  }
@@ -22,11 +22,9 @@ class TimeService extends eventemitter3_1.default {
22
22
  }
23
23
  constructor(options) {
24
24
  super();
25
- // Options
26
25
  this.syncInterval = options === null || options === void 0 ? void 0 : options.syncInterval;
27
26
  this.clientTimeProvider = options === null || options === void 0 ? void 0 : options.clientTimeProvider;
28
27
  this.serverTimeProvider = options === null || options === void 0 ? void 0 : options.serverTimeProvider;
29
- // Bind
30
28
  this.sync = this.sync.bind(this);
31
29
  this.fetchServerNTPResult = this.fetchServerNTPResult.bind(this);
32
30
  }
@@ -53,7 +51,6 @@ class TimeService extends eventemitter3_1.default {
53
51
  }
54
52
  setSyncInterval(interval) {
55
53
  this.syncInterval = interval;
56
- // Emit
57
54
  this.emit('SYNC_INTERVAL_CHANGED', interval);
58
55
  if (this.syncHandler !== undefined) {
59
56
  this.stopSync();
@@ -108,32 +105,22 @@ class TimeService extends eventemitter3_1.default {
108
105
  sync() {
109
106
  return __awaiter(this, void 0, void 0, function* () {
110
107
  try {
111
- // T1 (Client Request Time)
112
108
  const requestedAt = Date.now();
113
- // Fetch server time from server
114
109
  const serverNtpResult = yield this.fetchServerNTPResult(requestedAt);
115
- // Check is null
116
110
  if (serverNtpResult === null) {
117
111
  console.warn(LOG_TAG, 'Failed to get server time');
118
112
  return null;
119
113
  }
120
- // T2 (Server Receive Time)
121
114
  const { t2 } = serverNtpResult;
122
- // Check is not a number
123
115
  if (isNaN(Number(t2))) {
124
- // Not a Number
125
116
  console.error(LOG_TAG, 'invalid server time(t2), not a number', t2);
126
117
  return null;
127
118
  }
128
- // T3 (Server Transmit Time)
129
119
  const { t3 } = serverNtpResult;
130
- // Check is not a number
131
120
  if (isNaN(Number(t3))) {
132
- // Not a Number
133
121
  console.error(LOG_TAG, 'invalid server time(t2), not a number', t2);
134
122
  return null;
135
123
  }
136
- // T4 (Client Receive Time)
137
124
  const receivedAt = Date.now();
138
125
  const ntpResult = {
139
126
  t1: requestedAt,
@@ -141,11 +128,8 @@ class TimeService extends eventemitter3_1.default {
141
128
  t3: t3,
142
129
  t4: receivedAt,
143
130
  };
144
- // Calculate offset
145
131
  const offset = TimeService.calculateNTPResultOffset(ntpResult);
146
- // Save calculated offset
147
132
  this.setOffset(offset);
148
- // Mark synced timestamp
149
133
  const syncedAt = Date.now();
150
134
  this.setSyncedAt(syncedAt);
151
135
  this.emit('SYNCED', offset, syncedAt);
@@ -6,11 +6,6 @@ class ArrayUtils {
6
6
  static castArray(value) {
7
7
  return (0, global_1.castArray)(value);
8
8
  }
9
- /**
10
- * 객체를 요소로 가지는 배열에서 가장 큰 값(Property)를 가지는 객체를 반환한다
11
- * @param e 객체 배열
12
- * @param key 값을 비교할 Property 키
13
- */
14
9
  static getGreatestObject(e, key) {
15
10
  return e.reduce((prev, current) => ((prev[key] > current[key] ? prev : current)));
16
11
  }
@@ -16,7 +16,6 @@ class AxiosUtils {
16
16
  return e;
17
17
  }
18
18
  }
19
- // There is no any values having string type
20
19
  return null;
21
20
  }
22
21
  else {
@@ -39,7 +38,6 @@ class AxiosUtils {
39
38
  return e;
40
39
  }
41
40
  }
42
- // There is no any values having string type
43
41
  return null;
44
42
  }
45
43
  else {
@@ -17,7 +17,7 @@ class Calc {
17
17
  const len = values.length;
18
18
  if (len === 0)
19
19
  return NaN;
20
- const sorted = values.slice().sort((a, b) => a - b); // O(n log n)
20
+ const sorted = values.slice().sort((a, b) => a - b);
21
21
  const mid = len >> 1;
22
22
  return len % 2 === 0
23
23
  ? (sorted[mid - 1] + sorted[mid]) / 2
@@ -107,7 +107,6 @@ class DateUtils {
107
107
  }
108
108
  exports.DateUtils = DateUtils;
109
109
  DateUtils.relativeDate = (input, base = Date.now()) => {
110
- // Create new moment instance to apply new locale
111
110
  const datetime = moment_1.default.isMoment(input) ? (0, moment_1.default)(input.toDate()) : (0, moment_1.default)(input);
112
111
  if (!datetime.isValid()) {
113
112
  console.error('core-js:DateUtils.relativeDate() datetime is invalid', datetime);
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Enum = void 0;
4
+ class Enum {
5
+ static entries(e) {
6
+ return Object.entries(e).filter(([key, value]) => !/^-?\d+$/g.test(key) && typeof value !== 'function');
7
+ }
8
+ static keys(e) {
9
+ return Enum.entries(e).map(([key,]) => key);
10
+ }
11
+ static values(e) {
12
+ return Enum.entries(e).map(([, value]) => value);
13
+ }
14
+ static from(e) {
15
+ return new Enum(e);
16
+ }
17
+ constructor(e) {
18
+ this._e = e;
19
+ this._entries = Enum.entries(e);
20
+ this._keys = Enum.keys(e);
21
+ this._values = Enum.values(e);
22
+ }
23
+ value() {
24
+ return this._e;
25
+ }
26
+ entries() {
27
+ return this._entries;
28
+ }
29
+ keys() {
30
+ return this._keys;
31
+ }
32
+ values() {
33
+ return this._values;
34
+ }
35
+ }
36
+ exports.Enum = Enum;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -19,10 +19,9 @@ class JuminNumberUtils {
19
19
  if (replacedJuminNumber.length !== 13) {
20
20
  return false;
21
21
  }
22
- // 연도에 해당하는 숫자와 성별에 해당하는 숫자 비교
23
22
  const TODAY_YEAR = parseInt(new Date().getFullYear().toString().slice(-2), 10);
24
23
  const yearNum = parseInt(replacedJuminNumber.slice(0, 2), 10);
25
- const sexNum = replacedJuminNumber.slice(6, 7); // 대시 있는경우 7로 변경
24
+ const sexNum = replacedJuminNumber.slice(6, 7);
26
25
  if (sexNum === '1' || sexNum === '2') {
27
26
  if (yearNum < TODAY_YEAR)
28
27
  return false;
@@ -33,11 +32,9 @@ class JuminNumberUtils {
33
32
  }
34
33
  else
35
34
  return false;
36
- // 월과 일에 해당하는 숫자 조건 검사 (정규식으로)
37
35
  const regex = /^\d{2}(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])\d{7}$/;
38
36
  if (!regex.test(replacedJuminNumber))
39
37
  return false;
40
- // Validation X
41
38
  const currentX = parseInt(replacedJuminNumber.slice(-1), 10);
42
39
  const calculatedX = JuminNumberUtils.calculateX(replacedJuminNumber);
43
40
  if (currentX !== calculatedX) {
@@ -34,11 +34,9 @@ class Sequencer {
34
34
  this.sequences = [];
35
35
  this.status = SequencerStatus.IDLE;
36
36
  this.minimumExecutionTime = 0;
37
- // Reset variables task is done
38
37
  this.currentSequence = null;
39
38
  this.startTimestamp = null;
40
39
  this.endTimestamp = null;
41
- // Emitter
42
40
  this.eventEmitter = new eventemitter3_1.default();
43
41
  this.pushSequence = (sequence) => {
44
42
  this.sequences.push(sequence);
@@ -57,7 +55,6 @@ class Sequencer {
57
55
  console.log('Currently total execution time', this.executionTime);
58
56
  const sequenceStartTimeStamp = this.getCurrentTimeStamp;
59
57
  this.currentSequence = sequence;
60
- // Emitter
61
58
  this.eventEmitter.emit(SequencerEvent.SEQUENCE_START, sequence);
62
59
  try {
63
60
  yield new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
@@ -101,7 +98,6 @@ class Sequencer {
101
98
  }
102
99
  }));
103
100
  console.log('Out of Promise');
104
- // Emitter
105
101
  this.eventEmitter.emit(SequencerEvent.SEQUENCE_END, sequence);
106
102
  }
107
103
  catch (e) {
@@ -110,14 +106,12 @@ class Sequencer {
110
106
  this.status = SequencerStatus.ERROR;
111
107
  this.currentSequence = null;
112
108
  this.endTimestamp = this.currentSequence;
113
- // IMPORTANT
114
109
  return Promise.reject({
115
110
  sequence,
116
111
  reason: e,
117
112
  });
118
113
  }
119
114
  console.log(`Sequence ${sequence.key} failed`, e);
120
- // Emitter
121
115
  this.eventEmitter.emit(SequencerEvent.SEQUENCE_END, sequence);
122
116
  }
123
117
  }
@@ -28,9 +28,7 @@ StringUtils.levenshteinDistance = (str1 = '', str2 = '') => {
28
28
  for (let j = 1; j <= str2.length; j += 1) {
29
29
  for (let i = 1; i <= str1.length; i += 1) {
30
30
  const indicator = str1[i - 1] === str2[j - 1] ? 0 : 1;
31
- track[j][i] = Math.min(track[j][i - 1] + 1, // deletion
32
- track[j - 1][i] + 1, // insertion
33
- track[j - 1][i - 1] + indicator);
31
+ track[j][i] = Math.min(track[j][i - 1] + 1, track[j - 1][i] + 1, track[j - 1][i - 1] + indicator);
34
32
  }
35
33
  }
36
34
  return track[str2.length][str1.length];
@@ -42,15 +42,12 @@ class UuidUtils {
42
42
  }
43
43
  static format(uuid) {
44
44
  if (uuid.length === 32) {
45
- // Without dash: ca23c587d7f84c76be59f53bbc9f91f8
46
45
  return `${uuid.substring(0, 8)}-${uuid.substring(8, 12)}-${uuid.substring(12, 16)}-${uuid.substring(16, 20)}-${uuid.substring(20, 32)}`.toLowerCase();
47
46
  }
48
47
  else if (uuid.length === 36) {
49
- // With dash: ca23c587-d7f8-4c76-be59-f53bbc9f91f8
50
48
  return uuid.toLowerCase();
51
49
  }
52
50
  else {
53
- // Unexpected uuid
54
51
  console.warn('Unexpected uuid length', uuid);
55
52
  return uuid;
56
53
  }
@@ -16,14 +16,12 @@ class Validator {
16
16
  const startsWithNumber = /^\d/.test(value);
17
17
  const startsWithAlphabet = /^[A-Za-z]/.test(value);
18
18
  const startsWithSpecialCharacter = /^[~`!@#$%^&*()\-+={[}\]|\\:;"'<,>.?/]/.test(value);
19
- // 최소 길이
20
19
  if (options.minLength !== undefined && options.minLength > -1) {
21
20
  validations.push(Validator.VALIDATION.MIN_LENGTH);
22
21
  if (length < options.minLength) {
23
22
  errors.push(Validator.VALIDATION.MIN_LENGTH);
24
23
  }
25
24
  }
26
- // 최대 길이
27
25
  if (options.maxLength !== undefined && options.maxLength > -1) {
28
26
  validations.push(Validator.VALIDATION.MAX_LENGTH);
29
27
  if (length > options.maxLength) {
@@ -46,39 +44,30 @@ class Validator {
46
44
  }
47
45
  }
48
46
  };
49
- // 공백 개수
50
47
  validateMin(options.spaceMinCount, spaceCount, Validator.VALIDATION.SPACE_MIN_COUNT);
51
48
  validateMax(options.spaceMaxCount, spaceCount, Validator.VALIDATION.SPACE_MAX_COUNT);
52
- // 숫자 개수
53
49
  validateMin(options.numberMinCount, numberCount, Validator.VALIDATION.NUMBER_MIN_COUNT);
54
50
  validateMax(options.numberMaxCount, numberCount, Validator.VALIDATION.NUMBER_MAX_COUNT);
55
- // 알파벳 개수
56
51
  validateMin(options.alphabetMinCount, alphabetCount, Validator.VALIDATION.ALPHABET_MIN_COUNT);
57
52
  validateMax(options.alphabetMaxCount, alphabetCount, Validator.VALIDATION.ALPHABET_MAX_COUNT);
58
- // 알파벳(소문자) 개수
59
53
  validateMin(options.alphabetLowerCaseMinCount, alphabetLowerCaseCount, Validator.VALIDATION.ALPHABET_LOWER_CASE_MIN_COUNT);
60
54
  validateMax(options.alphabetLowerCaseMaxCount, alphabetLowerCaseCount, Validator.VALIDATION.ALPHABET_LOWER_CASE_MAX_COUNT);
61
- // 알파벳(대문자) 개수
62
55
  validateMin(options.alphabetUpperCaseMinCount, alphabetUpperCaseCount, Validator.VALIDATION.ALPHABET_UPPER_CASE_MIN_COUNT);
63
56
  validateMax(options.alphabetUpperCaseMaxCount, alphabetUpperCaseCount, Validator.VALIDATION.ALPHABET_UPPER_CASE_MAX_COUNT);
64
- // 특수문자 개수
65
57
  validateMin(options.specialCharacterMinCount, specialCount, Validator.VALIDATION.SPECIAL_CHARACTER_MIN_COUNT);
66
58
  validateMax(options.specialCharacterMaxCount, specialCount, Validator.VALIDATION.SPECIAL_CHARACTER_MAX_COUNT);
67
- // 숫자로 시작
68
59
  if (options.startsWithNumber) {
69
60
  validations.push(Validator.VALIDATION.STARTS_WITH_NUMBER);
70
61
  if (!startsWithNumber) {
71
62
  errors.push(Validator.VALIDATION.STARTS_WITH_NUMBER);
72
63
  }
73
64
  }
74
- // 영문으로 시작
75
65
  if (options.startsWithAlphabet) {
76
66
  validations.push(Validator.VALIDATION.STARTS_WITH_ALPHABET);
77
67
  if (!startsWithAlphabet) {
78
68
  errors.push(Validator.VALIDATION.STARTS_WITH_ALPHABET);
79
69
  }
80
70
  }
81
- // 특수문자로 시작
82
71
  if (options.startsWithSpecialCharacter) {
83
72
  validations.push(Validator.VALIDATION.STARTS_WITH_SPECIAL_CHARACTER);
84
73
  if (!startsWithSpecialCharacter) {
@@ -6,7 +6,6 @@ function firstNonNullish(...args) {
6
6
  return undefined;
7
7
  }
8
8
  if (args[0] != null) {
9
- // Not Nullish
10
9
  return args[0];
11
10
  }
12
11
  return firstNonNullish(...args.slice(1));
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- // flat.ts
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.flatten = flatten;
5
4
  exports.unflatten = unflatten;
@@ -24,6 +24,8 @@ __exportStar(require("./BooleanUtils"), exports);
24
24
  __exportStar(require("./Calc"), exports);
25
25
  __exportStar(require("./CoordinateUtils"), exports);
26
26
  __exportStar(require("./DateUtils"), exports);
27
+ __exportStar(require("./Enum"), exports);
28
+ __exportStar(require("./Enum.types"), exports);
27
29
  __exportStar(require("./I18nUtils"), exports);
28
30
  __exportStar(require("./NumberUtils"), exports);
29
31
  __exportStar(require("./ObjectIdUtils"), exports);
@@ -10,19 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.TryCatch = void 0;
13
- /**
14
- * Provides a utility class for handling synchronous and asynchronous operations with a consistent try-catch pattern.
15
- * It returns a tuple where the first element is the error (or null on success) and the second element is the result (or undefined on error).
16
- */
17
13
  class TryCatch {
18
- /**
19
- * Executes a synchronous function within a try-catch block.
20
- * @template T The return type of the function.
21
- * @template E The type of the error that might be thrown (defaults to Error).
22
- * @param fn The synchronous function to execute.
23
- *@param disableLogging console.error is default way of logging on error. You can disable it by setting it true
24
- * @returns A tuple containing the result of the function and an error (null if successful).
25
- */
26
14
  static function(fn, disableLogging) {
27
15
  try {
28
16
  return [
@@ -43,14 +31,6 @@ class TryCatch {
43
31
  ];
44
32
  }
45
33
  }
46
- /**
47
- * Executes an asynchronous function (Promise) within a try-catch block.
48
- * @template T The resolved value type of the Promise.
49
- * @template E The type of the error that might be rejected (defaults to Error).
50
- * @param fn The Promise to await.
51
- * @param disableLogging console.error is default way of logging on error. You can disable it by setting it true
52
- * @returns A tuple containing the resolved value of the Promise and an error (null if successful).
53
- */
54
34
  static asyncFunction(fn, disableLogging) {
55
35
  return __awaiter(this, void 0, void 0, function* () {
56
36
  try {