@powfix/core-js 0.19.1 → 0.19.2

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 (83) hide show
  1. package/dist/browser/cjs/browser/utils/UUID.js +132 -0
  2. package/dist/browser/cjs/shared/managers/SessionManager.js +10 -0
  3. package/dist/browser/cjs/shared/services/time/TimeService.js +16 -0
  4. package/dist/browser/cjs/shared/utils/ArrayUtils.js +5 -0
  5. package/dist/browser/cjs/shared/utils/AxiosUtils.js +2 -0
  6. package/dist/browser/cjs/shared/utils/Calc.js +1 -1
  7. package/dist/browser/cjs/shared/utils/DateUtils.js +1 -0
  8. package/dist/browser/cjs/shared/utils/JuminNumberUtils.js +4 -1
  9. package/dist/browser/cjs/shared/utils/Sequencer.js +6 -0
  10. package/dist/browser/cjs/shared/utils/StringUtils.js +3 -1
  11. package/dist/browser/cjs/shared/utils/UuidUtils.js +3 -0
  12. package/dist/browser/cjs/shared/utils/Validator.js +11 -0
  13. package/dist/browser/cjs/shared/utils/global/firstNonNullish.js +1 -0
  14. package/dist/browser/cjs/shared/utils/global/flat.js +1 -0
  15. package/dist/browser/cjs/shared/utils/global/pureEnum.js +9 -0
  16. package/dist/browser/cjs/shared/utils/try-catch/TryCatch.js +20 -0
  17. package/dist/browser/esm/browser/utils/UUID.mjs +132 -0
  18. package/dist/browser/esm/shared/managers/SessionManager.mjs +10 -0
  19. package/dist/browser/esm/shared/services/time/TimeService.mjs +16 -0
  20. package/dist/browser/esm/shared/utils/ArrayUtils.mjs +5 -0
  21. package/dist/browser/esm/shared/utils/AxiosUtils.mjs +2 -0
  22. package/dist/browser/esm/shared/utils/Calc.mjs +1 -1
  23. package/dist/browser/esm/shared/utils/DateUtils.mjs +1 -0
  24. package/dist/browser/esm/shared/utils/JuminNumberUtils.mjs +4 -1
  25. package/dist/browser/esm/shared/utils/Sequencer.mjs +6 -0
  26. package/dist/browser/esm/shared/utils/StringUtils.mjs +3 -1
  27. package/dist/browser/esm/shared/utils/UuidUtils.mjs +3 -0
  28. package/dist/browser/esm/shared/utils/Validator.mjs +11 -0
  29. package/dist/browser/esm/shared/utils/global/firstNonNullish.mjs +1 -0
  30. package/dist/browser/esm/shared/utils/global/flat.mjs +1 -0
  31. package/dist/browser/esm/shared/utils/global/pureEnum.mjs +9 -0
  32. package/dist/browser/esm/shared/utils/try-catch/TryCatch.mjs +20 -0
  33. package/dist/browser/types/browser/utils/UUID.d.ts +109 -0
  34. package/dist/browser/types/shared/utils/ArrayUtils.d.ts +5 -0
  35. package/dist/browser/types/shared/utils/UuidUtils.d.ts +6 -0
  36. package/dist/browser/types/shared/utils/global/pureEnum.d.ts +9 -0
  37. package/dist/browser/types/shared/utils/try-catch/TryCatch.d.ts +20 -0
  38. package/dist/node/cjs/browser/utils/UUID.js +132 -0
  39. package/dist/node/cjs/nodejs/managers/TransactionManager.js +3 -0
  40. package/dist/node/cjs/nodejs/services/redis/RedisClient.js +2 -0
  41. package/dist/node/cjs/nodejs/services/redis/RedisPublisher.js +1 -0
  42. package/dist/node/cjs/nodejs/services/redis/index.js +1 -0
  43. package/dist/node/cjs/shared/managers/SessionManager.js +10 -0
  44. package/dist/node/cjs/shared/services/time/TimeService.js +16 -0
  45. package/dist/node/cjs/shared/utils/ArrayUtils.js +5 -0
  46. package/dist/node/cjs/shared/utils/AxiosUtils.js +2 -0
  47. package/dist/node/cjs/shared/utils/Calc.js +1 -1
  48. package/dist/node/cjs/shared/utils/DateUtils.js +1 -0
  49. package/dist/node/cjs/shared/utils/JuminNumberUtils.js +4 -1
  50. package/dist/node/cjs/shared/utils/Sequencer.js +6 -0
  51. package/dist/node/cjs/shared/utils/StringUtils.js +3 -1
  52. package/dist/node/cjs/shared/utils/UuidUtils.js +3 -0
  53. package/dist/node/cjs/shared/utils/Validator.js +11 -0
  54. package/dist/node/cjs/shared/utils/global/firstNonNullish.js +1 -0
  55. package/dist/node/cjs/shared/utils/global/flat.js +1 -0
  56. package/dist/node/cjs/shared/utils/global/pureEnum.js +9 -0
  57. package/dist/node/cjs/shared/utils/try-catch/TryCatch.js +20 -0
  58. package/dist/node/esm/browser/utils/UUID.mjs +132 -0
  59. package/dist/node/esm/nodejs/managers/TransactionManager.mjs +3 -0
  60. package/dist/node/esm/nodejs/services/redis/RedisClient.mjs +2 -0
  61. package/dist/node/esm/nodejs/services/redis/RedisPublisher.mjs +1 -0
  62. package/dist/node/esm/nodejs/services/redis/index.mjs +1 -0
  63. package/dist/node/esm/shared/managers/SessionManager.mjs +10 -0
  64. package/dist/node/esm/shared/services/time/TimeService.mjs +16 -0
  65. package/dist/node/esm/shared/utils/ArrayUtils.mjs +5 -0
  66. package/dist/node/esm/shared/utils/AxiosUtils.mjs +2 -0
  67. package/dist/node/esm/shared/utils/Calc.mjs +1 -1
  68. package/dist/node/esm/shared/utils/DateUtils.mjs +1 -0
  69. package/dist/node/esm/shared/utils/JuminNumberUtils.mjs +4 -1
  70. package/dist/node/esm/shared/utils/Sequencer.mjs +6 -0
  71. package/dist/node/esm/shared/utils/StringUtils.mjs +3 -1
  72. package/dist/node/esm/shared/utils/UuidUtils.mjs +3 -0
  73. package/dist/node/esm/shared/utils/Validator.mjs +11 -0
  74. package/dist/node/esm/shared/utils/global/firstNonNullish.mjs +1 -0
  75. package/dist/node/esm/shared/utils/global/flat.mjs +1 -0
  76. package/dist/node/esm/shared/utils/global/pureEnum.mjs +9 -0
  77. package/dist/node/esm/shared/utils/try-catch/TryCatch.mjs +20 -0
  78. package/dist/node/types/browser/utils/UUID.d.ts +109 -0
  79. package/dist/node/types/shared/utils/ArrayUtils.d.ts +5 -0
  80. package/dist/node/types/shared/utils/UuidUtils.d.ts +6 -0
  81. package/dist/node/types/shared/utils/global/pureEnum.d.ts +9 -0
  82. package/dist/node/types/shared/utils/try-catch/TryCatch.d.ts +20 -0
  83. package/package.json +1 -1
