@vpmedia/simplify 1.69.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 +26 -0
- package/package.json +1 -1
- package/src/index.js +1 -0
- package/src/util/uuid.js +37 -0
- package/src/util/uuid.test.js +53 -0
- package/types/index.d.ts +1 -0
- package/types/util/uuid.d.ts +4 -0
- package/types/util/uuid.d.ts.map +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
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
|
|
17
|
+
## [1.70.0] - 2026-02-04
|
|
18
|
+
|
|
19
|
+
### π Features
|
|
20
|
+
|
|
21
|
+
- Added uuidv4 generator
|
|
22
|
+
|
|
23
|
+
### βοΈ Miscellaneous Tasks
|
|
24
|
+
|
|
25
|
+
- Release
|
|
26
|
+
- *(release)* V1.70.0
|
|
1
27
|
## [1.69.0] - 2026-02-04
|
|
2
28
|
|
|
3
29
|
### π Bug Fixes
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -39,4 +39,5 @@ export { deepMerge, getObjArrayPropSum, getObjValueByPath, purgeObject, setObjVa
|
|
|
39
39
|
export { getURLParam, sanitizeURLParam } from './util/query.js';
|
|
40
40
|
export { serverDataToState } from './util/state.js';
|
|
41
41
|
export { addLeadingZero, capitalize, getTypeFromValue, saveAsFile, underscoreToCamelCase } from './util/string.js';
|
|
42
|
+
export { uuidv4 } from './util/uuid.js';
|
|
42
43
|
export * from './util/validate.js';
|
package/src/util/uuid.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/* eslint-disable no-bitwise, unicorn/number-literal-case */
|
|
2
|
+
|
|
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);
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* UUIDv4 fallback generator (RFC 4122 compliant).
|
|
12
|
+
* @returns {string} UUIDv4 string.
|
|
13
|
+
*/
|
|
14
|
+
export const randomUUIDFallback = () => {
|
|
15
|
+
const bytes = crypto.getRandomValues
|
|
16
|
+
? crypto.getRandomValues(new Uint8Array(16))
|
|
17
|
+
: Array.from({ length: 16 }, () => Math.floor(Math.random() * 256));
|
|
18
|
+
|
|
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
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Crypto UUIDv4 wrapper with fallback.
|
|
35
|
+
* @returns {string} UUIDv4 string.
|
|
36
|
+
*/
|
|
37
|
+
export const uuidv4 = () => (typeof crypto.randomUUID === 'function' ? crypto.randomUUID() : randomUUIDFallback());
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
import { randomUUIDFallback, uuidv4 } from './uuid.js';
|
|
3
|
+
|
|
4
|
+
const uuidV4Regex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu;
|
|
5
|
+
|
|
6
|
+
describe('UUID functions', () => {
|
|
7
|
+
let originalRandomUUID = null;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
originalRandomUUID = crypto.randomUUID;
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
crypto.randomUUID = originalRandomUUID;
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('randomUUIDFallback generates a valid UUID v4', () => {
|
|
18
|
+
const uuid = randomUUIDFallback();
|
|
19
|
+
expect(uuid).toMatch(uuidV4Regex);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('uuidv4 returns a valid UUID v4', () => {
|
|
23
|
+
const uuid = uuidv4();
|
|
24
|
+
expect(uuid).toMatch(uuidV4Regex);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('uuidv4 uses crypto.randomUUID if available', () => {
|
|
28
|
+
// @ts-expect-error
|
|
29
|
+
crypto.randomUUID = vi.fn(() => 'mock-uuid');
|
|
30
|
+
const uuid = uuidv4();
|
|
31
|
+
expect(uuid).toBe('mock-uuid');
|
|
32
|
+
expect(crypto.randomUUID).toHaveBeenCalled();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('randomUUIDFallback fallback works if crypto.randomUUID not available', () => {
|
|
36
|
+
delete crypto.randomUUID;
|
|
37
|
+
const uuid = randomUUIDFallback();
|
|
38
|
+
expect(uuid).toMatch(uuidV4Regex);
|
|
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
|
+
});
|
|
53
|
+
});
|
package/types/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export { typeChecker } from "./typecheck/TypeChecker.js";
|
|
|
12
12
|
export { TypeCheckError } from "./typecheck/TypeCheckError.js";
|
|
13
13
|
export { EventEmitter } from "./util/event_emitter.js";
|
|
14
14
|
export { serverDataToState } from "./util/state.js";
|
|
15
|
+
export { uuidv4 } from "./util/uuid.js";
|
|
15
16
|
export { formatLogMessage, getLogLevelName } from "./logging/util.js";
|
|
16
17
|
export { addPageLifecycleCallback, getDocumentState, getPageLifecycleEventEmitter, getPageLifecycleState, initPageLifecycle, isPageLifecycleInitialized } from "./pagelifecycle/util.js";
|
|
17
18
|
export { typeCheck, typeCheckArray, typeCheckEnum } from "./typecheck/util.js";
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|