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