nanoid
Advanced tools
Comparing version 4.0.2 to 5.0.0
18
index.js
@@ -1,2 +0,1 @@ | ||
import { randomFillSync } from 'crypto' | ||
import { urlAlphabet } from './url-alphabet/index.js' | ||
@@ -6,9 +5,9 @@ export { urlAlphabet } | ||
let pool, poolOffset | ||
let fillPool = bytes => { | ||
function fillPool(bytes) { | ||
if (!pool || pool.length < bytes) { | ||
pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER) | ||
randomFillSync(pool) | ||
crypto.getRandomValues(pool) | ||
poolOffset = 0 | ||
} else if (poolOffset + bytes > pool.length) { | ||
randomFillSync(pool) | ||
crypto.getRandomValues(pool) | ||
poolOffset = 0 | ||
@@ -18,7 +17,7 @@ } | ||
} | ||
export let random = bytes => { | ||
export function random(bytes) { | ||
fillPool((bytes -= 0)) | ||
return pool.subarray(poolOffset - bytes, poolOffset) | ||
} | ||
export let customRandom = (alphabet, defaultSize, getRandom) => { | ||
export function customRandom(alphabet, defaultSize, getRandom) { | ||
let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1 | ||
@@ -38,5 +37,6 @@ let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length) | ||
} | ||
export let customAlphabet = (alphabet, size = 21) => | ||
customRandom(alphabet, size, random) | ||
export let nanoid = (size = 21) => { | ||
export function customAlphabet(alphabet, size = 21) { | ||
return customRandom(alphabet, size, random) | ||
} | ||
export function nanoid(size = 21) { | ||
fillPool((size -= 0)) | ||
@@ -43,0 +43,0 @@ let id = '' |
{ | ||
"name": "nanoid", | ||
"version": "4.0.2", | ||
"version": "5.0.0", | ||
"description": "A tiny (116 bytes), secure URL-friendly unique string ID generator", | ||
@@ -13,3 +13,3 @@ "keywords": [ | ||
"engines": { | ||
"node": "^14 || ^16 || >=18" | ||
"node": "^18 || >=20" | ||
}, | ||
@@ -30,6 +30,2 @@ "funding": [ | ||
}, | ||
"./async": { | ||
"browser": "./async/index.browser.js", | ||
"default": "./async/index.js" | ||
}, | ||
"./non-secure": "./non-secure/index.js", | ||
@@ -39,8 +35,4 @@ "./package.json": "./package.json" | ||
"browser": { | ||
"./index.js": "./index.browser.js", | ||
"./async/index.js": "./async/index.browser.js" | ||
"./index.js": "./index.browser.js" | ||
}, | ||
"react-native": { | ||
"./async/index.js": "./async/index.native.js" | ||
}, | ||
"bin": "./bin/nanoid.js", | ||
@@ -47,0 +39,0 @@ "sideEffects": false, |
@@ -6,4 +6,2 @@ # Nano ID | ||
**English** | [Русский](./README.ru.md) | [简体中文](./README.zh-CN.md) | [Bahasa Indonesia](./README.id-ID.md) | ||
A tiny, secure, URL-friendly, unique string ID generator for JavaScript. | ||
@@ -20,3 +18,3 @@ | ||
* **Portable.** Nano ID was ported | ||
to [20 programming languages](./README.md#other-programming-languages). | ||
to over [20 programming languages](./README.md#other-programming-languages). | ||
@@ -28,4 +26,8 @@ ```js | ||
Supports modern browsers, IE [with Babel], Node.js and React Native. | ||
--- | ||
<img src="https://cdn.evilmartians.com/badges/logo-no-label.svg" alt="" width="22" height="16" /> Made in <b><a href="https://evilmartians.com/?utm_source=nanoid&utm_campaign=devtools-button&utm_medium=github">Evil Martians</a></b>, product consulting for <b>developer tools</b>. | ||
--- | ||
[online tool]: https://gitpod.io/#https://github.com/ai/nanoid/ | ||
@@ -35,8 +37,4 @@ [with Babel]: https://developer.epages.com/blog/coding/how-to-transpile-node-modules-with-babel-and-webpack-in-a-monorepo/ | ||
<a href="https://evilmartians.com/?utm_source=nanoid"> | ||
<img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" | ||
alt="Sponsored by Evil Martians" width="236" height="54"> | ||
</a> | ||
## Docs | ||
Read full docs **[here](https://github.com/ai/nanoid#readme)**. |
10717
11
265
37