+13
-8
@@ -11,10 +11,15 @@ import { webcrypto as crypto } from 'node:crypto' | ||
| function fillPool(bytes) { | ||
| if (bytes < 0 || bytes > 1024) throw new RangeError('Wrong ID size') | ||
| if (!pool || pool.length < bytes) { | ||
| pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER) | ||
| crypto.getRandomValues(pool) | ||
| poolOffset = 0 | ||
| } else if (poolOffset + bytes > pool.length) { | ||
| crypto.getRandomValues(pool) | ||
| poolOffset = 0 | ||
| if (bytes < 0) throw new RangeError('Wrong ID size') | ||
| try { | ||
| if (!pool || pool.length < bytes) { | ||
| pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER) | ||
| crypto.getRandomValues(pool) | ||
| poolOffset = 0 | ||
| } else if (poolOffset + bytes > pool.length) { | ||
| crypto.getRandomValues(pool) | ||
| poolOffset = 0 | ||
| } | ||
| } catch (e) { | ||
| pool = undefined | ||
| throw e | ||
| } | ||
@@ -21,0 +26,0 @@ poolOffset += bytes |
+1
-1
| { | ||
| "name": "nanoid", | ||
| "version": "5.1.14", | ||
| "version": "5.1.15", | ||
| "description": "A tiny (118 bytes), secure URL-friendly unique string ID generator", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
13632
0.45%340
1.49%