@powfix/core-js 0.20.5 → 0.21.1

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 (213) hide show
  1. package/dist/browser/cjs/index.browser.js +3 -0
  2. package/dist/browser/cjs/shared/utils/index.js +1 -1
  3. package/dist/browser/esm/index.browser.mjs +1 -0
  4. package/dist/browser/esm/shared/utils/index.mjs +1 -1
  5. package/dist/browser/types/index.browser.d.ts +1 -0
  6. package/dist/browser/types/shared/utils/UUID.d.ts +1 -1
  7. package/dist/browser/types/shared/utils/index.d.ts +1 -0
  8. package/dist/cjs/index.js +17 -0
  9. package/dist/cjs/shared/constants/COORDINATE.js +10 -0
  10. package/dist/cjs/shared/constants/CRUD.js +22 -0
  11. package/dist/cjs/shared/constants/DATE.js +26 -0
  12. package/dist/cjs/shared/constants/DISTANCE.js +18 -0
  13. package/dist/cjs/shared/constants/DURATION.js +21 -0
  14. package/dist/cjs/shared/constants/NOT_NULL.js +4 -0
  15. package/dist/cjs/shared/constants/index.js +22 -0
  16. package/dist/cjs/shared/index.js +23 -0
  17. package/dist/cjs/shared/interfaces/Coordinate.js +2 -0
  18. package/dist/cjs/shared/interfaces/Point2.js +2 -0
  19. package/dist/cjs/shared/interfaces/Point3.js +2 -0
  20. package/dist/cjs/shared/interfaces/StorageProvider.js +2 -0
  21. package/dist/cjs/shared/interfaces/index.js +20 -0
  22. package/dist/cjs/shared/managers/SessionManager.js +134 -0
  23. package/dist/cjs/shared/managers/SessionManager.type.js +2 -0
  24. package/dist/cjs/shared/managers/index.js +18 -0
  25. package/dist/cjs/shared/scripts/base64Polyfill.js +18 -0
  26. package/dist/cjs/shared/scripts/index.js +17 -0
  27. package/dist/cjs/shared/services/index.js +17 -0
  28. package/dist/cjs/shared/services/time/TimeService.js +180 -0
  29. package/dist/cjs/shared/services/time/TimeService.type.js +2 -0
  30. package/dist/cjs/shared/services/time/index.js +18 -0
  31. package/dist/cjs/shared/types/IntRage.js +2 -0
  32. package/dist/cjs/shared/types/PartialExcept.js +2 -0
  33. package/dist/cjs/shared/types/index.js +18 -0
  34. package/dist/cjs/shared/utils/ArrayUtils.js +30 -0
  35. package/dist/cjs/shared/utils/AxiosUtils.js +53 -0
  36. package/dist/cjs/shared/utils/BooleanUtils.js +8 -0
  37. package/dist/cjs/shared/utils/Calc.js +27 -0
  38. package/dist/cjs/shared/utils/CoordinateUtils.js +42 -0
  39. package/dist/cjs/shared/utils/DateUtils.js +310 -0
  40. package/dist/cjs/shared/utils/Enum.js +36 -0
  41. package/dist/cjs/shared/utils/Enum.types.js +2 -0
  42. package/dist/cjs/shared/utils/I18nUtils.js +13 -0
  43. package/dist/cjs/shared/utils/JuminNumberUtils.js +50 -0
  44. package/dist/cjs/shared/utils/NumberUtils.js +25 -0
  45. package/dist/cjs/shared/utils/ObjectIdUtils.js +30 -0
  46. package/dist/cjs/shared/utils/Point3Utils.js +12 -0
  47. package/dist/cjs/shared/utils/RandomUtils.js +64 -0
  48. package/dist/cjs/shared/utils/Sequencer.js +148 -0
  49. package/dist/cjs/shared/utils/StringUtils.js +37 -0
  50. package/dist/cjs/shared/utils/UUID.js +320 -0
  51. package/dist/cjs/shared/utils/UUID.types.js +2 -0
  52. package/dist/cjs/shared/utils/Uint8ArrayUtils.js +13 -0
  53. package/dist/cjs/shared/utils/UuidUtils.js +77 -0
  54. package/dist/cjs/shared/utils/Validator.js +118 -0
  55. package/dist/cjs/shared/utils/global/atob.js +9 -0
  56. package/dist/cjs/shared/utils/global/base64.js +25 -0
  57. package/dist/cjs/shared/utils/global/between.js +7 -0
  58. package/dist/cjs/shared/utils/global/btoa.js +9 -0
  59. package/dist/cjs/shared/utils/global/castArray.js +6 -0
  60. package/dist/cjs/shared/utils/global/circularDistance.js +14 -0
  61. package/dist/cjs/shared/utils/global/fallbackIfMatch.js +9 -0
  62. package/dist/cjs/shared/utils/global/fallbackIfNull.js +7 -0
  63. package/dist/cjs/shared/utils/global/fallbackIfNullish.js +9 -0
  64. package/dist/cjs/shared/utils/global/fallbackIfUndefined.js +7 -0
  65. package/dist/cjs/shared/utils/global/firstNonNullish.js +13 -0
  66. package/dist/cjs/shared/utils/global/flat.js +117 -0
  67. package/dist/cjs/shared/utils/global/index.js +31 -0
  68. package/dist/cjs/shared/utils/global/processFirstNonNullish.js +11 -0
  69. package/dist/cjs/shared/utils/global/pureEnum.js +23 -0
  70. package/dist/cjs/shared/utils/global/sleep.js +5 -0
  71. package/dist/cjs/shared/utils/index.js +39 -0
  72. package/dist/cjs/shared/utils/try-catch/TryCatch.js +78 -0
  73. package/dist/cjs/shared/utils/try-catch/index.js +17 -0
  74. package/dist/esm/index.mjs +1 -0
  75. package/dist/esm/shared/constants/COORDINATE.mjs +6 -0
  76. package/dist/esm/shared/constants/CRUD.mjs +19 -0
  77. package/dist/esm/shared/constants/DATE.mjs +22 -0
  78. package/dist/esm/shared/constants/DISTANCE.mjs +14 -0
  79. package/dist/esm/shared/constants/DURATION.mjs +17 -0
  80. package/dist/esm/shared/constants/NOT_NULL.mjs +1 -0
  81. package/dist/esm/shared/constants/index.mjs +6 -0
  82. package/dist/esm/shared/index.mjs +7 -0
  83. package/dist/esm/shared/interfaces/Coordinate.mjs +1 -0
  84. package/dist/esm/shared/interfaces/Point2.mjs +1 -0
  85. package/dist/esm/shared/interfaces/Point3.mjs +1 -0
  86. package/dist/esm/shared/interfaces/StorageProvider.mjs +1 -0
  87. package/dist/esm/shared/interfaces/index.mjs +4 -0
  88. package/dist/esm/shared/managers/SessionManager.mjs +127 -0
  89. package/dist/esm/shared/managers/SessionManager.type.mjs +1 -0
  90. package/dist/esm/shared/managers/index.mjs +2 -0
  91. package/dist/esm/shared/scripts/base64Polyfill.mjs +11 -0
  92. package/dist/esm/shared/scripts/index.mjs +1 -0
  93. package/dist/esm/shared/services/index.mjs +1 -0
  94. package/dist/esm/shared/services/time/TimeService.mjs +173 -0
  95. package/dist/esm/shared/services/time/TimeService.type.mjs +1 -0
  96. package/dist/esm/shared/services/time/index.mjs +2 -0
  97. package/dist/esm/shared/types/IntRage.mjs +1 -0
  98. package/dist/esm/shared/types/PartialExcept.mjs +1 -0
  99. package/dist/esm/shared/types/index.mjs +2 -0
  100. package/dist/esm/shared/utils/ArrayUtils.mjs +26 -0
  101. package/dist/esm/shared/utils/AxiosUtils.mjs +49 -0
  102. package/dist/esm/shared/utils/BooleanUtils.mjs +5 -0
  103. package/dist/esm/shared/utils/Calc.mjs +23 -0
  104. package/dist/esm/shared/utils/CoordinateUtils.mjs +38 -0
  105. package/dist/esm/shared/utils/DateUtils.mjs +303 -0
  106. package/dist/esm/shared/utils/Enum.mjs +32 -0
  107. package/dist/esm/shared/utils/Enum.types.mjs +1 -0
  108. package/dist/esm/shared/utils/I18nUtils.mjs +6 -0
  109. package/dist/esm/shared/utils/JuminNumberUtils.mjs +46 -0
  110. package/dist/esm/shared/utils/NumberUtils.mjs +21 -0
  111. package/dist/esm/shared/utils/ObjectIdUtils.mjs +26 -0
  112. package/dist/esm/shared/utils/Point3Utils.mjs +8 -0
  113. package/dist/esm/shared/utils/RandomUtils.mjs +60 -0
  114. package/dist/esm/shared/utils/Sequencer.mjs +141 -0
  115. package/dist/esm/shared/utils/StringUtils.mjs +33 -0
  116. package/dist/esm/shared/utils/UUID.mjs +316 -0
  117. package/dist/esm/shared/utils/UUID.types.mjs +1 -0
  118. package/dist/esm/shared/utils/Uint8ArrayUtils.mjs +9 -0
  119. package/dist/esm/shared/utils/UuidUtils.mjs +40 -0
  120. package/dist/esm/shared/utils/Validator.mjs +114 -0
  121. package/dist/esm/shared/utils/global/atob.mjs +3 -0
  122. package/dist/esm/shared/utils/global/base64.mjs +21 -0
  123. package/dist/esm/shared/utils/global/between.mjs +3 -0
  124. package/dist/esm/shared/utils/global/btoa.mjs +3 -0
  125. package/dist/esm/shared/utils/global/castArray.mjs +3 -0
  126. package/dist/esm/shared/utils/global/circularDistance.mjs +11 -0
  127. package/dist/esm/shared/utils/global/fallbackIfMatch.mjs +6 -0
  128. package/dist/esm/shared/utils/global/fallbackIfNull.mjs +4 -0
  129. package/dist/esm/shared/utils/global/fallbackIfNullish.mjs +6 -0
  130. package/dist/esm/shared/utils/global/fallbackIfUndefined.mjs +4 -0
  131. package/dist/esm/shared/utils/global/firstNonNullish.mjs +10 -0
  132. package/dist/esm/shared/utils/global/flat.mjs +113 -0
  133. package/dist/esm/shared/utils/global/index.mjs +15 -0
  134. package/dist/esm/shared/utils/global/processFirstNonNullish.mjs +8 -0
  135. package/dist/esm/shared/utils/global/pureEnum.mjs +18 -0
  136. package/dist/esm/shared/utils/global/sleep.mjs +1 -0
  137. package/dist/esm/shared/utils/index.mjs +23 -0
  138. package/dist/esm/shared/utils/try-catch/TryCatch.mjs +74 -0
  139. package/dist/esm/shared/utils/try-catch/index.mjs +1 -0
  140. package/dist/node/cjs/index.nodejs.js +3 -0
  141. package/dist/node/cjs/shared/utils/index.js +1 -1
  142. package/dist/node/esm/index.nodejs.mjs +1 -0
  143. package/dist/node/esm/shared/utils/index.mjs +1 -1
  144. package/dist/node/types/index.nodejs.d.ts +1 -0
  145. package/dist/node/types/shared/utils/UUID.d.ts +1 -1
  146. package/dist/node/types/shared/utils/index.d.ts +1 -0
  147. package/dist/types/index.d.ts +1 -0
  148. package/dist/types/shared/constants/COORDINATE.d.ts +7 -0
  149. package/dist/types/shared/constants/CRUD.d.ts +9 -0
  150. package/dist/types/shared/constants/DATE.d.ts +13 -0
  151. package/dist/types/shared/constants/DISTANCE.d.ts +13 -0
  152. package/dist/types/shared/constants/DURATION.d.ts +16 -0
  153. package/dist/types/shared/constants/NOT_NULL.d.ts +1 -0
  154. package/dist/types/shared/constants/index.d.ts +6 -0
  155. package/dist/types/shared/index.d.ts +7 -0
  156. package/dist/types/shared/interfaces/Coordinate.d.ts +8 -0
  157. package/dist/types/shared/interfaces/Point2.d.ts +4 -0
  158. package/dist/types/shared/interfaces/Point3.d.ts +4 -0
  159. package/dist/types/shared/interfaces/StorageProvider.d.ts +7 -0
  160. package/dist/types/shared/interfaces/index.d.ts +4 -0
  161. package/dist/types/shared/managers/SessionManager.d.ts +15 -0
  162. package/dist/types/shared/managers/SessionManager.type.d.ts +9 -0
  163. package/dist/types/shared/managers/index.d.ts +2 -0
  164. package/dist/types/shared/scripts/base64Polyfill.d.ts +1 -0
  165. package/dist/types/shared/scripts/index.d.ts +1 -0
  166. package/dist/types/shared/services/index.d.ts +1 -0
  167. package/dist/types/shared/services/time/TimeService.d.ts +31 -0
  168. package/dist/types/shared/services/time/TimeService.type.d.ts +21 -0
  169. package/dist/types/shared/services/time/index.d.ts +2 -0
  170. package/dist/types/shared/types/IntRage.d.ts +3 -0
  171. package/dist/types/shared/types/PartialExcept.d.ts +1 -0
  172. package/dist/types/shared/types/index.d.ts +2 -0
  173. package/dist/types/shared/utils/ArrayUtils.d.ts +12 -0
  174. package/dist/types/shared/utils/AxiosUtils.d.ts +5 -0
  175. package/dist/types/shared/utils/BooleanUtils.d.ts +1 -0
  176. package/dist/types/shared/utils/Calc.d.ts +4 -0
  177. package/dist/types/shared/utils/CoordinateUtils.d.ts +8 -0
  178. package/dist/types/shared/utils/DateUtils.d.ts +24 -0
  179. package/dist/types/shared/utils/Enum.d.ts +16 -0
  180. package/dist/types/shared/utils/Enum.types.d.ts +6 -0
  181. package/dist/types/shared/utils/I18nUtils.d.ts +4 -0
  182. package/dist/types/shared/utils/JuminNumberUtils.d.ts +4 -0
  183. package/dist/types/shared/utils/NumberUtils.d.ts +4 -0
  184. package/dist/types/shared/utils/ObjectIdUtils.d.ts +4 -0
  185. package/dist/types/shared/utils/Point3Utils.d.ts +4 -0
  186. package/dist/types/shared/utils/RandomUtils.d.ts +8 -0
  187. package/dist/types/shared/utils/Sequencer.d.ts +38 -0
  188. package/dist/types/shared/utils/StringUtils.d.ts +5 -0
  189. package/dist/types/shared/utils/UUID.d.ts +147 -0
  190. package/dist/types/shared/utils/UUID.types.d.ts +2 -0
  191. package/dist/types/shared/utils/Uint8ArrayUtils.d.ts +4 -0
  192. package/dist/types/shared/utils/UuidUtils.d.ts +14 -0
  193. package/dist/types/shared/utils/Validator.d.ts +48 -0
  194. package/dist/types/shared/utils/global/atob.d.ts +2 -0
  195. package/dist/types/shared/utils/global/base64.d.ts +2 -0
  196. package/dist/types/shared/utils/global/between.d.ts +1 -0
  197. package/dist/types/shared/utils/global/btoa.d.ts +2 -0
  198. package/dist/types/shared/utils/global/castArray.d.ts +1 -0
  199. package/dist/types/shared/utils/global/circularDistance.d.ts +1 -0
  200. package/dist/types/shared/utils/global/fallbackIfMatch.d.ts +1 -0
  201. package/dist/types/shared/utils/global/fallbackIfNull.d.ts +1 -0
  202. package/dist/types/shared/utils/global/fallbackIfNullish.d.ts +1 -0
  203. package/dist/types/shared/utils/global/fallbackIfUndefined.d.ts +1 -0
  204. package/dist/types/shared/utils/global/firstNonNullish.d.ts +1 -0
  205. package/dist/types/shared/utils/global/flat.d.ts +14 -0
  206. package/dist/types/shared/utils/global/index.d.ts +15 -0
  207. package/dist/types/shared/utils/global/processFirstNonNullish.d.ts +1 -0
  208. package/dist/types/shared/utils/global/pureEnum.d.ts +17 -0
  209. package/dist/types/shared/utils/global/sleep.d.ts +1 -0
  210. package/dist/types/shared/utils/index.d.ts +23 -0
  211. package/dist/types/shared/utils/try-catch/TryCatch.d.ts +24 -0
  212. package/dist/types/shared/utils/try-catch/index.d.ts +1 -0
  213. package/package.json +10 -4
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.TimeService = void 0;
16
+ const eventemitter3_1 = __importDefault(require("eventemitter3"));
17
+ const LOG_TAG = 'TimeService';
18
+ class TimeService extends eventemitter3_1.default {
19
+ static calculateNTPResultOffset(ntpResult) {
20
+ const { t1, t2, t3, t4 } = ntpResult;
21
+ return ((t2 - t1) + (t3 - t4)) / 2;
22
+ }
23
+ constructor(options) {
24
+ super();
25
+ // Options
26
+ this.syncInterval = options === null || options === void 0 ? void 0 : options.syncInterval;
27
+ this.clientTimeProvider = options === null || options === void 0 ? void 0 : options.clientTimeProvider;
28
+ this.serverTimeProvider = options === null || options === void 0 ? void 0 : options.serverTimeProvider;
29
+ // Bind
30
+ this.sync = this.sync.bind(this);
31
+ this.fetchServerNTPResult = this.fetchServerNTPResult.bind(this);
32
+ }
33
+ getOffset(defaultValue) {
34
+ if (this.offset !== undefined) {
35
+ return this.offset;
36
+ }
37
+ if (defaultValue !== undefined) {
38
+ return defaultValue;
39
+ }
40
+ return undefined;
41
+ }
42
+ setOffset(offset) {
43
+ return this.offset = offset;
44
+ }
45
+ getSyncedAt() {
46
+ return this.syncedAt;
47
+ }
48
+ setSyncedAt(syncedAt) {
49
+ return (this.syncedAt = syncedAt);
50
+ }
51
+ getSyncInterval() {
52
+ return this.syncInterval;
53
+ }
54
+ setSyncInterval(interval) {
55
+ this.syncInterval = interval;
56
+ // Emit
57
+ this.emit('SYNC_INTERVAL_CHANGED', interval);
58
+ if (this.syncHandler !== undefined) {
59
+ this.stopSync();
60
+ this.startSync();
61
+ }
62
+ }
63
+ getClientTimeProvider() {
64
+ return this.clientTimeProvider;
65
+ }
66
+ setClientTimeProvider(provider) {
67
+ this.clientTimeProvider = provider !== null && provider !== void 0 ? provider : undefined;
68
+ }
69
+ getClientTime() {
70
+ var _a;
71
+ return (_a = this.getClientTimeProvider()) === null || _a === void 0 ? void 0 : _a();
72
+ }
73
+ getServerTimeProvider() {
74
+ return this.serverTimeProvider;
75
+ }
76
+ setServerTimeProvider(provider) {
77
+ this.serverTimeProvider = provider !== null && provider !== void 0 ? provider : undefined;
78
+ }
79
+ getServerTime() {
80
+ const offset = this.getOffset();
81
+ if (offset == null) {
82
+ return offset;
83
+ }
84
+ const clientTime = this.getClientTime();
85
+ if (clientTime == null) {
86
+ return clientTime;
87
+ }
88
+ return clientTime + offset;
89
+ }
90
+ getTime() {
91
+ var _a, _b;
92
+ return (_b = (_a = this.getServerTime()) !== null && _a !== void 0 ? _a : this.getClientTime()) !== null && _b !== void 0 ? _b : Date.now();
93
+ }
94
+ fetchServerNTPResult(t1) {
95
+ return __awaiter(this, void 0, void 0, function* () {
96
+ try {
97
+ const provider = this.getServerTimeProvider();
98
+ if (typeof provider === 'function') {
99
+ return yield provider(t1);
100
+ }
101
+ }
102
+ catch (e) {
103
+ console.error(e);
104
+ }
105
+ return null;
106
+ });
107
+ }
108
+ sync() {
109
+ return __awaiter(this, void 0, void 0, function* () {
110
+ try {
111
+ // T1 (Client Request Time)
112
+ const requestedAt = Date.now();
113
+ // Fetch server time from server
114
+ const serverNtpResult = yield this.fetchServerNTPResult(requestedAt);
115
+ // Check is null
116
+ if (serverNtpResult === null) {
117
+ console.warn(LOG_TAG, 'Failed to get server time');
118
+ return null;
119
+ }
120
+ // T2 (Server Receive Time)
121
+ const { t2 } = serverNtpResult;
122
+ // Check is not a number
123
+ if (isNaN(Number(t2))) {
124
+ // Not a Number
125
+ console.error(LOG_TAG, 'invalid server time(t2), not a number', t2);
126
+ return null;
127
+ }
128
+ // T3 (Server Transmit Time)
129
+ const { t3 } = serverNtpResult;
130
+ // Check is not a number
131
+ if (isNaN(Number(t3))) {
132
+ // Not a Number
133
+ console.error(LOG_TAG, 'invalid server time(t2), not a number', t2);
134
+ return null;
135
+ }
136
+ // T4 (Client Receive Time)
137
+ const receivedAt = Date.now();
138
+ const ntpResult = {
139
+ t1: requestedAt,
140
+ t2: t2,
141
+ t3: t3,
142
+ t4: receivedAt,
143
+ };
144
+ // Calculate offset
145
+ const offset = TimeService.calculateNTPResultOffset(ntpResult);
146
+ // Save calculated offset
147
+ this.setOffset(offset);
148
+ // Mark synced timestamp
149
+ const syncedAt = Date.now();
150
+ this.setSyncedAt(syncedAt);
151
+ this.emit('SYNCED', offset, syncedAt);
152
+ }
153
+ catch (e) {
154
+ console.error(e);
155
+ }
156
+ return null;
157
+ });
158
+ }
159
+ startSync() {
160
+ if (this.syncHandler != null) {
161
+ console.warn('sync is already started');
162
+ return;
163
+ }
164
+ const syncInterval = this.getSyncInterval();
165
+ if (syncInterval == null || syncInterval <= 0) {
166
+ console.warn('sync is not started', 'syncInterval', syncInterval);
167
+ return;
168
+ }
169
+ this.syncHandler = setInterval(this.sync.bind(this), syncInterval);
170
+ }
171
+ ;
172
+ stopSync() {
173
+ if (this.syncHandler != null) {
174
+ clearInterval(this.syncHandler);
175
+ this.syncHandler = undefined;
176
+ }
177
+ }
178
+ ;
179
+ }
180
+ exports.TimeService = TimeService;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./TimeService"), exports);
18
+ __exportStar(require("./TimeService.type"), exports);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./IntRage"), exports);
18
+ __exportStar(require("./PartialExcept"), exports);
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ArrayUtils = void 0;
4
+ const global_1 = require("./global");
5
+ class ArrayUtils {
6
+ static castArray(value) {
7
+ return (0, global_1.castArray)(value);
8
+ }
9
+ /**
10
+ * 객체를 요소로 가지는 배열에서 가장 큰 값(Property)를 가지는 객체를 반환한다
11
+ * @param e 객체 배열
12
+ * @param key 값을 비교할 Property 키
13
+ */
14
+ static getGreatestObject(e, key) {
15
+ return e.reduce((prev, current) => ((prev[key] > current[key] ? prev : current)));
16
+ }
17
+ static removeDuplicate(arr) {
18
+ return [...new Set(arr)];
19
+ }
20
+ static removeObjectDuplicate(arr, key) {
21
+ return arr.filter((v, i, self) => (i === self.findIndex(e => (e[key] === v[key]))));
22
+ }
23
+ static allValuesEqual(...values) {
24
+ if (values.length === 0) {
25
+ return true;
26
+ }
27
+ return values.every((value) => value === values[0]);
28
+ }
29
+ }
30
+ exports.ArrayUtils = ArrayUtils;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AxiosUtils = void 0;
4
+ class AxiosUtils {
5
+ static headerValue2String(value) {
6
+ if (value === undefined) {
7
+ return null;
8
+ }
9
+ if (value === null || typeof value === 'string') {
10
+ return value;
11
+ }
12
+ if (Array.isArray(value)) {
13
+ if (value.length > 0) {
14
+ for (const e of value) {
15
+ if (typeof e === 'string') {
16
+ return e;
17
+ }
18
+ }
19
+ // There is no any values having string type
20
+ return null;
21
+ }
22
+ else {
23
+ return null;
24
+ }
25
+ }
26
+ return String(value);
27
+ }
28
+ static headerValue2Number(value) {
29
+ if (value === undefined) {
30
+ return null;
31
+ }
32
+ if (value === null || typeof value === 'number') {
33
+ return value;
34
+ }
35
+ if (Array.isArray(value)) {
36
+ if (value.length > 0) {
37
+ for (const e of value) {
38
+ if (typeof e === 'number') {
39
+ return e;
40
+ }
41
+ }
42
+ // There is no any values having string type
43
+ return null;
44
+ }
45
+ else {
46
+ return null;
47
+ }
48
+ }
49
+ const result = Number(value);
50
+ return isNaN(result) ? null : result;
51
+ }
52
+ }
53
+ exports.AxiosUtils = AxiosUtils;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseBoolean = parseBoolean;
4
+ function parseBoolean(value, defaultValue) {
5
+ if (value === undefined || value === null)
6
+ return defaultValue;
7
+ return (value === 'true' || value === true) || (value === 1 || value === '1');
8
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Calc = void 0;
4
+ class Calc {
5
+ static average(...values) {
6
+ const length = values.length;
7
+ if (length === 0) {
8
+ return NaN;
9
+ }
10
+ let sum = 0;
11
+ for (let i = 0; i < length; ++i) {
12
+ sum += values[i];
13
+ }
14
+ return sum / length;
15
+ }
16
+ static median(...values) {
17
+ const len = values.length;
18
+ if (len === 0)
19
+ return NaN;
20
+ const sorted = values.slice().sort((a, b) => a - b); // O(n log n)
21
+ const mid = len >> 1;
22
+ return len % 2 === 0
23
+ ? (sorted[mid - 1] + sorted[mid]) / 2
24
+ : sorted[mid];
25
+ }
26
+ }
27
+ exports.Calc = Calc;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CoordinateUtils = void 0;
4
+ class CoordinateUtils {
5
+ static isValidLatitude(latitude) {
6
+ return /^-?([0-8]?[0-9]|90)(\.[0-9]{1,15})$/.test(latitude.toString());
7
+ }
8
+ static isValidLongitude(longitude) {
9
+ return /^-?([0-9]{1,2}|1[0-7][0-9]|180)(\.[0-9]{1,14})$/.test(longitude.toString());
10
+ }
11
+ static isValidLatitudeLongitude(latitude, longitude) {
12
+ return CoordinateUtils.isValidLatitude(latitude) && CoordinateUtils.isValidLongitude(longitude);
13
+ }
14
+ static isValidCoordinate(coordinate) {
15
+ return this.isValidLatitudeLongitude(coordinate.latitude, coordinate.longitude);
16
+ }
17
+ static crowDistance(...coordinates) {
18
+ if (coordinates.length <= 2) {
19
+ const toRad = (value) => value * Math.PI / 180;
20
+ const c1 = coordinates[0];
21
+ const c2 = coordinates[1];
22
+ if (!c1 || !c2) {
23
+ return 0;
24
+ }
25
+ const R = 6371e3;
26
+ const dLat = toRad(c2.latitude - c1.latitude);
27
+ const dLon = toRad(c2.longitude - c1.longitude);
28
+ const lat1 = toRad(c1.latitude);
29
+ const lat2 = toRad(c2.latitude);
30
+ const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
31
+ Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2);
32
+ const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
33
+ return R * c;
34
+ }
35
+ let totalDistance = 0;
36
+ for (let i = 0; i < coordinates.length - 1; ++i) {
37
+ totalDistance += this.crowDistance(coordinates[i], coordinates[i + 1]);
38
+ }
39
+ return totalDistance;
40
+ }
41
+ }
42
+ exports.CoordinateUtils = CoordinateUtils;