@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
@@ -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 {
@@ -1,5 +1,39 @@
1
- import { Uint8ArrayUtils } from "../../shared/utils/Uint8ArrayUtils.mjs";
1
+ import { Uint8ArrayUtils } from "../../shared/index.mjs";
2
2
  export class UUID {
3
+ static isValidHex(hex) {
4
+ if (typeof hex !== 'string') {
5
+ return false;
6
+ }
7
+ return UUID.REGEX_HEX.test(hex);
8
+ }
9
+ static isValidString(str) {
10
+ if (typeof str !== 'string') {
11
+ return false;
12
+ }
13
+ return UUID.REGEX_RFC4122.test(str);
14
+ }
15
+ static isValidBytes(bytes) {
16
+ return bytes.byteLength === UUID.BYTE_LENGTH;
17
+ }
18
+ static isValid(input) {
19
+ if (typeof input === 'string') {
20
+ const length = input.length;
21
+ switch (length) {
22
+ case UUID.STR_LENGTH:
23
+ return UUID.isValidString(input);
24
+ case UUID.HEX_STR_LENGTH:
25
+ return UUID.isValidHex(input);
26
+ default:
27
+ return false;
28
+ }
29
+ }
30
+ else if (ArrayBuffer.isView(input)) {
31
+ return UUID.isValidBytes(input);
32
+ }
33
+ else {
34
+ return false;
35
+ }
36
+ }
3
37
  static formatHex(hex) {
4
38
  if (hex.length !== UUID.HEX_STR_LENGTH) {
5
39
  throw new Error(`hex length should be ${UUID.HEX_STR_LENGTH}`);
@@ -13,34 +47,74 @@ export class UUID {
13
47
  static stripHyphens(str) {
14
48
  return str.replace(/-/g, "");
15
49
  }
50
+ static parseHex(hex) {
51
+ if (hex.length !== UUID.HEX_STR_LENGTH) {
52
+ throw new Error(`Invalid hex string, length should be ${UUID.HEX_STR_LENGTH}`);
53
+ }
54
+ return Uint8ArrayUtils.fromHex(hex);
55
+ }
16
56
  static parseString(str) {
57
+ if (str.length !== UUID.STR_LENGTH) {
58
+ throw new Error(`Invalid UUID string, invalid character length should be ${UUID.STR_LENGTH}`);
59
+ }
60
+ if (!UUID.isValid(str)) {
61
+ throw new Error('Invalid UUID string, should be RFC 4122 format');
62
+ }
17
63
  const hex = UUID.stripHyphens(str);
18
64
  if (hex.length !== UUID.HEX_STR_LENGTH) {
19
- throw new Error('Invalid UUID string');
65
+ throw new Error('Invalid UUID string, invalid character length after strip hyphens');
20
66
  }
21
67
  return Uint8ArrayUtils.fromHex(hex);
22
68
  }
69
+ static parseBytes(bytes) {
70
+ const view = new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
71
+ if (view.length !== UUID.BYTE_LENGTH) {
72
+ throw new Error(`Expected ${UUID.BYTE_LENGTH} bytes`);
73
+ }
74
+ return new Uint8Array(view);
75
+ }
76
+ static fromHex(hex) {
77
+ return new UUID(UUID.parseHex(hex));
78
+ }
23
79
  static fromString(str) {
24
- return new UUID(str);
80
+ return new UUID(UUID.parseString(str));
25
81
  }
26
- static parseBytes(bytes) {
27
- if (bytes instanceof Uint8Array) {
28
- return new Uint8Array(bytes);
82
+ static fromBytes(bytes) {
83
+ return new UUID(UUID.parseBytes(bytes));
84
+ }
85
+ static parse(input) {
86
+ if (typeof input === 'string') {
87
+ const length = input.length;
88
+ switch (length) {
89
+ case UUID.STR_LENGTH:
90
+ return UUID.parseString(input);
91
+ case UUID.HEX_STR_LENGTH:
92
+ return UUID.parseHex(input);
93
+ default:
94
+ throw new Error(`Invalid input string, length should be ${UUID.STR_LENGTH} or ${UUID.HEX_STR_LENGTH}`);
95
+ }
96
+ }
97
+ else if (ArrayBuffer.isView(input)) {
98
+ return UUID.parseBytes(input);
29
99
  }
30
100
  else {
31
- return new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
101
+ throw new Error("Invalid input, Expected string or ArrayBufferView");
32
102
  }
33
103
  }
34
- static fromBytes(bytes) {
35
- return new UUID(UUID.parseBytes(bytes));
104
+ static from(input) {
105
+ return UUID.fromBytes(UUID.parse(input));
36
106
  }
37
107
  static nil() {
38
- return new UUID(new Uint8Array(UUID.BYTE_LENGTH));
108
+ return UUID.fromBytes(new Uint8Array(UUID.BYTE_LENGTH));
109
+ }
110
+ static max() {
111
+ return UUID.fromBytes((new Uint8Array(UUID.BYTE_LENGTH)).fill(0xFF));
39
112
  }
40
113
  static equals(...uuids) {
41
114
  const n = uuids.length;
42
- if (n <= 1)
43
- return true;
115
+ if (n < 2) {
116
+ throw new Error('At least two UUIDs required for comparison');
117
+ }
44
118
  const ref = uuids[0].bytes;
45
119
  for (let i = 1; i < n; ++i) {
46
120
  const b = uuids[i].bytes;
@@ -61,21 +135,7 @@ export class UUID {
61
135
  return 0;
62
136
  }
63
137
  constructor(input) {
64
- if (input == null) {
65
- throw new Error('Input cannot be null');
66
- }
67
- if (typeof input === 'string') {
68
- this.bytes = UUID.parseString(input);
69
- }
70
- else if (ArrayBuffer.isView(input)) {
71
- this.bytes = UUID.parseBytes(input);
72
- }
73
- else {
74
- throw new Error("Expected string or ArrayBufferView");
75
- }
76
- if (this.bytes.byteLength !== UUID.BYTE_LENGTH) {
77
- throw new Error(`UUID must be ${UUID.BYTE_LENGTH} bytes`);
78
- }
138
+ this.bytes = UUID.parse(input);
79
139
  }
80
140
  equals(...uuids) {
81
141
  return UUID.equals(this, ...uuids);
@@ -88,13 +148,15 @@ export class UUID {
88
148
  return this._str;
89
149
  }
90
150
  const hex = this.toHex();
91
- return UUID.formatHex(hex);
151
+ this._str = UUID.formatHex(hex);
152
+ return this._str;
92
153
  }
93
154
  toHex() {
94
155
  if (this._hex != null) {
95
156
  return this._hex;
96
157
  }
97
- return Uint8ArrayUtils.toHex(this.bytes);
158
+ this._hex = Uint8ArrayUtils.toHex(this.bytes);
159
+ return this._hex;
98
160
  }
99
161
  toBytes() {
100
162
  return new Uint8Array(this.bytes);
@@ -103,5 +165,8 @@ export class UUID {
103
165
  return this.toString();
104
166
  }
105
167
  }
168
+ 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}$/;
169
+ 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}$/;
106
170
  UUID.BYTE_LENGTH = 16;
171
+ UUID.STR_LENGTH = 36;
107
172
  UUID.HEX_STR_LENGTH = 32;
@@ -12,10 +12,8 @@ import { TransactionManagerLogLevel, TransactionManagerTimeoutAction } from "../
12
12
  const LOG_TAG = '[TransactionManager]';
13
13
  export class TransactionManager {
14
14
  constructor() {
15
- // Members
16
15
  this.logLevel = TransactionManagerLogLevel.VERBOSE;
17
16
  this.transactionTimeoutMap = new Map();
18
- // Emitter
19
17
  this.emitter = new EventEmitter();
20
18
  if (this.logLevel <= TransactionManagerLogLevel.VERBOSE) {
21
19
  console.log(LOG_TAG, 'TransactionManager instance initialized');
@@ -55,7 +53,6 @@ export class TransactionManager {
55
53
  handler,
56
54
  action,
57
55
  });
58
- // Callback
59
56
  transaction.afterCommit(this.afterCommit.bind(this));
60
57
  }
61
58
  remove(transaction) {
@@ -30,7 +30,6 @@ export class RedisClient {
30
30
  start() {
31
31
  return __awaiter(this, void 0, void 0, function* () {
32
32
  console.log(LOG_PREFIX, 'trying to start');
33
- // register event callback
34
33
  this.client.on('connect', this.handleOnConnect);
35
34
  this.client.on('error', this.handleOnError);
36
35
  console.log('before connect');
@@ -44,7 +43,6 @@ export class RedisClient {
44
43
  stop() {
45
44
  return __awaiter(this, void 0, void 0, function* () {
46
45
  console.log(LOG_PREFIX, 'trying to stop');
47
- // unregister event callback
48
46
  this.client.off('connect', this.handleOnConnect);
49
47
  this.client.off('error', this.handleOnError);
50
48
  if (this.client.isOpen) {
@@ -37,7 +37,6 @@ export class RedisPublisher extends RedisClient {
37
37
  getLogging() {
38
38
  return this.logging;
39
39
  }
40
- // Make public method
41
40
  publish(channel, data) {
42
41
  return __awaiter(this, void 0, void 0, function* () {
43
42
  const stringifyData = typeof data !== 'string' ? JSON.stringify(data) : data;
@@ -1,4 +1,3 @@
1
- // Files
2
1
  export * from './RedisClient.mjs';
3
2
  export * from './RedisPublisher.mjs';
4
3
  export * from './RedisSubscriber.mjs';
@@ -1,3 +1,6 @@
1
1
  import { UUID as BaseUUID } from "../../browser/utils/UUID.mjs";
2
2
  export class UUID extends BaseUUID {
3
+ toBuffer() {
4
+ return Buffer.from(this.bytes);
5
+ }
3
6
  }
@@ -13,10 +13,8 @@ import EventEmitter from 'eventemitter3';
13
13
  export class SessionManager extends EventEmitter {
14
14
  constructor(options) {
15
15
  super();
16
- // Init service parameters
17
16
  this.api = options.api;
18
17
  this.storageProvider = options.storageProvider;
19
- // Logging
20
18
  console.log('SessionManager initialized', Date.now(), options.api);
21
19
  }
22
20
  get key() {
@@ -57,7 +55,6 @@ export class SessionManager extends EventEmitter {
57
55
  return null;
58
56
  }
59
57
  try {
60
- // Replace Bearer prefix
61
58
  nextAuthorization = nextAuthorization.replace(/^Bearer\s+/, '');
62
59
  const decoded = jwtDecode(nextAuthorization);
63
60
  if (!decoded) {
@@ -98,13 +95,9 @@ export class SessionManager extends EventEmitter {
98
95
  return [decoded.exp, exp.format(), exp.diff(Date.now(), 'days'), 'days left'];
99
96
  })());
100
97
  })();
101
- // AsyncStorage 에 토큰 저장
102
98
  yield this.storageProvider.set(this.key, nextAuthorization);
103
- // API Instance header 설정
104
99
  this.api.defaults.headers.common.Authorization = `Bearer ${nextAuthorization}`;
105
- // Emit
106
100
  this.emit('AUTHORIZATION_CHANGED', nextAuthorization);
107
- // Return
108
101
  return nextAuthorization;
109
102
  }
110
103
  catch (e) {
@@ -115,11 +108,8 @@ export class SessionManager extends EventEmitter {
115
108
  }
116
109
  removeAuthorization() {
117
110
  return __awaiter(this, void 0, void 0, function* () {
118
- // API Instance header 에서 토큰 제거
119
111
  delete this.api.defaults.headers.common.Authorization;
120
- // 스토리지에서 authorization 제거
121
112
  yield this.storageProvider.remove(this.key);
122
- // Emit
123
113
  this.emit('AUTHORIZATION_CHANGED', null);
124
114
  });
125
115
  }
@@ -16,11 +16,9 @@ export class TimeService extends EventEmitter {
16
16
  }
17
17
  constructor(options) {
18
18
  super();
19
- // Options
20
19
  this.syncInterval = options === null || options === void 0 ? void 0 : options.syncInterval;
21
20
  this.clientTimeProvider = options === null || options === void 0 ? void 0 : options.clientTimeProvider;
22
21
  this.serverTimeProvider = options === null || options === void 0 ? void 0 : options.serverTimeProvider;
23
- // Bind
24
22
  this.sync = this.sync.bind(this);
25
23
  this.fetchServerNTPResult = this.fetchServerNTPResult.bind(this);
26
24
  }
@@ -47,7 +45,6 @@ export class TimeService extends EventEmitter {
47
45
  }
48
46
  setSyncInterval(interval) {
49
47
  this.syncInterval = interval;
50
- // Emit
51
48
  this.emit('SYNC_INTERVAL_CHANGED', interval);
52
49
  if (this.syncHandler !== undefined) {
53
50
  this.stopSync();
@@ -102,32 +99,22 @@ export class TimeService extends EventEmitter {
102
99
  sync() {
103
100
  return __awaiter(this, void 0, void 0, function* () {
104
101
  try {
105
- // T1 (Client Request Time)
106
102
  const requestedAt = Date.now();
107
- // Fetch server time from server
108
103
  const serverNtpResult = yield this.fetchServerNTPResult(requestedAt);
109
- // Check is null
110
104
  if (serverNtpResult === null) {
111
105
  console.warn(LOG_TAG, 'Failed to get server time');
112
106
  return null;
113
107
  }
114
- // T2 (Server Receive Time)
115
108
  const { t2 } = serverNtpResult;
116
- // Check is not a number
117
109
  if (isNaN(Number(t2))) {
118
- // Not a Number
119
110
  console.error(LOG_TAG, 'invalid server time(t2), not a number', t2);
120
111
  return null;
121
112
  }
122
- // T3 (Server Transmit Time)
123
113
  const { t3 } = serverNtpResult;
124
- // Check is not a number
125
114
  if (isNaN(Number(t3))) {
126
- // Not a Number
127
115
  console.error(LOG_TAG, 'invalid server time(t2), not a number', t2);
128
116
  return null;
129
117
  }
130
- // T4 (Client Receive Time)
131
118
  const receivedAt = Date.now();
132
119
  const ntpResult = {
133
120
  t1: requestedAt,
@@ -135,11 +122,8 @@ export class TimeService extends EventEmitter {
135
122
  t3: t3,
136
123
  t4: receivedAt,
137
124
  };
138
- // Calculate offset
139
125
  const offset = TimeService.calculateNTPResultOffset(ntpResult);
140
- // Save calculated offset
141
126
  this.setOffset(offset);
142
- // Mark synced timestamp
143
127
  const syncedAt = Date.now();
144
128
  this.setSyncedAt(syncedAt);
145
129
  this.emit('SYNCED', offset, syncedAt);
@@ -3,11 +3,6 @@ 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
- */
11
6
  static getGreatestObject(e, key) {
12
7
  return e.reduce((prev, current) => ((prev[key] > current[key] ? prev : current)));
13
8
  }
@@ -13,7 +13,6 @@ export class AxiosUtils {
13
13
  return e;
14
14
  }
15
15
  }
16
- // There is no any values having string type
17
16
  return null;
18
17
  }
19
18
  else {
@@ -36,7 +35,6 @@ export class AxiosUtils {
36
35
  return e;
37
36
  }
38
37
  }
39
- // There is no any values having string type
40
38
  return null;
41
39
  }
42
40
  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); // O(n log n)
17
+ const sorted = values.slice().sort((a, b) => a - b);
18
18
  const mid = len >> 1;
19
19
  return len % 2 === 0
20
20
  ? (sorted[mid - 1] + sorted[mid]) / 2
@@ -100,7 +100,6 @@ export class DateUtils {
100
100
  }
101
101
  }
102
102
  DateUtils.relativeDate = (input, base = Date.now()) => {
103
- // Create new moment instance to apply new locale
104
103
  const datetime = moment.isMoment(input) ? moment(input.toDate()) : moment(input);
105
104
  if (!datetime.isValid()) {
106
105
  console.error('core-js:DateUtils.relativeDate() datetime is invalid', datetime);
@@ -0,0 +1,32 @@
1
+ export class Enum {
2
+ static entries(e) {
3
+ return Object.entries(e).filter(([key, value]) => !/^-?\d+$/g.test(key) && typeof value !== 'function');
4
+ }
5
+ static keys(e) {
6
+ return Enum.entries(e).map(([key,]) => key);
7
+ }
8
+ static values(e) {
9
+ return Enum.entries(e).map(([, value]) => value);
10
+ }
11
+ static from(e) {
12
+ return new Enum(e);
13
+ }
14
+ constructor(e) {
15
+ this._e = e;
16
+ this._entries = Enum.entries(e);
17
+ this._keys = Enum.keys(e);
18
+ this._values = Enum.values(e);
19
+ }
20
+ value() {
21
+ return this._e;
22
+ }
23
+ entries() {
24
+ return this._entries;
25
+ }
26
+ keys() {
27
+ return this._keys;
28
+ }
29
+ values() {
30
+ return this._values;
31
+ }
32
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -16,10 +16,9 @@ export class JuminNumberUtils {
16
16
  if (replacedJuminNumber.length !== 13) {
17
17
  return false;
18
18
  }
19
- // 연도에 해당하는 숫자와 성별에 해당하는 숫자 비교
20
19
  const TODAY_YEAR = parseInt(new Date().getFullYear().toString().slice(-2), 10);
21
20
  const yearNum = parseInt(replacedJuminNumber.slice(0, 2), 10);
22
- const sexNum = replacedJuminNumber.slice(6, 7); // 대시 있는경우 7로 변경
21
+ const sexNum = replacedJuminNumber.slice(6, 7);
23
22
  if (sexNum === '1' || sexNum === '2') {
24
23
  if (yearNum < TODAY_YEAR)
25
24
  return false;
@@ -30,11 +29,9 @@ export class JuminNumberUtils {
30
29
  }
31
30
  else
32
31
  return false;
33
- // 월과 일에 해당하는 숫자 조건 검사 (정규식으로)
34
32
  const regex = /^\d{2}(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])\d{7}$/;
35
33
  if (!regex.test(replacedJuminNumber))
36
34
  return false;
37
- // Validation X
38
35
  const currentX = parseInt(replacedJuminNumber.slice(-1), 10);
39
36
  const calculatedX = JuminNumberUtils.calculateX(replacedJuminNumber);
40
37
  if (currentX !== calculatedX) {
@@ -28,11 +28,9 @@ export class Sequencer {
28
28
  this.sequences = [];
29
29
  this.status = SequencerStatus.IDLE;
30
30
  this.minimumExecutionTime = 0;
31
- // Reset variables task is done
32
31
  this.currentSequence = null;
33
32
  this.startTimestamp = null;
34
33
  this.endTimestamp = null;
35
- // Emitter
36
34
  this.eventEmitter = new EventEmitter3();
37
35
  this.pushSequence = (sequence) => {
38
36
  this.sequences.push(sequence);
@@ -51,7 +49,6 @@ export class Sequencer {
51
49
  console.log('Currently total execution time', this.executionTime);
52
50
  const sequenceStartTimeStamp = this.getCurrentTimeStamp;
53
51
  this.currentSequence = sequence;
54
- // Emitter
55
52
  this.eventEmitter.emit(SequencerEvent.SEQUENCE_START, sequence);
56
53
  try {
57
54
  yield new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
@@ -95,7 +92,6 @@ export class Sequencer {
95
92
  }
96
93
  }));
97
94
  console.log('Out of Promise');
98
- // Emitter
99
95
  this.eventEmitter.emit(SequencerEvent.SEQUENCE_END, sequence);
100
96
  }
101
97
  catch (e) {
@@ -104,14 +100,12 @@ export class Sequencer {
104
100
  this.status = SequencerStatus.ERROR;
105
101
  this.currentSequence = null;
106
102
  this.endTimestamp = this.currentSequence;
107
- // IMPORTANT
108
103
  return Promise.reject({
109
104
  sequence,
110
105
  reason: e,
111
106
  });
112
107
  }
113
108
  console.log(`Sequence ${sequence.key} failed`, e);
114
- // Emitter
115
109
  this.eventEmitter.emit(SequencerEvent.SEQUENCE_END, sequence);
116
110
  }
117
111
  }
@@ -24,9 +24,7 @@ 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, // deletion
28
- track[j - 1][i] + 1, // insertion
29
- track[j - 1][i - 1] + indicator);
27
+ track[j][i] = Math.min(track[j][i - 1] + 1, track[j - 1][i] + 1, track[j - 1][i - 1] + indicator);
30
28
  }
31
29
  }
32
30
  return track[str2.length][str1.length];
@@ -6,15 +6,12 @@ export class UuidUtils {
6
6
  }
7
7
  static format(uuid) {
8
8
  if (uuid.length === 32) {
9
- // Without dash: ca23c587d7f84c76be59f53bbc9f91f8
10
9
  return `${uuid.substring(0, 8)}-${uuid.substring(8, 12)}-${uuid.substring(12, 16)}-${uuid.substring(16, 20)}-${uuid.substring(20, 32)}`.toLowerCase();
11
10
  }
12
11
  else if (uuid.length === 36) {
13
- // With dash: ca23c587-d7f8-4c76-be59-f53bbc9f91f8
14
12
  return uuid.toLowerCase();
15
13
  }
16
14
  else {
17
- // Unexpected uuid
18
15
  console.warn('Unexpected uuid length', uuid);
19
16
  return uuid;
20
17
  }
@@ -13,14 +13,12 @@ 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
- // 최소 길이
17
16
  if (options.minLength !== undefined && options.minLength > -1) {
18
17
  validations.push(Validator.VALIDATION.MIN_LENGTH);
19
18
  if (length < options.minLength) {
20
19
  errors.push(Validator.VALIDATION.MIN_LENGTH);
21
20
  }
22
21
  }
23
- // 최대 길이
24
22
  if (options.maxLength !== undefined && options.maxLength > -1) {
25
23
  validations.push(Validator.VALIDATION.MAX_LENGTH);
26
24
  if (length > options.maxLength) {
@@ -43,39 +41,30 @@ export class Validator {
43
41
  }
44
42
  }
45
43
  };
46
- // 공백 개수
47
44
  validateMin(options.spaceMinCount, spaceCount, Validator.VALIDATION.SPACE_MIN_COUNT);
48
45
  validateMax(options.spaceMaxCount, spaceCount, Validator.VALIDATION.SPACE_MAX_COUNT);
49
- // 숫자 개수
50
46
  validateMin(options.numberMinCount, numberCount, Validator.VALIDATION.NUMBER_MIN_COUNT);
51
47
  validateMax(options.numberMaxCount, numberCount, Validator.VALIDATION.NUMBER_MAX_COUNT);
52
- // 알파벳 개수
53
48
  validateMin(options.alphabetMinCount, alphabetCount, Validator.VALIDATION.ALPHABET_MIN_COUNT);
54
49
  validateMax(options.alphabetMaxCount, alphabetCount, Validator.VALIDATION.ALPHABET_MAX_COUNT);
55
- // 알파벳(소문자) 개수
56
50
  validateMin(options.alphabetLowerCaseMinCount, alphabetLowerCaseCount, Validator.VALIDATION.ALPHABET_LOWER_CASE_MIN_COUNT);
57
51
  validateMax(options.alphabetLowerCaseMaxCount, alphabetLowerCaseCount, Validator.VALIDATION.ALPHABET_LOWER_CASE_MAX_COUNT);
58
- // 알파벳(대문자) 개수
59
52
  validateMin(options.alphabetUpperCaseMinCount, alphabetUpperCaseCount, Validator.VALIDATION.ALPHABET_UPPER_CASE_MIN_COUNT);
60
53
  validateMax(options.alphabetUpperCaseMaxCount, alphabetUpperCaseCount, Validator.VALIDATION.ALPHABET_UPPER_CASE_MAX_COUNT);
61
- // 특수문자 개수
62
54
  validateMin(options.specialCharacterMinCount, specialCount, Validator.VALIDATION.SPECIAL_CHARACTER_MIN_COUNT);
63
55
  validateMax(options.specialCharacterMaxCount, specialCount, Validator.VALIDATION.SPECIAL_CHARACTER_MAX_COUNT);
64
- // 숫자로 시작
65
56
  if (options.startsWithNumber) {
66
57
  validations.push(Validator.VALIDATION.STARTS_WITH_NUMBER);
67
58
  if (!startsWithNumber) {
68
59
  errors.push(Validator.VALIDATION.STARTS_WITH_NUMBER);
69
60
  }
70
61
  }
71
- // 영문으로 시작
72
62
  if (options.startsWithAlphabet) {
73
63
  validations.push(Validator.VALIDATION.STARTS_WITH_ALPHABET);
74
64
  if (!startsWithAlphabet) {
75
65
  errors.push(Validator.VALIDATION.STARTS_WITH_ALPHABET);
76
66
  }
77
67
  }
78
- // 특수문자로 시작
79
68
  if (options.startsWithSpecialCharacter) {
80
69
  validations.push(Validator.VALIDATION.STARTS_WITH_SPECIAL_CHARACTER);
81
70
  if (!startsWithSpecialCharacter) {
@@ -3,7 +3,6 @@ export function firstNonNullish(...args) {
3
3
  return undefined;
4
4
  }
5
5
  if (args[0] != null) {
6
- // Not Nullish
7
6
  return args[0];
8
7
  }
9
8
  return firstNonNullish(...args.slice(1));
@@ -1,4 +1,3 @@
1
- // flat.ts
2
1
  function isBuffer(obj) {
3
2
  return !!(obj &&
4
3
  obj.constructor &&
@@ -8,6 +8,8 @@ export * from './BooleanUtils.mjs';
8
8
  export * from './Calc.mjs';
9
9
  export * from './CoordinateUtils.mjs';
10
10
  export * from './DateUtils.mjs';
11
+ export * from './Enum.mjs';
12
+ export * from './Enum.types.mjs';
11
13
  export * from './I18nUtils.mjs';
12
14
  export * from './NumberUtils.mjs';
13
15
  export * from './ObjectIdUtils.mjs';