fastv7 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Dane Wilson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # fastv7
2
+
3
+ Fast, spec-compliant UUIDv7 generator with monotonic ordering.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install fastv7
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { fastv7 } from "fastv7";
15
+
16
+ const id = fastv7();
17
+ // → 019b3ae7-0184-799d-babe-a5a0bb7f263f
18
+ ```
19
+
20
+ ## Benchmark
21
+
22
+ 500k iterations on M-series hardware:
23
+
24
+ | Generator | ms | ops/sec |
25
+ | --------------------- | ----: | ---------- |
26
+ | `crypto.randomUUID` | 20.46 | 24,432,455 |
27
+ | **fastv7** | 27.36 | 18,276,941 |
28
+ | `uuidv7` (uuidv7 pkg) | 77.67 | 6,437,388 |
29
+ | `uuid` v7 (uuid pkg) | 100.2 | 4,989,267 |
30
+
31
+ ~3× faster than `uuidv7`, ~4× faster than `uuid`.
32
+
33
+ ## License
34
+
35
+ MIT
@@ -0,0 +1,2 @@
1
+ export declare function fastv7(): string;
2
+ //# sourceMappingURL=fastv7.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fastv7.d.ts","sourceRoot":"","sources":["../src/fastv7.ts"],"names":[],"mappings":"AAaA,wBAAgB,MAAM,WAqDrB"}
package/dist/fastv7.js ADDED
@@ -0,0 +1,58 @@
1
+ const HEX = Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
2
+ let pool = new Uint8Array(4096);
3
+ let poolOffset = pool.length;
4
+ function refillPool() {
5
+ crypto.getRandomValues(pool);
6
+ poolOffset = 0;
7
+ }
8
+ let lastTs = 0;
9
+ let seq = 0;
10
+ export function fastv7() {
11
+ const now = Date.now();
12
+ if (now > lastTs) {
13
+ lastTs = now;
14
+ seq = 0;
15
+ }
16
+ else {
17
+ seq++;
18
+ if (seq > 0xfff)
19
+ seq = 0;
20
+ }
21
+ if (poolOffset + 8 > pool.length)
22
+ refillPool();
23
+ const off = poolOffset;
24
+ poolOffset += 8;
25
+ const r2 = pool[off + 0];
26
+ const r3 = pool[off + 1];
27
+ const r4 = pool[off + 2];
28
+ const r5 = pool[off + 3];
29
+ const r6 = pool[off + 4];
30
+ const r7 = pool[off + 5];
31
+ const r8 = pool[off + 6];
32
+ const r9 = pool[off + 7];
33
+ const ts = lastTs;
34
+ const hi = (ts / 65536) >>> 0;
35
+ const lo = ts & 0xffff;
36
+ const randA_hi = seq >>> 8;
37
+ const randA_lo = seq & 0xff;
38
+ return (HEX[(hi >>> 24) & 0xff] +
39
+ HEX[(hi >>> 16) & 0xff] +
40
+ HEX[(hi >>> 8) & 0xff] +
41
+ HEX[hi & 0xff] +
42
+ "-" +
43
+ HEX[(lo >>> 8) & 0xff] +
44
+ HEX[lo & 0xff] +
45
+ "-" +
46
+ HEX[(0x70 | randA_hi) & 0xff] +
47
+ HEX[randA_lo] +
48
+ "-" +
49
+ HEX[(r2 & 0x3f) | 0x80] +
50
+ HEX[r3] +
51
+ "-" +
52
+ HEX[r4] +
53
+ HEX[r5] +
54
+ HEX[r6] +
55
+ HEX[r7] +
56
+ HEX[r8] +
57
+ HEX[r9]);
58
+ }
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "fastv7",
3
+ "version": "1.0.0",
4
+ "description": "Fast UUID v7 generator with monotonic ordering",
5
+ "type": "module",
6
+ "main": "./dist/fastv7.js",
7
+ "module": "./dist/fastv7.js",
8
+ "types": "./dist/fastv7.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/fastv7.d.ts",
12
+ "import": "./dist/fastv7.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsc",
20
+ "test": "vitest run",
21
+ "test:watch": "vitest",
22
+ "prepublishOnly": "npm run build"
23
+ },
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/danew/fastv7.git"
27
+ },
28
+ "homepage": "https://github.com/danew/fastv7#readme",
29
+ "bugs": {
30
+ "url": "https://github.com/danew/fastv7/issues"
31
+ },
32
+ "keywords": [
33
+ "uuid",
34
+ "uuidv7",
35
+ "uuid-v7",
36
+ "monotonic",
37
+ "fast",
38
+ "id",
39
+ "identifier"
40
+ ],
41
+ "author": "Dane Wilson",
42
+ "license": "MIT",
43
+ "devDependencies": {
44
+ "typescript": "^5.7.2",
45
+ "vitest": "^2.1.8"
46
+ },
47
+ "engines": {
48
+ "node": ">=18"
49
+ },
50
+ "sideEffects": false
51
+ }