@powfix/core-js 0.17.2 → 0.17.3
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/utils/UUID.js +41 -18
- package/dist/browser/esm/utils/UUID.mjs +41 -18
- package/dist/browser/types/utils/UUID.d.ts +5 -1
- package/dist/node/cjs/utils/UUID.js +41 -18
- package/dist/node/esm/utils/UUID.mjs +41 -18
- package/dist/node/types/utils/UUID.d.ts +5 -1
- package/package.json +1 -1
|
@@ -26,9 +26,43 @@ class UUID {
|
|
|
26
26
|
static fromString(str) {
|
|
27
27
|
return new UUID(str);
|
|
28
28
|
}
|
|
29
|
+
static parseBytes(bytes) {
|
|
30
|
+
if (bytes instanceof Uint8Array) {
|
|
31
|
+
return new Uint8Array(bytes);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
return new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
static fromBytes(bytes) {
|
|
38
|
+
return new UUID(UUID.parseBytes(bytes));
|
|
39
|
+
}
|
|
29
40
|
static nil() {
|
|
30
41
|
return new UUID(new Uint8Array(UUID.BYTE_LENGTH));
|
|
31
42
|
}
|
|
43
|
+
static equals(...uuids) {
|
|
44
|
+
const n = uuids.length;
|
|
45
|
+
if (n <= 1)
|
|
46
|
+
return true;
|
|
47
|
+
const ref = uuids[0].bytes;
|
|
48
|
+
for (let i = 1; i < n; ++i) {
|
|
49
|
+
const b = uuids[i].bytes;
|
|
50
|
+
for (let j = 0; j < UUID.BYTE_LENGTH; ++j) {
|
|
51
|
+
if (ref[j] !== b[j])
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
static compare(uuid1, uuid2) {
|
|
58
|
+
const a = uuid1.bytes;
|
|
59
|
+
const b = uuid2.bytes;
|
|
60
|
+
for (let i = 0; i < UUID.BYTE_LENGTH; i++) {
|
|
61
|
+
if (a[i] !== b[i])
|
|
62
|
+
return a[i] < b[i] ? -1 : 1;
|
|
63
|
+
}
|
|
64
|
+
return 0;
|
|
65
|
+
}
|
|
32
66
|
constructor(input) {
|
|
33
67
|
if (input == null) {
|
|
34
68
|
throw new Error('Input cannot be null');
|
|
@@ -36,32 +70,21 @@ class UUID {
|
|
|
36
70
|
if (typeof input === 'string') {
|
|
37
71
|
this.bytes = UUID.parseString(input);
|
|
38
72
|
}
|
|
73
|
+
else if (ArrayBuffer.isView(input)) {
|
|
74
|
+
this.bytes = UUID.parseBytes(input);
|
|
75
|
+
}
|
|
39
76
|
else {
|
|
40
|
-
|
|
41
|
-
this.bytes = new Uint8Array(input);
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
this.bytes = new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
|
|
45
|
-
}
|
|
77
|
+
throw new Error("Expected string or ArrayBufferView");
|
|
46
78
|
}
|
|
47
79
|
if (this.bytes.byteLength !== UUID.BYTE_LENGTH) {
|
|
48
80
|
throw new Error(`UUID must be ${UUID.BYTE_LENGTH} bytes`);
|
|
49
81
|
}
|
|
50
82
|
}
|
|
51
|
-
equals(
|
|
52
|
-
|
|
53
|
-
let v = 0;
|
|
54
|
-
for (let i = 0; i < UUID.BYTE_LENGTH; i++)
|
|
55
|
-
v |= a[i] ^ b[i];
|
|
56
|
-
return v === 0;
|
|
83
|
+
equals(...uuids) {
|
|
84
|
+
return UUID.equals(this, ...uuids);
|
|
57
85
|
}
|
|
58
86
|
compare(other) {
|
|
59
|
-
|
|
60
|
-
for (let i = 0; i < UUID.BYTE_LENGTH; i++) {
|
|
61
|
-
if (a[i] !== b[i])
|
|
62
|
-
return a[i] < b[i] ? -1 : 1;
|
|
63
|
-
}
|
|
64
|
-
return 0;
|
|
87
|
+
return UUID.compare(this, other);
|
|
65
88
|
}
|
|
66
89
|
toString() {
|
|
67
90
|
if (this._str != null) {
|
|
@@ -23,9 +23,43 @@ export class UUID {
|
|
|
23
23
|
static fromString(str) {
|
|
24
24
|
return new UUID(str);
|
|
25
25
|
}
|
|
26
|
+
static parseBytes(bytes) {
|
|
27
|
+
if (bytes instanceof Uint8Array) {
|
|
28
|
+
return new Uint8Array(bytes);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
return new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
static fromBytes(bytes) {
|
|
35
|
+
return new UUID(UUID.parseBytes(bytes));
|
|
36
|
+
}
|
|
26
37
|
static nil() {
|
|
27
38
|
return new UUID(new Uint8Array(UUID.BYTE_LENGTH));
|
|
28
39
|
}
|
|
40
|
+
static equals(...uuids) {
|
|
41
|
+
const n = uuids.length;
|
|
42
|
+
if (n <= 1)
|
|
43
|
+
return true;
|
|
44
|
+
const ref = uuids[0].bytes;
|
|
45
|
+
for (let i = 1; i < n; ++i) {
|
|
46
|
+
const b = uuids[i].bytes;
|
|
47
|
+
for (let j = 0; j < UUID.BYTE_LENGTH; ++j) {
|
|
48
|
+
if (ref[j] !== b[j])
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
static compare(uuid1, uuid2) {
|
|
55
|
+
const a = uuid1.bytes;
|
|
56
|
+
const b = uuid2.bytes;
|
|
57
|
+
for (let i = 0; i < UUID.BYTE_LENGTH; i++) {
|
|
58
|
+
if (a[i] !== b[i])
|
|
59
|
+
return a[i] < b[i] ? -1 : 1;
|
|
60
|
+
}
|
|
61
|
+
return 0;
|
|
62
|
+
}
|
|
29
63
|
constructor(input) {
|
|
30
64
|
if (input == null) {
|
|
31
65
|
throw new Error('Input cannot be null');
|
|
@@ -33,32 +67,21 @@ export class UUID {
|
|
|
33
67
|
if (typeof input === 'string') {
|
|
34
68
|
this.bytes = UUID.parseString(input);
|
|
35
69
|
}
|
|
70
|
+
else if (ArrayBuffer.isView(input)) {
|
|
71
|
+
this.bytes = UUID.parseBytes(input);
|
|
72
|
+
}
|
|
36
73
|
else {
|
|
37
|
-
|
|
38
|
-
this.bytes = new Uint8Array(input);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
this.bytes = new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
|
|
42
|
-
}
|
|
74
|
+
throw new Error("Expected string or ArrayBufferView");
|
|
43
75
|
}
|
|
44
76
|
if (this.bytes.byteLength !== UUID.BYTE_LENGTH) {
|
|
45
77
|
throw new Error(`UUID must be ${UUID.BYTE_LENGTH} bytes`);
|
|
46
78
|
}
|
|
47
79
|
}
|
|
48
|
-
equals(
|
|
49
|
-
|
|
50
|
-
let v = 0;
|
|
51
|
-
for (let i = 0; i < UUID.BYTE_LENGTH; i++)
|
|
52
|
-
v |= a[i] ^ b[i];
|
|
53
|
-
return v === 0;
|
|
80
|
+
equals(...uuids) {
|
|
81
|
+
return UUID.equals(this, ...uuids);
|
|
54
82
|
}
|
|
55
83
|
compare(other) {
|
|
56
|
-
|
|
57
|
-
for (let i = 0; i < UUID.BYTE_LENGTH; i++) {
|
|
58
|
-
if (a[i] !== b[i])
|
|
59
|
-
return a[i] < b[i] ? -1 : 1;
|
|
60
|
-
}
|
|
61
|
-
return 0;
|
|
84
|
+
return UUID.compare(this, other);
|
|
62
85
|
}
|
|
63
86
|
toString() {
|
|
64
87
|
if (this._str != null) {
|
|
@@ -5,12 +5,16 @@ export declare class UUID {
|
|
|
5
5
|
private static stripHyphens;
|
|
6
6
|
private static parseString;
|
|
7
7
|
static fromString(str: string): UUID;
|
|
8
|
+
private static parseBytes;
|
|
9
|
+
static fromBytes(bytes: ArrayBufferView): UUID;
|
|
8
10
|
static nil(): UUID;
|
|
11
|
+
static equals(...uuids: UUID[]): boolean;
|
|
12
|
+
static compare(uuid1: UUID, uuid2: UUID): number;
|
|
9
13
|
private readonly bytes;
|
|
10
14
|
private _str?;
|
|
11
15
|
private _hex?;
|
|
12
16
|
constructor(input: string | ArrayBufferView);
|
|
13
|
-
equals(
|
|
17
|
+
equals(...uuids: UUID[]): boolean;
|
|
14
18
|
compare(other: UUID): number;
|
|
15
19
|
toString(): string;
|
|
16
20
|
toHex(): string;
|
|
@@ -26,9 +26,43 @@ class UUID {
|
|
|
26
26
|
static fromString(str) {
|
|
27
27
|
return new UUID(str);
|
|
28
28
|
}
|
|
29
|
+
static parseBytes(bytes) {
|
|
30
|
+
if (bytes instanceof Uint8Array) {
|
|
31
|
+
return new Uint8Array(bytes);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
return new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
static fromBytes(bytes) {
|
|
38
|
+
return new UUID(UUID.parseBytes(bytes));
|
|
39
|
+
}
|
|
29
40
|
static nil() {
|
|
30
41
|
return new UUID(new Uint8Array(UUID.BYTE_LENGTH));
|
|
31
42
|
}
|
|
43
|
+
static equals(...uuids) {
|
|
44
|
+
const n = uuids.length;
|
|
45
|
+
if (n <= 1)
|
|
46
|
+
return true;
|
|
47
|
+
const ref = uuids[0].bytes;
|
|
48
|
+
for (let i = 1; i < n; ++i) {
|
|
49
|
+
const b = uuids[i].bytes;
|
|
50
|
+
for (let j = 0; j < UUID.BYTE_LENGTH; ++j) {
|
|
51
|
+
if (ref[j] !== b[j])
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
static compare(uuid1, uuid2) {
|
|
58
|
+
const a = uuid1.bytes;
|
|
59
|
+
const b = uuid2.bytes;
|
|
60
|
+
for (let i = 0; i < UUID.BYTE_LENGTH; i++) {
|
|
61
|
+
if (a[i] !== b[i])
|
|
62
|
+
return a[i] < b[i] ? -1 : 1;
|
|
63
|
+
}
|
|
64
|
+
return 0;
|
|
65
|
+
}
|
|
32
66
|
constructor(input) {
|
|
33
67
|
if (input == null) {
|
|
34
68
|
throw new Error('Input cannot be null');
|
|
@@ -36,32 +70,21 @@ class UUID {
|
|
|
36
70
|
if (typeof input === 'string') {
|
|
37
71
|
this.bytes = UUID.parseString(input);
|
|
38
72
|
}
|
|
73
|
+
else if (ArrayBuffer.isView(input)) {
|
|
74
|
+
this.bytes = UUID.parseBytes(input);
|
|
75
|
+
}
|
|
39
76
|
else {
|
|
40
|
-
|
|
41
|
-
this.bytes = new Uint8Array(input);
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
this.bytes = new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
|
|
45
|
-
}
|
|
77
|
+
throw new Error("Expected string or ArrayBufferView");
|
|
46
78
|
}
|
|
47
79
|
if (this.bytes.byteLength !== UUID.BYTE_LENGTH) {
|
|
48
80
|
throw new Error(`UUID must be ${UUID.BYTE_LENGTH} bytes`);
|
|
49
81
|
}
|
|
50
82
|
}
|
|
51
|
-
equals(
|
|
52
|
-
|
|
53
|
-
let v = 0;
|
|
54
|
-
for (let i = 0; i < UUID.BYTE_LENGTH; i++)
|
|
55
|
-
v |= a[i] ^ b[i];
|
|
56
|
-
return v === 0;
|
|
83
|
+
equals(...uuids) {
|
|
84
|
+
return UUID.equals(this, ...uuids);
|
|
57
85
|
}
|
|
58
86
|
compare(other) {
|
|
59
|
-
|
|
60
|
-
for (let i = 0; i < UUID.BYTE_LENGTH; i++) {
|
|
61
|
-
if (a[i] !== b[i])
|
|
62
|
-
return a[i] < b[i] ? -1 : 1;
|
|
63
|
-
}
|
|
64
|
-
return 0;
|
|
87
|
+
return UUID.compare(this, other);
|
|
65
88
|
}
|
|
66
89
|
toString() {
|
|
67
90
|
if (this._str != null) {
|
|
@@ -23,9 +23,43 @@ export class UUID {
|
|
|
23
23
|
static fromString(str) {
|
|
24
24
|
return new UUID(str);
|
|
25
25
|
}
|
|
26
|
+
static parseBytes(bytes) {
|
|
27
|
+
if (bytes instanceof Uint8Array) {
|
|
28
|
+
return new Uint8Array(bytes);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
return new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
static fromBytes(bytes) {
|
|
35
|
+
return new UUID(UUID.parseBytes(bytes));
|
|
36
|
+
}
|
|
26
37
|
static nil() {
|
|
27
38
|
return new UUID(new Uint8Array(UUID.BYTE_LENGTH));
|
|
28
39
|
}
|
|
40
|
+
static equals(...uuids) {
|
|
41
|
+
const n = uuids.length;
|
|
42
|
+
if (n <= 1)
|
|
43
|
+
return true;
|
|
44
|
+
const ref = uuids[0].bytes;
|
|
45
|
+
for (let i = 1; i < n; ++i) {
|
|
46
|
+
const b = uuids[i].bytes;
|
|
47
|
+
for (let j = 0; j < UUID.BYTE_LENGTH; ++j) {
|
|
48
|
+
if (ref[j] !== b[j])
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
static compare(uuid1, uuid2) {
|
|
55
|
+
const a = uuid1.bytes;
|
|
56
|
+
const b = uuid2.bytes;
|
|
57
|
+
for (let i = 0; i < UUID.BYTE_LENGTH; i++) {
|
|
58
|
+
if (a[i] !== b[i])
|
|
59
|
+
return a[i] < b[i] ? -1 : 1;
|
|
60
|
+
}
|
|
61
|
+
return 0;
|
|
62
|
+
}
|
|
29
63
|
constructor(input) {
|
|
30
64
|
if (input == null) {
|
|
31
65
|
throw new Error('Input cannot be null');
|
|
@@ -33,32 +67,21 @@ export class UUID {
|
|
|
33
67
|
if (typeof input === 'string') {
|
|
34
68
|
this.bytes = UUID.parseString(input);
|
|
35
69
|
}
|
|
70
|
+
else if (ArrayBuffer.isView(input)) {
|
|
71
|
+
this.bytes = UUID.parseBytes(input);
|
|
72
|
+
}
|
|
36
73
|
else {
|
|
37
|
-
|
|
38
|
-
this.bytes = new Uint8Array(input);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
this.bytes = new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
|
|
42
|
-
}
|
|
74
|
+
throw new Error("Expected string or ArrayBufferView");
|
|
43
75
|
}
|
|
44
76
|
if (this.bytes.byteLength !== UUID.BYTE_LENGTH) {
|
|
45
77
|
throw new Error(`UUID must be ${UUID.BYTE_LENGTH} bytes`);
|
|
46
78
|
}
|
|
47
79
|
}
|
|
48
|
-
equals(
|
|
49
|
-
|
|
50
|
-
let v = 0;
|
|
51
|
-
for (let i = 0; i < UUID.BYTE_LENGTH; i++)
|
|
52
|
-
v |= a[i] ^ b[i];
|
|
53
|
-
return v === 0;
|
|
80
|
+
equals(...uuids) {
|
|
81
|
+
return UUID.equals(this, ...uuids);
|
|
54
82
|
}
|
|
55
83
|
compare(other) {
|
|
56
|
-
|
|
57
|
-
for (let i = 0; i < UUID.BYTE_LENGTH; i++) {
|
|
58
|
-
if (a[i] !== b[i])
|
|
59
|
-
return a[i] < b[i] ? -1 : 1;
|
|
60
|
-
}
|
|
61
|
-
return 0;
|
|
84
|
+
return UUID.compare(this, other);
|
|
62
85
|
}
|
|
63
86
|
toString() {
|
|
64
87
|
if (this._str != null) {
|
|
@@ -5,12 +5,16 @@ export declare class UUID {
|
|
|
5
5
|
private static stripHyphens;
|
|
6
6
|
private static parseString;
|
|
7
7
|
static fromString(str: string): UUID;
|
|
8
|
+
private static parseBytes;
|
|
9
|
+
static fromBytes(bytes: ArrayBufferView): UUID;
|
|
8
10
|
static nil(): UUID;
|
|
11
|
+
static equals(...uuids: UUID[]): boolean;
|
|
12
|
+
static compare(uuid1: UUID, uuid2: UUID): number;
|
|
9
13
|
private readonly bytes;
|
|
10
14
|
private _str?;
|
|
11
15
|
private _hex?;
|
|
12
16
|
constructor(input: string | ArrayBufferView);
|
|
13
|
-
equals(
|
|
17
|
+
equals(...uuids: UUID[]): boolean;
|
|
14
18
|
compare(other: UUID): number;
|
|
15
19
|
toString(): string;
|
|
16
20
|
toHex(): string;
|