@@ -2,29 +2,61 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UUID = void 0;
4
4
  const shared_1 = require("../../shared");
5
+ /**
6
+ * Represents a UUID (Universally Unique Identifier) and provides various utility
7
+ * methods for validation, conversion, comparison and creation.
8
+ */
5
9
  class UUID {
10
+ /* --------------------------------------------------------------------
11
+ * Validation helpers
12
+ * -------------------------------------------------------------------- */
13
+ /**
14
+ * Checks if the supplied value is a valid hex representation of a UUID.
15
+ * @param hex - The string to validate.
16
+ * @returns true if the string matches {@link REGEX_HEX}.
17
+ */
6
18
  static isValidHex(hex) {
7
19
  if (typeof hex !== 'string') {
8
20
  return false;
9
21
  }
10
22
  return UUID.REGEX_HEX.test(hex);
11
23
  }
24
+ /**
25
+ * Checks if the supplied value is a valid RFC 4122 UUID string.
26
+ * @param str - The string to validate.
27
+ * @returns true if the string matches {@link REGEX_RFC4122}.
28
+ */
12
29
  static isValidString(str) {
13
30
  if (typeof str !== 'string') {
14
31
  return false;
15
32
  }
16
33
  return UUID.REGEX_RFC4122.test(str);
17
34
  }
35
+ /**
36
+ * Checks whether an ArrayBufferView contains exactly {@link BYTE_LENGTH} bytes.
37
+ * @param bytes - The view to check.
38
+ * @returns true if the byte length is correct.
39
+ */
18
40
  static isValidBytes(bytes) {
19
41
  return bytes.byteLength === UUID.BYTE_LENGTH;
20
42
  }
43
+ /**
44
+ * Generic validation that accepts either a string (hex or RFC 4122 format)
45
+ * or an ArrayBufferView containing the raw bytes.
46
+ * @param input - The value to validate.
47
+ * @returns true if the input is a valid representation of a UUID.
48
+ */
21
49
  static isValid(input) {
22
50
  if (typeof input === 'string') {
23
51
  const length = input.length;
24
52
  switch (length) {
25
53
  case UUID.STR_LENGTH:
54
+ // RFC 4122 uuid(string)
55
+ // 9e472052-a654-4693-9a8b-3ce57ada3d6c
26
56
  return UUID.isValidString(input);
27
57
  case UUID.HEX_STR_LENGTH:
58
+ // RFC 4122 uuid(string) without hyphens
59
+ // 9e472052a65446939a8b3ce57ada3d6c
28
60
  return UUID.isValidHex(input);
29
61
  default:
30
62
  return false;
@@ -37,6 +69,14 @@ class UUID {
37
69
  return false;
38
70
  }
39
71
  }
72
+ /* --------------------------------------------------------------------
73
+ * Parsing / formatting helpers
74
+ * -------------------------------------------------------------------- */
75
+ /**
76
+ * Inserts hyphens into a 32‑character hex string to produce an RFC 4122 string.
77
+ * @param hex - The plain hexadecimal UUID.
78
+ * @returns The formatted RFC 4122 string.
79
+ */
40
80
  static formatHex(hex) {
41
81
  if (hex.length !== UUID.HEX_STR_LENGTH) {
42
82
  throw new Error(`hex length should be ${UUID.HEX_STR_LENGTH}`);
@@ -47,15 +87,26 @@ class UUID {
47
87
  hex.slice(16, 20) + '-' +
48
88
  hex.slice(20);
49
89
  }
90
+ /** Removes all hyphens from a UUID string. */
50
91
  static stripHyphens(str) {
51
92
  return str.replace(/-/g, "");
52
93
  }
94
+ /**
95
+ * Converts a plain hexadecimal UUID into a Uint8Array.
96
+ * @param hex - The hex string to parse.
97
+ * @returns A Uint8Array containing the raw bytes.
98
+ */
53
99
  static parseHex(hex) {
54
100
  if (hex.length !== UUID.HEX_STR_LENGTH) {
55
101
  throw new Error(`Invalid hex string, length should be ${UUID.HEX_STR_LENGTH}`);
56
102
  }
57
103
  return shared_1.Uint8ArrayUtils.fromHex(hex);
58
104
  }
105
+ /**
106
+ * Parses an RFC 4122 string into a Uint8Array.
107
+ * @param str - The formatted UUID string.
108
+ * @returns A Uint8Array containing the raw bytes.
109
+ */
59
110
  static parseString(str) {
60
111
  if (str.length !== UUID.STR_LENGTH) {
61
112
  throw new Error(`Invalid UUID string, invalid character length should be ${UUID.STR_LENGTH}`);
@@ -69,6 +120,11 @@ class UUID {
69
120
  }
70
121
  return shared_1.Uint8ArrayUtils.fromHex(hex);
71
122
  }
123
+ /**
124
+ * Parses an ArrayBufferView into a Uint8Array ensuring the correct byte length.
125
+ * @param bytes - The view to parse.
126
+ * @returns A Uint8Array containing the raw bytes.
127
+ */
72
128
  static parseBytes(bytes) {
73
129
  const view = new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
74
130
  if (view.length !== UUID.BYTE_LENGTH) {
@@ -76,22 +132,47 @@ class UUID {
76
132
  }
77
133
  return new Uint8Array(view);
78
134
  }
135
+ /* --------------------------------------------------------------------
136
+ * Factory methods
137
+ * -------------------------------------------------------------------- */
138
+ /**
139
+ * Creates a UUID instance from a plain hexadecimal string.
140
+ * @param hex - The hex representation of the UUID.
141
+ * @returns A new {@link UUID} object.
142
+ */
79
143
  static fromHex(hex) {
80
144
  return new UUID(UUID.parseHex(hex));
81
145
  }
146
+ /**
147
+ * Creates a UUID instance from an RFC 4122 formatted string.
148
+ * @param str - The UUID string with hyphens.
149
+ * @returns A new {@link UUID} object.
150
+ */
82
151
  static fromString(str) {
83
152
  return new UUID(UUID.parseString(str));
84
153
  }
154
+ /**
155
+ * Creates a UUID instance from raw bytes.
156
+ * @param bytes - An ArrayBufferView containing 16 bytes.
157
+ * @returns A new {@link UUID} object.
158
+ */
85
159
  static fromBytes(bytes) {
86
160
  return new UUID(UUID.parseBytes(bytes));
87
161
  }
162
+ /**
163
+ * Parses any supported input (string or bytes) and returns the raw byte array.
164
+ * @param input - The value to parse.
165
+ * @returns A Uint8Array of length {@link BYTE_LENGTH}.
166
+ */
88
167
  static parse(input) {
89
168
  if (typeof input === 'string') {
90
169
  const length = input.length;
91
170
  switch (length) {
92
171
  case UUID.STR_LENGTH:
172
+ // RFC 4122 uuid(string)
93
173
  return UUID.parseString(input);
94
174
  case UUID.HEX_STR_LENGTH:
175
+ // RFC 4122 uuid(string) without hyphens
95
176
  return UUID.parseHex(input);
96
177
  default:
97
178
  throw new Error(`Invalid input string, length should be ${UUID.STR_LENGTH} or ${UUID.HEX_STR_LENGTH}`);
@@ -104,15 +185,30 @@ class UUID {
104
185
  throw new Error("Invalid input, Expected string or ArrayBufferView");
105
186
  }
106
187
  }
188
+ /**
189
+ * Creates a UUID from any supported input type.
190
+ * @param input - The value to parse.
191
+ * @returns A new {@link UUID} object.
192
+ */
107
193
  static from(input) {
108
194
  return UUID.fromBytes(UUID.parse(input));
109
195
  }
196
+ /** Returns the nil (all zero) UUID. */
110
197
  static nil() {
111
198
  return UUID.fromBytes(new Uint8Array(UUID.BYTE_LENGTH));
112
199
  }
200
+ /** Returns a UUID consisting of all 0xFF bytes. */
113
201
  static max() {
114
202
  return UUID.fromBytes((new Uint8Array(UUID.BYTE_LENGTH)).fill(0xFF));
115
203
  }
204
+ /* --------------------------------------------------------------------
205
+ * Equality / comparison
206
+ * -------------------------------------------------------------------- */
207
+ /**
208
+ * Compares multiple UUIDs for strict equality.
209
+ * @param uuids - The UUIDs to compare (at least two required).
210
+ * @returns true if all provided UUIDs are identical.
211
+ */
116
212
  static equals(...uuids) {
117
213
  const n = uuids.length;
118
214
  if (n < 2) {
@@ -128,6 +224,12 @@ class UUID {
128
224
  }
129
225
  return true;
130
226
  }
227
+ /**
228
+ * Lexicographically compares two UUIDs.
229
+ * @param uuid1 - The first UUID.
230
+ * @param uuid2 - The second UUID.
231
+ * @returns -1 if uuid1 < uuid2, 1 if uuid1 > uuid2, 0 otherwise.
232
+ */
131
233
  static compare(uuid1, uuid2) {
132
234
  const a = uuid1.bytes;
133
235
  const b = uuid2.bytes;
@@ -137,15 +239,25 @@ class UUID {
137
239
  }
138
240
  return 0;
139
241
  }
242
+ /**
243
+ * Constructs a new {@link UUID} instance from any supported input type.
244
+ * @param input - The value to parse (string or ArrayBufferView).
245
+ */
140
246
  constructor(input) {
141
247
  this.bytes = UUID.parse(input);
142
248
  }
249
+ /** Instance wrapper for {@link equals}. */
143
250
  equals(...uuids) {
144
251
  return UUID.equals(this, ...uuids);
145
252
  }
253
+ /** Instance wrapper for {@link compare}. */
146
254
  compare(other) {
147
255
  return UUID.compare(this, other);
148
256
  }
257
+ /**
258
+ * Returns the RFC 4122 string representation of this UUID.
259
+ * @returns The formatted UUID string.
260
+ */
149
261
  toString() {
150
262
  if (this._str != null) {
151
263
  return this._str;
@@ -154,6 +266,10 @@ class UUID {
154
266
  this._str = UUID.formatHex(hex);
155
267
  return this._str;
156
268
  }
269
+ /**
270
+ * Returns the plain hexadecimal representation of this UUID.
271
+ * @returns A 32‑character hex string.
272
+ */
157
273
  toHex() {
158
274
  if (this._hex != null) {
159
275
  return this._hex;
@@ -161,16 +277,32 @@ class UUID {
161
277
  this._hex = shared_1.Uint8ArrayUtils.toHex(this.bytes);
162
278
  return this._hex;
163
279
  }
280
+ /**
281
+ * Returns a copy of the raw byte array.
282
+ * @returns A new Uint8Array containing the UUID bytes.
283
+ */
164
284
  toBytes() {
165
285
  return new Uint8Array(this.bytes);
166
286
  }
287
+ /** JSON serialization helper – returns the RFC 4122 string. */
167
288
  toJSON() {
168
289
  return this.toString();
169
290
  }
170
291
  }
171
292
  exports.UUID = UUID;
293
+ /* --------------------------------------------------------------------
294
+ * Regular expressions used to validate UUIDs in different string forms
295
+ * -------------------------------------------------------------------- */
296
+ /** Matches a 32‑character hexadecimal representation of a UUID without hyphens. */
172
297
  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}$/;
298
+ /** Matches the RFC 4122 canonical UUID format with hyphens. */
173
299
  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}$/;
300
+ /* --------------------------------------------------------------------
301
+ * Constant lengths used throughout the class
302
+ * -------------------------------------------------------------------- */
303
+ /** Number of bytes that represent a UUID. */
174
304
  UUID.BYTE_LENGTH = 16;
305
+ /** Total length of an RFC 4122 UUID string (including hyphens). */
175
306
  UUID.STR_LENGTH = 36;
307
+ /** Length of a UUID represented as a plain hexadecimal string. */
176
308
  UUID.HEX_STR_LENGTH = 32;
@@ -19,8 +19,10 @@ 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
22
23
  this.api = options.api;
23
24
  this.storageProvider = options.storageProvider;
25
+ // Logging
24
26
  console.log('SessionManager initialized', Date.now(), options.api);
25
27
  }
26
28
  get key() {
@@ -61,6 +63,7 @@ class SessionManager extends eventemitter3_1.default {
61
63
  return null;
62
64
  }
63
65
  try {
66
+ // Replace Bearer prefix
64
67
  nextAuthorization = nextAuthorization.replace(/^Bearer\s+/, '');
65
68
  const decoded = (0, jwt_decode_1.jwtDecode)(nextAuthorization);
66
69
  if (!decoded) {
@@ -101,9 +104,13 @@ class SessionManager extends eventemitter3_1.default {
101
104
  return [decoded.exp, exp.format(), exp.diff(Date.now(), 'days'), 'days left'];
102
105
  })());
103
106
  })();
107
+ // AsyncStorage 에 토큰 저장
104
108
  yield this.storageProvider.set(this.key, nextAuthorization);
109
+ // API Instance header 설정
105
110
  this.api.defaults.headers.common.Authorization = `Bearer ${nextAuthorization}`;
111
+ // Emit
106
112
  this.emit('AUTHORIZATION_CHANGED', nextAuthorization);
113
+ // Return
107
114
  return nextAuthorization;
108
115
  }
109
116
  catch (e) {
@@ -114,8 +121,11 @@ class SessionManager extends eventemitter3_1.default {
114
121
  }
115
122
  removeAuthorization() {
116
123
  return __awaiter(this, void 0, void 0, function* () {
124
+ // API Instance header 에서 토큰 제거
117
125
  delete this.api.defaults.headers.common.Authorization;
126
+ // 스토리지에서 authorization 제거
118
127
  yield this.storageProvider.remove(this.key);
128
+ // Emit
119
129
  this.emit('AUTHORIZATION_CHANGED', null);
120
130
  });
121
131
  }
@@ -22,9 +22,11 @@ class TimeService extends eventemitter3_1.default {
22
22
  }
23
23
  constructor(options) {
24
24
  super();
25
+ // Options
25
26
  this.syncInterval = options === null || options === void 0 ? void 0 : options.syncInterval;
26
27
  this.clientTimeProvider = options === null || options === void 0 ? void 0 : options.clientTimeProvider;
27
28
  this.serverTimeProvider = options === null || options === void 0 ? void 0 : options.serverTimeProvider;
29
+ // Bind
28
30
  this.sync = this.sync.bind(this);
29
31
  this.fetchServerNTPResult = this.fetchServerNTPResult.bind(this);
30
32
  }
@@ -51,6 +53,7 @@ class TimeService extends eventemitter3_1.default {
51
53
  }
52
54
  setSyncInterval(interval) {
53
55
  this.syncInterval = interval;
56
+ // Emit
54
57
  this.emit('SYNC_INTERVAL_CHANGED', interval);
55
58
  if (this.syncHandler !== undefined) {
56
59
  this.stopSync();
@@ -105,22 +108,32 @@ class TimeService extends eventemitter3_1.default {
105
108
  sync() {
106
109
  return __awaiter(this, void 0, void 0, function* () {
107
110
  try {
111
+ // T1 (Client Request Time)
108
112
  const requestedAt = Date.now();
113
+ // Fetch server time from server
109
114
  const serverNtpResult = yield this.fetchServerNTPResult(requestedAt);
115
+ // Check is null
110
116
  if (serverNtpResult === null) {
111
117
  console.warn(LOG_TAG, 'Failed to get server time');
112
118
  return null;
113
119
  }
120
+ // T2 (Server Receive Time)
114
121
  const { t2 } = serverNtpResult;
122
+ // Check is not a number
115
123
  if (isNaN(Number(t2))) {
124
+ // Not a Number
116
125
  console.error(LOG_TAG, 'invalid server time(t2), not a number', t2);
117
126
  return null;
118
127
  }
128
+ // T3 (Server Transmit Time)
119
129
  const { t3 } = serverNtpResult;
130
+ // Check is not a number
120
131
  if (isNaN(Number(t3))) {
132
+ // Not a Number
121
133
  console.error(LOG_TAG, 'invalid server time(t2), not a number', t2);
122
134
  return null;
123
135
  }
136
+ // T4 (Client Receive Time)
124
137
  const receivedAt = Date.now();
125
138
  const ntpResult = {
126
139
  t1: requestedAt,
@@ -128,8 +141,11 @@ class TimeService extends eventemitter3_1.default {
128
141
  t3: t3,
129
142
  t4: receivedAt,
130
143
  };
144
+ // Calculate offset
131
145
  const offset = TimeService.calculateNTPResultOffset(ntpResult);
146
+ // Save calculated offset
132
147
  this.setOffset(offset);
148
+ // Mark synced timestamp
133
149
  const syncedAt = Date.now();
134
150
  this.setSyncedAt(syncedAt);
135
151
  this.emit('SYNCED', offset, syncedAt);
@@ -6,6 +6,11 @@ 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
+ */
9
14
  static getGreatestObject(e, key) {
10
15
  return e.reduce((prev, current) => ((prev[key] > current[key] ? prev : current)));
11
16
  }
@@ -16,6 +16,7 @@ class AxiosUtils {
16
16
  return e;
17
17
  }
18
18
  }
19
+ // There is no any values having string type
19
20
  return null;
20
21
  }
21
22
  else {
@@ -38,6 +39,7 @@ class AxiosUtils {
38
39
  return e;
39
40
  }
40
41
  }
42
+ // There is no any values having string type
41
43
  return null;
42
44
  }
43
45
  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);
20
+ const sorted = values.slice().sort((a, b) => a - b); // O(n log n)
21
21
  const mid = len >> 1;
22
22
  return len % 2 === 0
23
23
  ? (sorted[mid - 1] + sorted[mid]) / 2
@@ -107,6 +107,7 @@ 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
110
111
  const datetime = moment_1.default.isMoment(input) ? (0, moment_1.default)(input.toDate()) : (0, moment_1.default)(input);
111
112
  if (!datetime.isValid()) {
112
113
  console.error('core-js:DateUtils.relativeDate() datetime is invalid', datetime);
@@ -19,9 +19,10 @@ class JuminNumberUtils {
19
19
  if (replacedJuminNumber.length !== 13) {
20
20
  return false;
21
21
  }
22
+ // 연도에 해당하는 숫자와 성별에 해당하는 숫자 비교
22
23
  const TODAY_YEAR = parseInt(new Date().getFullYear().toString().slice(-2), 10);
23
24
  const yearNum = parseInt(replacedJuminNumber.slice(0, 2), 10);
24
- const sexNum = replacedJuminNumber.slice(6, 7);
25
+ const sexNum = replacedJuminNumber.slice(6, 7); // 대시 있는경우 7로 변경
25
26
  if (sexNum === '1' || sexNum === '2') {
26
27
  if (yearNum < TODAY_YEAR)
27
28
  return false;
@@ -32,9 +33,11 @@ class JuminNumberUtils {
32
33
  }
33
34
  else
34
35
  return false;
36
+ // 월과 일에 해당하는 숫자 조건 검사 (정규식으로)
35
37
  const regex = /^\d{2}(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])\d{7}$/;
36
38
  if (!regex.test(replacedJuminNumber))
37
39
  return false;
40
+ // Validation X
38
41
  const currentX = parseInt(replacedJuminNumber.slice(-1), 10);
39
42
  const calculatedX = JuminNumberUtils.calculateX(replacedJuminNumber);
40
43
  if (currentX !== calculatedX) {
@@ -34,9 +34,11 @@ class Sequencer {
34
34
  this.sequences = [];
35
35
  this.status = SequencerStatus.IDLE;
36
36
  this.minimumExecutionTime = 0;
37
+ // Reset variables task is done
37
38
  this.currentSequence = null;
38
39
  this.startTimestamp = null;
39
40
  this.endTimestamp = null;
41
+ // Emitter
40
42
  this.eventEmitter = new eventemitter3_1.default();
41
43
  this.pushSequence = (sequence) => {
42
44
  this.sequences.push(sequence);
@@ -55,6 +57,7 @@ class Sequencer {
55
57
  console.log('Currently total execution time', this.executionTime);
56
58
  const sequenceStartTimeStamp = this.getCurrentTimeStamp;
57
59
  this.currentSequence = sequence;
60
+ // Emitter
58
61
  this.eventEmitter.emit(SequencerEvent.SEQUENCE_START, sequence);
59
62
  try {
60
63
  yield new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
@@ -98,6 +101,7 @@ class Sequencer {
98
101
  }
99
102
  }));
100
103
  console.log('Out of Promise');
104
+ // Emitter
101
105
  this.eventEmitter.emit(SequencerEvent.SEQUENCE_END, sequence);
102
106
  }
103
107
  catch (e) {
@@ -106,12 +110,14 @@ class Sequencer {
106
110
  this.status = SequencerStatus.ERROR;
107
111
  this.currentSequence = null;
108
112
  this.endTimestamp = this.currentSequence;
113
+ // IMPORTANT
109
114
  return Promise.reject({
110
115
  sequence,
111
116
  reason: e,
112
117
  });
113
118
  }
114
119
  console.log(`Sequence ${sequence.key} failed`, e);
120
+ // Emitter
115
121
  this.eventEmitter.emit(SequencerEvent.SEQUENCE_END, sequence);
116
122
  }
117
123
  }
@@ -28,7 +28,9 @@ 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, track[j - 1][i] + 1, track[j - 1][i - 1] + indicator);
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);
32
34
  }
33
35
  }
34
36
  return track[str2.length][str1.length];
@@ -42,12 +42,15 @@ class UuidUtils {
42
42
  }
43
43
  static format(uuid) {
44
44
  if (uuid.length === 32) {
45
+ // Without dash: ca23c587d7f84c76be59f53bbc9f91f8
45
46
  return `${uuid.substring(0, 8)}-${uuid.substring(8, 12)}-${uuid.substring(12, 16)}-${uuid.substring(16, 20)}-${uuid.substring(20, 32)}`.toLowerCase();
46
47
  }
47
48
  else if (uuid.length === 36) {
49
+ // With dash: ca23c587-d7f8-4c76-be59-f53bbc9f91f8
48
50
  return uuid.toLowerCase();
49
51
  }
50
52
  else {
53
+ // Unexpected uuid
51
54
  console.warn('Unexpected uuid length', uuid);
52
55
  return uuid;
53
56
  }
@@ -16,12 +16,14 @@ 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
+ // 최소 길이
19
20
  if (options.minLength !== undefined && options.minLength > -1) {
20
21
  validations.push(Validator.VALIDATION.MIN_LENGTH);
21
22
  if (length < options.minLength) {
22
23
  errors.push(Validator.VALIDATION.MIN_LENGTH);
23
24
  }
24
25
  }
26
+ // 최대 길이
25
27
  if (options.maxLength !== undefined && options.maxLength > -1) {
26
28
  validations.push(Validator.VALIDATION.MAX_LENGTH);
27
29
  if (length > options.maxLength) {
@@ -44,30 +46,39 @@ class Validator {
44
46
  }
45
47
  }
46
48
  };
49
+ // 공백 개수
47
50
  validateMin(options.spaceMinCount, spaceCount, Validator.VALIDATION.SPACE_MIN_COUNT);
48
51
  validateMax(options.spaceMaxCount, spaceCount, Validator.VALIDATION.SPACE_MAX_COUNT);
52
+ // 숫자 개수
49
53
  validateMin(options.numberMinCount, numberCount, Validator.VALIDATION.NUMBER_MIN_COUNT);
50
54
  validateMax(options.numberMaxCount, numberCount, Validator.VALIDATION.NUMBER_MAX_COUNT);
55
+ // 알파벳 개수
51
56
  validateMin(options.alphabetMinCount, alphabetCount, Validator.VALIDATION.ALPHABET_MIN_COUNT);
52
57
  validateMax(options.alphabetMaxCount, alphabetCount, Validator.VALIDATION.ALPHABET_MAX_COUNT);
58
+ // 알파벳(소문자) 개수
53
59
  validateMin(options.alphabetLowerCaseMinCount, alphabetLowerCaseCount, Validator.VALIDATION.ALPHABET_LOWER_CASE_MIN_COUNT);
54
60
  validateMax(options.alphabetLowerCaseMaxCount, alphabetLowerCaseCount, Validator.VALIDATION.ALPHABET_LOWER_CASE_MAX_COUNT);
61
+ // 알파벳(대문자) 개수
55
62
  validateMin(options.alphabetUpperCaseMinCount, alphabetUpperCaseCount, Validator.VALIDATION.ALPHABET_UPPER_CASE_MIN_COUNT);
56
63
  validateMax(options.alphabetUpperCaseMaxCount, alphabetUpperCaseCount, Validator.VALIDATION.ALPHABET_UPPER_CASE_MAX_COUNT);
64
+ // 특수문자 개수
57
65
  validateMin(options.specialCharacterMinCount, specialCount, Validator.VALIDATION.SPECIAL_CHARACTER_MIN_COUNT);
58
66
  validateMax(options.specialCharacterMaxCount, specialCount, Validator.VALIDATION.SPECIAL_CHARACTER_MAX_COUNT);
67
+ // 숫자로 시작
59
68
  if (options.startsWithNumber) {
60
69
  validations.push(Validator.VALIDATION.STARTS_WITH_NUMBER);
61
70
  if (!startsWithNumber) {
62
71
  errors.push(Validator.VALIDATION.STARTS_WITH_NUMBER);
63
72
  }
64
73
  }
74
+ // 영문으로 시작
65
75
  if (options.startsWithAlphabet) {
66
76
  validations.push(Validator.VALIDATION.STARTS_WITH_ALPHABET);
67
77
  if (!startsWithAlphabet) {
68
78
  errors.push(Validator.VALIDATION.STARTS_WITH_ALPHABET);
69
79
  }
70
80
  }
81
+ // 특수문자로 시작
71
82
  if (options.startsWithSpecialCharacter) {
72
83
  validations.push(Validator.VALIDATION.STARTS_WITH_SPECIAL_CHARACTER);
73
84
  if (!startsWithSpecialCharacter) {
@@ -6,6 +6,7 @@ function firstNonNullish(...args) {
6
6
  return undefined;
7
7
  }
8
8
  if (args[0] != null) {
9
+ // Not Nullish
9
10
  return args[0];
10
11
  }
11
12
  return firstNonNullish(...args.slice(1));
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ // flat.ts
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.flatten = flatten;
4
5
  exports.unflatten = unflatten;
@@ -3,12 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.pureEnum = pureEnum;
4
4
  exports.pureEnumKeys = pureEnumKeys;
5
5
  exports.pureEnumValues = pureEnumValues;
6
+ /**
7
+ * @deprecated Use Enum instead.
8
+ */
6
9
  function pureEnum(e) {
7
10
  return Object.entries(e).filter(([key, value]) => !/^-?\d+$/g.test(key) && typeof value !== 'function');
8
11
  }
12
+ /**
13
+ * @deprecated Use Enum instead.
14
+ */
9
15
  function pureEnumKeys(e) {
10
16
  return pureEnum(e).map(([key]) => key);
11
17
  }
18
+ /**
19
+ * @deprecated Use Enum instead.
20
+ */
12
21
  function pureEnumValues(e) {
13
22
  return pureEnum(e).map(([, value]) => value);
14
23
  }
@@ -10,7 +10,19 @@ 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
+ */
13
17
  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
+ */
14
26
  static function(fn, disableLogging) {
15
27
  try {
16
28
  return [
@@ -31,6 +43,14 @@ class TryCatch {
31
43
  ];
32
44
  }
33
45
  }
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
+ */
34
54
  static asyncFunction(fn, disableLogging) {
35
55
  return __awaiter(this, void 0, void 0, function* () {
36
56
  try {