@powfix/core-js 0.20.5 → 0.21.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.
- package/dist/browser/cjs/index.browser.js +3 -0
- package/dist/browser/cjs/shared/utils/index.js +1 -1
- package/dist/browser/esm/index.browser.mjs +1 -0
- package/dist/browser/esm/shared/utils/index.mjs +1 -1
- package/dist/browser/types/index.browser.d.ts +1 -0
- package/dist/browser/types/shared/utils/index.d.ts +1 -0
- package/dist/cjs/index.js +17 -0
- package/dist/cjs/shared/constants/COORDINATE.js +10 -0
- package/dist/cjs/shared/constants/CRUD.js +22 -0
- package/dist/cjs/shared/constants/DATE.js +26 -0
- package/dist/cjs/shared/constants/DISTANCE.js +18 -0
- package/dist/cjs/shared/constants/DURATION.js +21 -0
- package/dist/cjs/shared/constants/NOT_NULL.js +4 -0
- package/dist/cjs/shared/constants/index.js +22 -0
- package/dist/cjs/shared/index.js +23 -0
- package/dist/cjs/shared/interfaces/Coordinate.js +2 -0
- package/dist/cjs/shared/interfaces/Point2.js +2 -0
- package/dist/cjs/shared/interfaces/Point3.js +2 -0
- package/dist/cjs/shared/interfaces/StorageProvider.js +2 -0
- package/dist/cjs/shared/interfaces/index.js +20 -0
- package/dist/cjs/shared/managers/SessionManager.js +134 -0
- package/dist/cjs/shared/managers/SessionManager.type.js +2 -0
- package/dist/cjs/shared/managers/index.js +18 -0
- package/dist/cjs/shared/scripts/base64Polyfill.js +18 -0
- package/dist/cjs/shared/scripts/index.js +17 -0
- package/dist/cjs/shared/services/index.js +17 -0
- package/dist/cjs/shared/services/time/TimeService.js +180 -0
- package/dist/cjs/shared/services/time/TimeService.type.js +2 -0
- package/dist/cjs/shared/services/time/index.js +18 -0
- package/dist/cjs/shared/types/IntRage.js +2 -0
- package/dist/cjs/shared/types/PartialExcept.js +2 -0
- package/dist/cjs/shared/types/index.js +18 -0
- package/dist/cjs/shared/utils/ArrayUtils.js +30 -0
- package/dist/cjs/shared/utils/AxiosUtils.js +53 -0
- package/dist/cjs/shared/utils/BooleanUtils.js +8 -0
- package/dist/cjs/shared/utils/Calc.js +27 -0
- package/dist/cjs/shared/utils/CoordinateUtils.js +42 -0
- package/dist/cjs/shared/utils/DateUtils.js +310 -0
- package/dist/cjs/shared/utils/Enum.js +36 -0
- package/dist/cjs/shared/utils/Enum.types.js +2 -0
- package/dist/cjs/shared/utils/I18nUtils.js +13 -0
- package/dist/cjs/shared/utils/JuminNumberUtils.js +50 -0
- package/dist/cjs/shared/utils/NumberUtils.js +25 -0
- package/dist/cjs/shared/utils/ObjectIdUtils.js +30 -0
- package/dist/cjs/shared/utils/Point3Utils.js +12 -0
- package/dist/cjs/shared/utils/RandomUtils.js +64 -0
- package/dist/cjs/shared/utils/Sequencer.js +148 -0
- package/dist/cjs/shared/utils/StringUtils.js +37 -0
- package/dist/cjs/shared/utils/UUID.js +320 -0
- package/dist/cjs/shared/utils/UUID.types.js +2 -0
- package/dist/cjs/shared/utils/Uint8ArrayUtils.js +13 -0
- package/dist/cjs/shared/utils/UuidUtils.js +77 -0
- package/dist/cjs/shared/utils/Validator.js +118 -0
- package/dist/cjs/shared/utils/global/atob.js +9 -0
- package/dist/cjs/shared/utils/global/base64.js +25 -0
- package/dist/cjs/shared/utils/global/between.js +7 -0
- package/dist/cjs/shared/utils/global/btoa.js +9 -0
- package/dist/cjs/shared/utils/global/castArray.js +6 -0
- package/dist/cjs/shared/utils/global/circularDistance.js +14 -0
- package/dist/cjs/shared/utils/global/fallbackIfMatch.js +9 -0
- package/dist/cjs/shared/utils/global/fallbackIfNull.js +7 -0
- package/dist/cjs/shared/utils/global/fallbackIfNullish.js +9 -0
- package/dist/cjs/shared/utils/global/fallbackIfUndefined.js +7 -0
- package/dist/cjs/shared/utils/global/firstNonNullish.js +13 -0
- package/dist/cjs/shared/utils/global/flat.js +117 -0
- package/dist/cjs/shared/utils/global/index.js +31 -0
- package/dist/cjs/shared/utils/global/processFirstNonNullish.js +11 -0
- package/dist/cjs/shared/utils/global/pureEnum.js +23 -0
- package/dist/cjs/shared/utils/global/sleep.js +5 -0
- package/dist/cjs/shared/utils/index.js +39 -0
- package/dist/cjs/shared/utils/try-catch/TryCatch.js +78 -0
- package/dist/cjs/shared/utils/try-catch/index.js +17 -0
- package/dist/esm/index.mjs +1 -0
- package/dist/esm/shared/constants/COORDINATE.mjs +6 -0
- package/dist/esm/shared/constants/CRUD.mjs +19 -0
- package/dist/esm/shared/constants/DATE.mjs +22 -0
- package/dist/esm/shared/constants/DISTANCE.mjs +14 -0
- package/dist/esm/shared/constants/DURATION.mjs +17 -0
- package/dist/esm/shared/constants/NOT_NULL.mjs +1 -0
- package/dist/esm/shared/constants/index.mjs +6 -0
- package/dist/esm/shared/index.mjs +7 -0
- package/dist/esm/shared/interfaces/Coordinate.mjs +1 -0
- package/dist/esm/shared/interfaces/Point2.mjs +1 -0
- package/dist/esm/shared/interfaces/Point3.mjs +1 -0
- package/dist/esm/shared/interfaces/StorageProvider.mjs +1 -0
- package/dist/esm/shared/interfaces/index.mjs +4 -0
- package/dist/esm/shared/managers/SessionManager.mjs +127 -0
- package/dist/esm/shared/managers/SessionManager.type.mjs +1 -0
- package/dist/esm/shared/managers/index.mjs +2 -0
- package/dist/esm/shared/scripts/base64Polyfill.mjs +11 -0
- package/dist/esm/shared/scripts/index.mjs +1 -0
- package/dist/esm/shared/services/index.mjs +1 -0
- package/dist/esm/shared/services/time/TimeService.mjs +173 -0
- package/dist/esm/shared/services/time/TimeService.type.mjs +1 -0
- package/dist/esm/shared/services/time/index.mjs +2 -0
- package/dist/esm/shared/types/IntRage.mjs +1 -0
- package/dist/esm/shared/types/PartialExcept.mjs +1 -0
- package/dist/esm/shared/types/index.mjs +2 -0
- package/dist/esm/shared/utils/ArrayUtils.mjs +26 -0
- package/dist/esm/shared/utils/AxiosUtils.mjs +49 -0
- package/dist/esm/shared/utils/BooleanUtils.mjs +5 -0
- package/dist/esm/shared/utils/Calc.mjs +23 -0
- package/dist/esm/shared/utils/CoordinateUtils.mjs +38 -0
- package/dist/esm/shared/utils/DateUtils.mjs +303 -0
- package/dist/esm/shared/utils/Enum.mjs +32 -0
- package/dist/esm/shared/utils/Enum.types.mjs +1 -0
- package/dist/esm/shared/utils/I18nUtils.mjs +6 -0
- package/dist/esm/shared/utils/JuminNumberUtils.mjs +46 -0
- package/dist/esm/shared/utils/NumberUtils.mjs +21 -0
- package/dist/esm/shared/utils/ObjectIdUtils.mjs +26 -0
- package/dist/esm/shared/utils/Point3Utils.mjs +8 -0
- package/dist/esm/shared/utils/RandomUtils.mjs +60 -0
- package/dist/esm/shared/utils/Sequencer.mjs +141 -0
- package/dist/esm/shared/utils/StringUtils.mjs +33 -0
- package/dist/esm/shared/utils/UUID.mjs +316 -0
- package/dist/esm/shared/utils/UUID.types.mjs +1 -0
- package/dist/esm/shared/utils/Uint8ArrayUtils.mjs +9 -0
- package/dist/esm/shared/utils/UuidUtils.mjs +40 -0
- package/dist/esm/shared/utils/Validator.mjs +114 -0
- package/dist/esm/shared/utils/global/atob.mjs +3 -0
- package/dist/esm/shared/utils/global/base64.mjs +21 -0
- package/dist/esm/shared/utils/global/between.mjs +3 -0
- package/dist/esm/shared/utils/global/btoa.mjs +3 -0
- package/dist/esm/shared/utils/global/castArray.mjs +3 -0
- package/dist/esm/shared/utils/global/circularDistance.mjs +11 -0
- package/dist/esm/shared/utils/global/fallbackIfMatch.mjs +6 -0
- package/dist/esm/shared/utils/global/fallbackIfNull.mjs +4 -0
- package/dist/esm/shared/utils/global/fallbackIfNullish.mjs +6 -0
- package/dist/esm/shared/utils/global/fallbackIfUndefined.mjs +4 -0
- package/dist/esm/shared/utils/global/firstNonNullish.mjs +10 -0
- package/dist/esm/shared/utils/global/flat.mjs +113 -0
- package/dist/esm/shared/utils/global/index.mjs +15 -0
- package/dist/esm/shared/utils/global/processFirstNonNullish.mjs +8 -0
- package/dist/esm/shared/utils/global/pureEnum.mjs +18 -0
- package/dist/esm/shared/utils/global/sleep.mjs +1 -0
- package/dist/esm/shared/utils/index.mjs +23 -0
- package/dist/esm/shared/utils/try-catch/TryCatch.mjs +74 -0
- package/dist/esm/shared/utils/try-catch/index.mjs +1 -0
- package/dist/node/cjs/index.nodejs.js +3 -0
- package/dist/node/cjs/shared/utils/index.js +1 -1
- package/dist/node/esm/index.nodejs.mjs +1 -0
- package/dist/node/esm/shared/utils/index.mjs +1 -1
- package/dist/node/types/index.nodejs.d.ts +1 -0
- package/dist/node/types/shared/utils/index.d.ts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/shared/constants/COORDINATE.d.ts +7 -0
- package/dist/types/shared/constants/CRUD.d.ts +9 -0
- package/dist/types/shared/constants/DATE.d.ts +13 -0
- package/dist/types/shared/constants/DISTANCE.d.ts +13 -0
- package/dist/types/shared/constants/DURATION.d.ts +16 -0
- package/dist/types/shared/constants/NOT_NULL.d.ts +1 -0
- package/dist/types/shared/constants/index.d.ts +6 -0
- package/dist/types/shared/index.d.ts +7 -0
- package/dist/types/shared/interfaces/Coordinate.d.ts +8 -0
- package/dist/types/shared/interfaces/Point2.d.ts +4 -0
- package/dist/types/shared/interfaces/Point3.d.ts +4 -0
- package/dist/types/shared/interfaces/StorageProvider.d.ts +7 -0
- package/dist/types/shared/interfaces/index.d.ts +4 -0
- package/dist/types/shared/managers/SessionManager.d.ts +15 -0
- package/dist/types/shared/managers/SessionManager.type.d.ts +9 -0
- package/dist/types/shared/managers/index.d.ts +2 -0
- package/dist/types/shared/scripts/base64Polyfill.d.ts +1 -0
- package/dist/types/shared/scripts/index.d.ts +1 -0
- package/dist/types/shared/services/index.d.ts +1 -0
- package/dist/types/shared/services/time/TimeService.d.ts +31 -0
- package/dist/types/shared/services/time/TimeService.type.d.ts +21 -0
- package/dist/types/shared/services/time/index.d.ts +2 -0
- package/dist/types/shared/types/IntRage.d.ts +3 -0
- package/dist/types/shared/types/PartialExcept.d.ts +1 -0
- package/dist/types/shared/types/index.d.ts +2 -0
- package/dist/types/shared/utils/ArrayUtils.d.ts +12 -0
- package/dist/types/shared/utils/AxiosUtils.d.ts +5 -0
- package/dist/types/shared/utils/BooleanUtils.d.ts +1 -0
- package/dist/types/shared/utils/Calc.d.ts +4 -0
- package/dist/types/shared/utils/CoordinateUtils.d.ts +8 -0
- package/dist/types/shared/utils/DateUtils.d.ts +24 -0
- package/dist/types/shared/utils/Enum.d.ts +16 -0
- package/dist/types/shared/utils/Enum.types.d.ts +6 -0
- package/dist/types/shared/utils/I18nUtils.d.ts +4 -0
- package/dist/types/shared/utils/JuminNumberUtils.d.ts +4 -0
- package/dist/types/shared/utils/NumberUtils.d.ts +4 -0
- package/dist/types/shared/utils/ObjectIdUtils.d.ts +4 -0
- package/dist/types/shared/utils/Point3Utils.d.ts +4 -0
- package/dist/types/shared/utils/RandomUtils.d.ts +8 -0
- package/dist/types/shared/utils/Sequencer.d.ts +38 -0
- package/dist/types/shared/utils/StringUtils.d.ts +5 -0
- package/dist/types/shared/utils/UUID.d.ts +147 -0
- package/dist/types/shared/utils/UUID.types.d.ts +2 -0
- package/dist/types/shared/utils/Uint8ArrayUtils.d.ts +4 -0
- package/dist/types/shared/utils/UuidUtils.d.ts +14 -0
- package/dist/types/shared/utils/Validator.d.ts +48 -0
- package/dist/types/shared/utils/global/atob.d.ts +2 -0
- package/dist/types/shared/utils/global/base64.d.ts +2 -0
- package/dist/types/shared/utils/global/between.d.ts +1 -0
- package/dist/types/shared/utils/global/btoa.d.ts +2 -0
- package/dist/types/shared/utils/global/castArray.d.ts +1 -0
- package/dist/types/shared/utils/global/circularDistance.d.ts +1 -0
- package/dist/types/shared/utils/global/fallbackIfMatch.d.ts +1 -0
- package/dist/types/shared/utils/global/fallbackIfNull.d.ts +1 -0
- package/dist/types/shared/utils/global/fallbackIfNullish.d.ts +1 -0
- package/dist/types/shared/utils/global/fallbackIfUndefined.d.ts +1 -0
- package/dist/types/shared/utils/global/firstNonNullish.d.ts +1 -0
- package/dist/types/shared/utils/global/flat.d.ts +14 -0
- package/dist/types/shared/utils/global/index.d.ts +15 -0
- package/dist/types/shared/utils/global/processFirstNonNullish.d.ts +1 -0
- package/dist/types/shared/utils/global/pureEnum.d.ts +17 -0
- package/dist/types/shared/utils/global/sleep.d.ts +1 -0
- package/dist/types/shared/utils/index.d.ts +23 -0
- package/dist/types/shared/utils/try-catch/TryCatch.d.ts +24 -0
- package/dist/types/shared/utils/try-catch/index.d.ts +1 -0
- package/package.json +10 -4
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ObjectIdUtils = void 0;
|
|
4
|
+
const UuidUtils_1 = require("./UuidUtils");
|
|
5
|
+
const Uint8ArrayUtils_1 = require("./Uint8ArrayUtils");
|
|
6
|
+
class ObjectIdUtils {
|
|
7
|
+
static toUuid(objectId, pad = 'start') {
|
|
8
|
+
const src = Uint8ArrayUtils_1.Uint8ArrayUtils.fromHex(objectId);
|
|
9
|
+
if (src.length !== 12) {
|
|
10
|
+
throw new Error(`objectId must be 12 bytes (24 hex), got ${src.length} bytes`);
|
|
11
|
+
}
|
|
12
|
+
const result = new Uint8Array(16);
|
|
13
|
+
const offset = pad === 'start' ? 4 : 0;
|
|
14
|
+
result.set(src, offset);
|
|
15
|
+
return UuidUtils_1.UuidUtils.toString(result);
|
|
16
|
+
}
|
|
17
|
+
static fromUuid(uuid, pad) {
|
|
18
|
+
const buffer = UuidUtils_1.UuidUtils.toBuffer(uuid);
|
|
19
|
+
const isPadEnd = buffer.subarray(buffer.length - 4).every(byte => byte === 0);
|
|
20
|
+
if (isPadEnd || pad === 'end') {
|
|
21
|
+
return buffer.subarray(0, buffer.length - 4).toString('hex');
|
|
22
|
+
}
|
|
23
|
+
const isPadStart = buffer.subarray(0, 4).every(byte => byte === 0);
|
|
24
|
+
if (!isPadStart) {
|
|
25
|
+
console.warn('buffer is not pad start and pad end');
|
|
26
|
+
}
|
|
27
|
+
return buffer.subarray(4).toString('hex');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.ObjectIdUtils = ObjectIdUtils;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Point3Utils = void 0;
|
|
4
|
+
class Point3Utils {
|
|
5
|
+
static distance(p1, p2) {
|
|
6
|
+
const dx = p1.x - p2.x;
|
|
7
|
+
const dy = p1.y - p2.y;
|
|
8
|
+
const dz = p1.z - p2.z;
|
|
9
|
+
return Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.Point3Utils = Point3Utils;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RandomUtils = void 0;
|
|
4
|
+
class RandomUtils {
|
|
5
|
+
static randomNumber(min, max) {
|
|
6
|
+
min = Math.ceil(min);
|
|
7
|
+
max = Math.floor(max);
|
|
8
|
+
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
9
|
+
}
|
|
10
|
+
static randomLatinStrings(length) {
|
|
11
|
+
const strings = [];
|
|
12
|
+
for (let i = 0; i < length; ++i) {
|
|
13
|
+
const isLowerCase = RandomUtils.randomNumber(0, 1);
|
|
14
|
+
if (isLowerCase) {
|
|
15
|
+
strings.push(String.fromCharCode(RandomUtils.randomNumber(97, 122)));
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
strings.push(String.fromCharCode(RandomUtils.randomNumber(65, 90)));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return strings.join('');
|
|
22
|
+
}
|
|
23
|
+
static randomLatinLowercaseStrings(length) {
|
|
24
|
+
const strings = [];
|
|
25
|
+
for (let i = 0; i < length; ++i) {
|
|
26
|
+
strings.push(String.fromCharCode(RandomUtils.randomNumber(97, 122)));
|
|
27
|
+
}
|
|
28
|
+
return strings.join('');
|
|
29
|
+
}
|
|
30
|
+
static randomLatinUppercaseStrings(length) {
|
|
31
|
+
const strings = [];
|
|
32
|
+
for (let i = 0; i < length; ++i) {
|
|
33
|
+
strings.push(String.fromCharCode(RandomUtils.randomNumber(65, 90)));
|
|
34
|
+
}
|
|
35
|
+
return strings.join('');
|
|
36
|
+
}
|
|
37
|
+
static randomNumberStrings(length) {
|
|
38
|
+
const strings = [];
|
|
39
|
+
for (let i = 0; i < length; ++i) {
|
|
40
|
+
strings.push(String.fromCharCode(RandomUtils.randomNumber(48, 57)));
|
|
41
|
+
}
|
|
42
|
+
return strings.join('');
|
|
43
|
+
}
|
|
44
|
+
static randomStrings(length) {
|
|
45
|
+
const strings = [];
|
|
46
|
+
for (let i = 0; i < length; ++i) {
|
|
47
|
+
const isNumber = RandomUtils.randomNumber(0, 1);
|
|
48
|
+
if (isNumber) {
|
|
49
|
+
strings.push(String.fromCharCode(RandomUtils.randomNumber(48, 57)));
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
const isLowerCase = RandomUtils.randomNumber(0, 1);
|
|
53
|
+
if (isLowerCase) {
|
|
54
|
+
strings.push(String.fromCharCode(RandomUtils.randomNumber(97, 122)));
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
strings.push(String.fromCharCode(RandomUtils.randomNumber(65, 90)));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return strings.join('');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.RandomUtils = RandomUtils;
|
|
@@ -0,0 +1,148 @@
|
|
|
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.Sequencer = exports.SequencerEvent = exports.SequencerStatus = void 0;
|
|
16
|
+
const moment_1 = __importDefault(require("moment"));
|
|
17
|
+
const eventemitter3_1 = __importDefault(require("eventemitter3"));
|
|
18
|
+
var SequencerStatus;
|
|
19
|
+
(function (SequencerStatus) {
|
|
20
|
+
SequencerStatus[SequencerStatus["IDLE"] = 0] = "IDLE";
|
|
21
|
+
SequencerStatus[SequencerStatus["RUNNING"] = 1] = "RUNNING";
|
|
22
|
+
SequencerStatus[SequencerStatus["ERROR"] = 2] = "ERROR";
|
|
23
|
+
SequencerStatus[SequencerStatus["DONE"] = 3] = "DONE";
|
|
24
|
+
})(SequencerStatus || (exports.SequencerStatus = SequencerStatus = {}));
|
|
25
|
+
var SequencerEvent;
|
|
26
|
+
(function (SequencerEvent) {
|
|
27
|
+
SequencerEvent["START"] = "START";
|
|
28
|
+
SequencerEvent["END"] = "END";
|
|
29
|
+
SequencerEvent["SEQUENCE_START"] = "SEQUENCE_START";
|
|
30
|
+
SequencerEvent["SEQUENCE_END"] = "SEQUENCE_END";
|
|
31
|
+
})(SequencerEvent || (exports.SequencerEvent = SequencerEvent = {}));
|
|
32
|
+
class Sequencer {
|
|
33
|
+
constructor(option) {
|
|
34
|
+
this.sequences = [];
|
|
35
|
+
this.status = SequencerStatus.IDLE;
|
|
36
|
+
this.minimumExecutionTime = 0;
|
|
37
|
+
// Reset variables task is done
|
|
38
|
+
this.currentSequence = null;
|
|
39
|
+
this.startTimestamp = null;
|
|
40
|
+
this.endTimestamp = null;
|
|
41
|
+
// Emitter
|
|
42
|
+
this.eventEmitter = new eventemitter3_1.default();
|
|
43
|
+
this.pushSequence = (sequence) => {
|
|
44
|
+
this.sequences.push(sequence);
|
|
45
|
+
};
|
|
46
|
+
this.start = () => __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
if (this.status === SequencerStatus.RUNNING) {
|
|
48
|
+
console.warn('Sequencer status is', this.status);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
this.status = SequencerStatus.RUNNING;
|
|
52
|
+
this.currentSequence = null;
|
|
53
|
+
this.startTimestamp = this.getCurrentTimeStamp;
|
|
54
|
+
this.endTimestamp = null;
|
|
55
|
+
console.log(`Sequence started, started at ${this.startTimestamp}, MINIMUM_EXECUTION_TIME is ${this.minimumExecutionTime}`);
|
|
56
|
+
for (let sequence of this.sequences) {
|
|
57
|
+
console.log('Currently total execution time', this.executionTime);
|
|
58
|
+
const sequenceStartTimeStamp = this.getCurrentTimeStamp;
|
|
59
|
+
this.currentSequence = sequence;
|
|
60
|
+
// Emitter
|
|
61
|
+
this.eventEmitter.emit(SequencerEvent.SEQUENCE_START, sequence);
|
|
62
|
+
try {
|
|
63
|
+
yield new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
var _a;
|
|
65
|
+
try {
|
|
66
|
+
console.log(`Sequence ${sequence.key} start`);
|
|
67
|
+
yield ((_a = sequence.task) === null || _a === void 0 ? void 0 : _a.call(sequence));
|
|
68
|
+
const sequenceEndTimeStamp = this.getCurrentTimeStamp;
|
|
69
|
+
const sequenceExecutionTime = sequenceEndTimeStamp - sequenceStartTimeStamp;
|
|
70
|
+
console.log(`✅ Sequence ${sequence.key} done at`, sequenceEndTimeStamp);
|
|
71
|
+
console.log('Sequence execution time', sequenceExecutionTime, 'ms');
|
|
72
|
+
if (sequence.minimumExecutionTime) {
|
|
73
|
+
console.log(`Sequence has minimumExecutionTime`, sequence.minimumExecutionTime, 'ms');
|
|
74
|
+
if (sequenceExecutionTime < sequence.minimumExecutionTime) {
|
|
75
|
+
const delay = sequence.minimumExecutionTime - sequenceExecutionTime;
|
|
76
|
+
console.log(`Sequence will delay`, delay, 'ms');
|
|
77
|
+
let dotInterpreterBlocked = false;
|
|
78
|
+
const dotInterpreter = setInterval(() => {
|
|
79
|
+
if (dotInterpreterBlocked) {
|
|
80
|
+
console.log('!');
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
console.log('.');
|
|
84
|
+
}, 100);
|
|
85
|
+
setTimeout(() => {
|
|
86
|
+
dotInterpreterBlocked = true;
|
|
87
|
+
clearInterval(dotInterpreter);
|
|
88
|
+
console.log('done');
|
|
89
|
+
resolve();
|
|
90
|
+
}, delay);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
console.log('Sequence execution time is greater than minimum execution time');
|
|
94
|
+
resolve();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
resolve();
|
|
98
|
+
}
|
|
99
|
+
catch (e) {
|
|
100
|
+
reject(e);
|
|
101
|
+
}
|
|
102
|
+
}));
|
|
103
|
+
console.log('Out of Promise');
|
|
104
|
+
// Emitter
|
|
105
|
+
this.eventEmitter.emit(SequencerEvent.SEQUENCE_END, sequence);
|
|
106
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
if (sequence.required) {
|
|
109
|
+
console.error(`🚫 Sequence ${sequence.key} failed`, e);
|
|
110
|
+
this.status = SequencerStatus.ERROR;
|
|
111
|
+
this.currentSequence = null;
|
|
112
|
+
this.endTimestamp = this.currentSequence;
|
|
113
|
+
// IMPORTANT
|
|
114
|
+
return Promise.reject({
|
|
115
|
+
sequence,
|
|
116
|
+
reason: e,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
console.log(`Sequence ${sequence.key} failed`, e);
|
|
120
|
+
// Emitter
|
|
121
|
+
this.eventEmitter.emit(SequencerEvent.SEQUENCE_END, sequence);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
this.status = SequencerStatus.DONE;
|
|
125
|
+
this.currentSequence = null;
|
|
126
|
+
this.endTimestamp = this.currentSequence;
|
|
127
|
+
});
|
|
128
|
+
if (option === null || option === void 0 ? void 0 : option.sequences) {
|
|
129
|
+
this.sequences.push(...option.sequences);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
get getCurrentTimeStamp() {
|
|
133
|
+
return parseInt((0, moment_1.default)().format('x'), 10);
|
|
134
|
+
}
|
|
135
|
+
get executionTime() {
|
|
136
|
+
if (this.status === SequencerStatus.IDLE) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
if (!this.startTimestamp) {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
if (this.startTimestamp && this.endTimestamp) {
|
|
143
|
+
return this.endTimestamp - this.startTimestamp;
|
|
144
|
+
}
|
|
145
|
+
return this.getCurrentTimeStamp - this.startTimestamp;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
exports.Sequencer = Sequencer;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StringUtils = void 0;
|
|
4
|
+
class StringUtils {
|
|
5
|
+
static numberWithCommas(x) {
|
|
6
|
+
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
7
|
+
}
|
|
8
|
+
static getByte(s) {
|
|
9
|
+
const getByteLength = (decimal) => {
|
|
10
|
+
const LINE_FEED = 10;
|
|
11
|
+
return (decimal >> 7) || (LINE_FEED === decimal) ? 2 : 1;
|
|
12
|
+
};
|
|
13
|
+
return s
|
|
14
|
+
.split('')
|
|
15
|
+
.map((s) => s.charCodeAt(0))
|
|
16
|
+
.reduce((prev, unicodeDecimalValue) => prev + getByteLength(unicodeDecimalValue), 0);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.StringUtils = StringUtils;
|
|
20
|
+
StringUtils.levenshteinDistance = (str1 = '', str2 = '') => {
|
|
21
|
+
const track = Array(str2.length + 1).fill(null).map(() => Array(str1.length + 1).fill(null));
|
|
22
|
+
for (let i = 0; i <= str1.length; i += 1) {
|
|
23
|
+
track[0][i] = i;
|
|
24
|
+
}
|
|
25
|
+
for (let j = 0; j <= str2.length; j += 1) {
|
|
26
|
+
track[j][0] = j;
|
|
27
|
+
}
|
|
28
|
+
for (let j = 1; j <= str2.length; j += 1) {
|
|
29
|
+
for (let i = 1; i <= str1.length; i += 1) {
|
|
30
|
+
const indicator = str1[i - 1] === str2[j - 1] ? 0 : 1;
|
|
31
|
+
track[j][i] = Math.min(track[j][i - 1] + 1, // deletion
|
|
32
|
+
track[j - 1][i] + 1, // insertion
|
|
33
|
+
track[j - 1][i - 1] + indicator);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return track[str2.length][str1.length];
|
|
37
|
+
};
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UUID = void 0;
|
|
4
|
+
const index_1 = require("../index");
|
|
5
|
+
/**
|
|
6
|
+
* Represents a UUID (Universally Unique Identifier) and provides various utility
|
|
7
|
+
* methods for validation, conversion, comparison and creation.
|
|
8
|
+
*/
|
|
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
|
+
*/
|
|
18
|
+
static isValidHex(hex) {
|
|
19
|
+
if (typeof hex !== 'string') {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
return UUID.REGEX_HEX.test(hex);
|
|
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
|
+
*/
|
|
29
|
+
static isValidString(str) {
|
|
30
|
+
if (typeof str !== 'string') {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
return UUID.REGEX_RFC4122.test(str);
|
|
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
|
+
*/
|
|
40
|
+
static isValidBytes(bytes) {
|
|
41
|
+
return bytes.byteLength === UUID.BYTE_LENGTH;
|
|
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
|
+
*/
|
|
49
|
+
static isValid(input) {
|
|
50
|
+
if (typeof input === 'string') {
|
|
51
|
+
const length = input.length;
|
|
52
|
+
switch (length) {
|
|
53
|
+
case UUID.STR_LENGTH:
|
|
54
|
+
// RFC 4122 uuid(string)
|
|
55
|
+
// 9e472052-a654-4693-9a8b-3ce57ada3d6c
|
|
56
|
+
return UUID.isValidString(input);
|
|
57
|
+
case UUID.HEX_STR_LENGTH:
|
|
58
|
+
// RFC 4122 uuid(string) without hyphens
|
|
59
|
+
// 9e472052a65446939a8b3ce57ada3d6c
|
|
60
|
+
return UUID.isValidHex(input);
|
|
61
|
+
default:
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else if (input instanceof UUID) {
|
|
66
|
+
return UUID.isValidBytes(input.bytes);
|
|
67
|
+
}
|
|
68
|
+
else if (ArrayBuffer.isView(input)) {
|
|
69
|
+
return UUID.isValidBytes(input);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
static version(input) {
|
|
76
|
+
return (this.parse(input)[6] >> 4) & 0x0F;
|
|
77
|
+
}
|
|
78
|
+
/* --------------------------------------------------------------------
|
|
79
|
+
* Parsing / formatting helpers
|
|
80
|
+
* -------------------------------------------------------------------- */
|
|
81
|
+
/**
|
|
82
|
+
* Inserts hyphens into a 32‑character hex string to produce an RFC 4122 string.
|
|
83
|
+
* @param hex - The plain hexadecimal UUID.
|
|
84
|
+
* @returns The formatted RFC 4122 string.
|
|
85
|
+
*/
|
|
86
|
+
static formatHex(hex) {
|
|
87
|
+
if (hex.length !== UUID.HEX_STR_LENGTH) {
|
|
88
|
+
throw new Error(`hex length should be ${UUID.HEX_STR_LENGTH}`);
|
|
89
|
+
}
|
|
90
|
+
return hex.slice(0, 8) + '-' +
|
|
91
|
+
hex.slice(8, 12) + '-' +
|
|
92
|
+
hex.slice(12, 16) + '-' +
|
|
93
|
+
hex.slice(16, 20) + '-' +
|
|
94
|
+
hex.slice(20);
|
|
95
|
+
}
|
|
96
|
+
/** Removes all hyphens from a UUID string. */
|
|
97
|
+
static stripHyphens(str) {
|
|
98
|
+
return str.replace(/-/g, "");
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Converts a plain hexadecimal UUID into a Uint8Array.
|
|
102
|
+
* @param hex - The hex string to parse.
|
|
103
|
+
* @returns A Uint8Array containing the raw bytes.
|
|
104
|
+
*/
|
|
105
|
+
static parseHex(hex) {
|
|
106
|
+
if (hex.length !== UUID.HEX_STR_LENGTH) {
|
|
107
|
+
throw new Error(`Invalid hex string, length should be ${UUID.HEX_STR_LENGTH}`);
|
|
108
|
+
}
|
|
109
|
+
return index_1.Uint8ArrayUtils.fromHex(hex);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Parses an RFC 4122 string into a Uint8Array.
|
|
113
|
+
* @param str - The formatted UUID string.
|
|
114
|
+
* @returns A Uint8Array containing the raw bytes.
|
|
115
|
+
*/
|
|
116
|
+
static parseString(str) {
|
|
117
|
+
if (str.length !== UUID.STR_LENGTH) {
|
|
118
|
+
throw new Error(`Invalid UUID string, invalid character length should be ${UUID.STR_LENGTH}`);
|
|
119
|
+
}
|
|
120
|
+
if (!UUID.isValid(str)) {
|
|
121
|
+
throw new Error('Invalid UUID string, should be RFC 4122 format');
|
|
122
|
+
}
|
|
123
|
+
const hex = UUID.stripHyphens(str);
|
|
124
|
+
if (hex.length !== UUID.HEX_STR_LENGTH) {
|
|
125
|
+
throw new Error('Invalid UUID string, invalid character length after strip hyphens');
|
|
126
|
+
}
|
|
127
|
+
return index_1.Uint8ArrayUtils.fromHex(hex);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Parses an ArrayBufferView into a Uint8Array ensuring the correct byte length.
|
|
131
|
+
* @param bytes - The view to parse.
|
|
132
|
+
* @returns A Uint8Array containing the raw bytes.
|
|
133
|
+
*/
|
|
134
|
+
static parseBytes(bytes) {
|
|
135
|
+
const view = new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
136
|
+
if (view.length !== UUID.BYTE_LENGTH) {
|
|
137
|
+
throw new Error(`Expected ${UUID.BYTE_LENGTH} bytes`);
|
|
138
|
+
}
|
|
139
|
+
return new Uint8Array(view);
|
|
140
|
+
}
|
|
141
|
+
/* --------------------------------------------------------------------
|
|
142
|
+
* Factory methods
|
|
143
|
+
* -------------------------------------------------------------------- */
|
|
144
|
+
/**
|
|
145
|
+
* Creates a UUID instance from a plain hexadecimal string.
|
|
146
|
+
* @param hex - The hex representation of the UUID.
|
|
147
|
+
* @returns A new {@link UUID} object.
|
|
148
|
+
*/
|
|
149
|
+
static fromHex(hex) {
|
|
150
|
+
return new this(UUID.parseHex(hex));
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Creates a UUID instance from an RFC 4122 formatted string.
|
|
154
|
+
* @param str - The UUID string with hyphens.
|
|
155
|
+
* @returns A new {@link UUID} object.
|
|
156
|
+
*/
|
|
157
|
+
static fromString(str) {
|
|
158
|
+
return new this(UUID.parseString(str));
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Creates a UUID instance from raw bytes.
|
|
162
|
+
* @param bytes - An ArrayBufferView containing 16 bytes.
|
|
163
|
+
* @returns A new {@link UUID} object.
|
|
164
|
+
*/
|
|
165
|
+
static fromBytes(bytes) {
|
|
166
|
+
return new this(UUID.parseBytes(bytes));
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Parses any supported input (string or bytes) and returns the raw byte array.
|
|
170
|
+
* @param input - The value to parse.
|
|
171
|
+
* @returns A Uint8Array of length {@link BYTE_LENGTH}.
|
|
172
|
+
*/
|
|
173
|
+
static parse(input) {
|
|
174
|
+
if (typeof input === 'string') {
|
|
175
|
+
const length = input.length;
|
|
176
|
+
switch (length) {
|
|
177
|
+
case UUID.STR_LENGTH:
|
|
178
|
+
// RFC 4122 uuid(string)
|
|
179
|
+
return UUID.parseString(input);
|
|
180
|
+
case UUID.HEX_STR_LENGTH:
|
|
181
|
+
// RFC 4122 uuid(string) without hyphens
|
|
182
|
+
return UUID.parseHex(input);
|
|
183
|
+
default:
|
|
184
|
+
throw new Error(`Invalid input string, length should be ${UUID.STR_LENGTH} or ${UUID.HEX_STR_LENGTH}`);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
else if (input instanceof UUID) {
|
|
188
|
+
return input.toBytes();
|
|
189
|
+
}
|
|
190
|
+
else if (ArrayBuffer.isView(input)) {
|
|
191
|
+
return UUID.parseBytes(input);
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
throw new Error("Invalid input, Expected string or ArrayBufferView");
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Creates a UUID from any supported input type.
|
|
199
|
+
* @param input - The value to parse.
|
|
200
|
+
* @returns A new {@link UUID} object.
|
|
201
|
+
*/
|
|
202
|
+
static from(input) {
|
|
203
|
+
return this.fromBytes(UUID.parse(input));
|
|
204
|
+
}
|
|
205
|
+
/** Returns the nil (all zero) UUID. */
|
|
206
|
+
static nil() {
|
|
207
|
+
return this.fromBytes(new Uint8Array(UUID.BYTE_LENGTH));
|
|
208
|
+
}
|
|
209
|
+
/** Returns a UUID consisting of all 0xFF bytes. */
|
|
210
|
+
static max() {
|
|
211
|
+
return this.fromBytes((new Uint8Array(UUID.BYTE_LENGTH)).fill(0xFF));
|
|
212
|
+
}
|
|
213
|
+
/* --------------------------------------------------------------------
|
|
214
|
+
* Equality / comparison
|
|
215
|
+
* -------------------------------------------------------------------- */
|
|
216
|
+
/**
|
|
217
|
+
* Compares multiple UUIDs for strict equality.
|
|
218
|
+
* @param inputs - The UUIDs to compare (at least two required).
|
|
219
|
+
* @returns true if all provided UUIDs are identical.
|
|
220
|
+
*/
|
|
221
|
+
static equals(...inputs) {
|
|
222
|
+
const n = inputs.length;
|
|
223
|
+
if (n < 2) {
|
|
224
|
+
throw new Error('At least two UUIDs required for comparison');
|
|
225
|
+
}
|
|
226
|
+
const ref = this.parse(inputs[0]);
|
|
227
|
+
for (let i = 1; i < n; ++i) {
|
|
228
|
+
const b = this.parse(inputs[i]);
|
|
229
|
+
for (let j = 0; j < UUID.BYTE_LENGTH; ++j) {
|
|
230
|
+
if (ref[j] !== b[j])
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Lexicographically compares two UUIDs.
|
|
238
|
+
* @param uuid1 - The first UUID.
|
|
239
|
+
* @param uuid2 - The second UUID.
|
|
240
|
+
* @returns -1 if uuid1 < uuid2, 1 if uuid1 > uuid2, 0 otherwise.
|
|
241
|
+
*/
|
|
242
|
+
static compare(uuid1, uuid2) {
|
|
243
|
+
const a = this.parse(uuid1);
|
|
244
|
+
const b = this.parse(uuid2);
|
|
245
|
+
for (let i = 0; i < UUID.BYTE_LENGTH; i++) {
|
|
246
|
+
if (a[i] !== b[i])
|
|
247
|
+
return a[i] < b[i] ? -1 : 1;
|
|
248
|
+
}
|
|
249
|
+
return 0;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Constructs a new {@link UUID} instance from any supported input type.
|
|
253
|
+
* @param input - The value to parse (string or ArrayBufferView).
|
|
254
|
+
*/
|
|
255
|
+
constructor(input) {
|
|
256
|
+
this.bytes = UUID.parse(input);
|
|
257
|
+
}
|
|
258
|
+
/** Instance wrapper for {@link equals}. */
|
|
259
|
+
equals(...inputs) {
|
|
260
|
+
return UUID.equals(this, ...inputs);
|
|
261
|
+
}
|
|
262
|
+
/** Instance wrapper for {@link compare}. */
|
|
263
|
+
compare(other) {
|
|
264
|
+
return UUID.compare(this, other);
|
|
265
|
+
}
|
|
266
|
+
version() {
|
|
267
|
+
return UUID.version(this);
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Returns the RFC 4122 string representation of this UUID.
|
|
271
|
+
* @returns The formatted UUID string.
|
|
272
|
+
*/
|
|
273
|
+
toString() {
|
|
274
|
+
if (this._str != null) {
|
|
275
|
+
return this._str;
|
|
276
|
+
}
|
|
277
|
+
const hex = this.toHex();
|
|
278
|
+
this._str = UUID.formatHex(hex);
|
|
279
|
+
return this._str;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Returns the plain hexadecimal representation of this UUID.
|
|
283
|
+
* @returns A 32‑character hex string.
|
|
284
|
+
*/
|
|
285
|
+
toHex() {
|
|
286
|
+
if (this._hex != null) {
|
|
287
|
+
return this._hex;
|
|
288
|
+
}
|
|
289
|
+
this._hex = index_1.Uint8ArrayUtils.toHex(this.bytes);
|
|
290
|
+
return this._hex;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Returns a copy of the raw byte array.
|
|
294
|
+
* @returns A new Uint8Array containing the UUID bytes.
|
|
295
|
+
*/
|
|
296
|
+
toBytes() {
|
|
297
|
+
return new Uint8Array(this.bytes);
|
|
298
|
+
}
|
|
299
|
+
/** JSON serialization helper – returns the RFC 4122 string. */
|
|
300
|
+
toJSON() {
|
|
301
|
+
return this.toString();
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
exports.UUID = UUID;
|
|
305
|
+
/* --------------------------------------------------------------------
|
|
306
|
+
* Regular expressions used to validate UUIDs in different string forms
|
|
307
|
+
* -------------------------------------------------------------------- */
|
|
308
|
+
/** Matches a 32‑character hexadecimal representation of a UUID without hyphens. */
|
|
309
|
+
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}$/;
|
|
310
|
+
/** Matches the RFC 4122 canonical UUID format with hyphens. */
|
|
311
|
+
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}$/;
|
|
312
|
+
/* --------------------------------------------------------------------
|
|
313
|
+
* Constant lengths used throughout the class
|
|
314
|
+
* -------------------------------------------------------------------- */
|
|
315
|
+
/** Number of bytes that represent a UUID. */
|
|
316
|
+
UUID.BYTE_LENGTH = 16;
|
|
317
|
+
/** Total length of an RFC 4122 UUID string (including hyphens). */
|
|
318
|
+
UUID.STR_LENGTH = 36;
|
|
319
|
+
/** Length of a UUID represented as a plain hexadecimal string. */
|
|
320
|
+
UUID.HEX_STR_LENGTH = 32;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Uint8ArrayUtils = void 0;
|
|
4
|
+
class Uint8ArrayUtils {
|
|
5
|
+
static fromHex(hex) {
|
|
6
|
+
var _a, _b;
|
|
7
|
+
return Uint8Array.from((_b = (_a = hex.match(/.{1,2}/g)) === null || _a === void 0 ? void 0 : _a.map((byte) => parseInt(byte, 16))) !== null && _b !== void 0 ? _b : []);
|
|
8
|
+
}
|
|
9
|
+
static toHex(bytes) {
|
|
10
|
+
return bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '');
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.Uint8ArrayUtils = Uint8ArrayUtils;
|