@vpmedia/simplify 1.68.0 → 1.70.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 +20 -0
- package/package.json +1 -1
- package/src/index.js +2 -1
- package/src/util/uuid.js +19 -0
- package/src/util/uuid.test.js +39 -0
- package/types/index.d.ts +2 -1
- package/types/util/uuid.d.ts +4 -0
- package/types/util/uuid.d.ts.map +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
## [1.70.0] - 2026-02-04
|
|
2
|
+
|
|
3
|
+
### 🚀 Features
|
|
4
|
+
|
|
5
|
+
- Added uuidv4 generator
|
|
6
|
+
|
|
7
|
+
### ⚙️ Miscellaneous Tasks
|
|
8
|
+
|
|
9
|
+
- Release
|
|
10
|
+
- *(release)* V1.70.0
|
|
11
|
+
## [1.69.0] - 2026-02-04
|
|
12
|
+
|
|
13
|
+
### 🐛 Bug Fixes
|
|
14
|
+
|
|
15
|
+
- Fixed export name
|
|
16
|
+
|
|
17
|
+
### ⚙️ Miscellaneous Tasks
|
|
18
|
+
|
|
19
|
+
- Release
|
|
20
|
+
- *(release)* V1.69.0
|
|
1
21
|
## [1.68.0] - 2026-02-04
|
|
2
22
|
|
|
3
23
|
### 🚜 Refactor
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -21,7 +21,7 @@ export { TypeCheckError } from './typecheck/TypeCheckError.js';
|
|
|
21
21
|
export { typeCheck, typeCheckArray, typeCheckEnum } from './typecheck/util.js';
|
|
22
22
|
export { delayPromise, loadJSON } from './util/async.js';
|
|
23
23
|
export { getErrorDetails, getTypedError } from './util/error.js';
|
|
24
|
-
export { EventEmitter
|
|
24
|
+
export { EventEmitter } from './util/event_emitter.js';
|
|
25
25
|
export { FetchError, fetchRetry, HTTP_0_ANY } from './util/fetch.js';
|
|
26
26
|
export {
|
|
27
27
|
deg2rad,
|
|
@@ -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,19 @@
|
|
|
1
|
+
/* eslint-disable no-bitwise, unicorn/number-literal-case */
|
|
2
|
+
|
|
3
|
+
export const hex = (s, b) => s + (b >>> 4).toString(16) + (b & 0b1111).toString(16);
|
|
4
|
+
|
|
5
|
+
export const randomUUIDFallback = () => {
|
|
6
|
+
const r = crypto.getRandomValues
|
|
7
|
+
? crypto.getRandomValues(new Uint8Array(16))
|
|
8
|
+
: 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
|
+
|
|
14
|
+
if (!crypto.randomUUID) {
|
|
15
|
+
// @ts-expect-error
|
|
16
|
+
crypto.randomUUID = randomUUIDFallback;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const uuidv4 = () => crypto.randomUUID();
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
const uuid = randomUUIDFallback();
|
|
37
|
+
expect(uuid).toMatch(uuidV4Regex);
|
|
38
|
+
});
|
|
39
|
+
});
|
package/types/index.d.ts
CHANGED
|
@@ -10,8 +10,9 @@ export { OpenTelemetryLogHandler } from "./logging/OpenTelemetryLogHandler.js";
|
|
|
10
10
|
export { SentryLogHandler } from "./logging/SentryLogHandler.js";
|
|
11
11
|
export { typeChecker } from "./typecheck/TypeChecker.js";
|
|
12
12
|
export { TypeCheckError } from "./typecheck/TypeCheckError.js";
|
|
13
|
-
export { EventEmitter
|
|
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":"AAEO,4CAA4E;AAE5E,6CAON;AAOM,8EAAwC"}
|