@vpmedia/simplify 1.70.0 → 1.71.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/CHANGELOG.md +16 -0
- package/package.json +1 -1
- package/src/util/uuid.js +29 -11
- package/src/util/uuid.test.js +14 -0
- package/types/util/uuid.d.ts +2 -2
- package/types/util/uuid.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
## [1.71.0] - 2026-02-05
|
|
2
|
+
|
|
3
|
+
### 🚜 Refactor
|
|
4
|
+
|
|
5
|
+
- Improve uuidv4 generator
|
|
6
|
+
|
|
7
|
+
### 🧪 Testing
|
|
8
|
+
|
|
9
|
+
- Adjusted uuid test
|
|
10
|
+
- Improve uuid tests
|
|
11
|
+
|
|
12
|
+
### ⚙️ Miscellaneous Tasks
|
|
13
|
+
|
|
14
|
+
- Release
|
|
15
|
+
- Regenerate types and source maps
|
|
16
|
+
- *(release)* V1.71.0
|
|
1
17
|
## [1.70.0] - 2026-02-04
|
|
2
18
|
|
|
3
19
|
### 🚀 Features
|
package/package.json
CHANGED
package/src/util/uuid.js
CHANGED
|
@@ -1,19 +1,37 @@
|
|
|
1
1
|
/* eslint-disable no-bitwise, unicorn/number-literal-case */
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Convert a byte (0–255) to a 2‑character hex string.
|
|
5
|
+
* @param {number} byte - Byte value.
|
|
6
|
+
* @returns {string} Hex value.
|
|
7
|
+
*/
|
|
8
|
+
export const byteToHex = (byte) => (byte >>> 4).toString(16) + (byte & 0b1111).toString(16);
|
|
4
9
|
|
|
10
|
+
/**
|
|
11
|
+
* UUIDv4 fallback generator (RFC 4122 compliant).
|
|
12
|
+
* @returns {string} UUIDv4 string.
|
|
13
|
+
*/
|
|
5
14
|
export const randomUUIDFallback = () => {
|
|
6
|
-
const
|
|
15
|
+
const bytes = crypto.getRandomValues
|
|
7
16
|
? crypto.getRandomValues(new Uint8Array(16))
|
|
8
17
|
: Array.from({ length: 16 }, () => Math.floor(Math.random() * 256));
|
|
9
|
-
r[6] = (r[6] & 0x0f) | 0x40;
|
|
10
|
-
r[8] = (r[8] & 0x3f) | 0x80;
|
|
11
|
-
return [...r].reduce((uuid, b, i) => uuid + hex(i === 4 || i === 6 || i === 8 || i === 10 ? '-' : '', b), '');
|
|
12
|
-
};
|
|
13
18
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
// RFC 4122 version & variant bits
|
|
20
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
21
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
22
|
+
|
|
23
|
+
let uuid = '';
|
|
24
|
+
for (const [index, byte] of bytes.entries()) {
|
|
25
|
+
if (index === 4 || index === 6 || index === 8 || index === 10) {
|
|
26
|
+
uuid += '-';
|
|
27
|
+
}
|
|
28
|
+
uuid += byteToHex(byte);
|
|
29
|
+
}
|
|
30
|
+
return uuid;
|
|
31
|
+
};
|
|
18
32
|
|
|
19
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Crypto UUIDv4 wrapper with fallback.
|
|
35
|
+
* @returns {string} UUIDv4 string.
|
|
36
|
+
*/
|
|
37
|
+
export const uuidv4 = () => (typeof crypto.randomUUID === 'function' ? crypto.randomUUID() : randomUUIDFallback());
|
package/src/util/uuid.test.js
CHANGED
|
@@ -33,7 +33,21 @@ describe('UUID functions', () => {
|
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
it('randomUUIDFallback fallback works if crypto.randomUUID not available', () => {
|
|
36
|
+
delete crypto.randomUUID;
|
|
36
37
|
const uuid = randomUUIDFallback();
|
|
37
38
|
expect(uuid).toMatch(uuidV4Regex);
|
|
38
39
|
});
|
|
40
|
+
|
|
41
|
+
it('randomUUIDFallback does not generate duplicates', () => {
|
|
42
|
+
const uuidMap = new Map();
|
|
43
|
+
const numSamples = 1000;
|
|
44
|
+
for (let i = 0; i < numSamples; i += 1) {
|
|
45
|
+
const uuid = randomUUIDFallback();
|
|
46
|
+
if (uuidMap.has(uuid)) {
|
|
47
|
+
throw new Error('Duplicate UUIDv4 found');
|
|
48
|
+
}
|
|
49
|
+
uuidMap.set(uuid, true);
|
|
50
|
+
}
|
|
51
|
+
expect(uuidMap.size).toBe(numSamples);
|
|
52
|
+
});
|
|
39
53
|
});
|
package/types/util/uuid.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export function
|
|
1
|
+
export function byteToHex(byte: number): string;
|
|
2
2
|
export function randomUUIDFallback(): string;
|
|
3
|
-
export function uuidv4():
|
|
3
|
+
export function uuidv4(): string;
|
|
4
4
|
//# sourceMappingURL=uuid.d.ts.map
|
package/types/util/uuid.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uuid.d.ts","sourceRoot":"","sources":["../../src/util/uuid.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"uuid.d.ts","sourceRoot":"","sources":["../../src/util/uuid.js"],"names":[],"mappings":"AAOO,gCAHI,MAAM,GACJ,MAAM,CAEwE;AAMpF,sCAFM,MAAM,CAmBlB;AAMM,0BAFM,MAAM,CAE+F"}
|