@nichoth/nanoid
Advanced tools
Comparing version 5.0.7 to 5.0.8
# Change Log | ||
This project adheres to [Semantic Versioning](http://semver.org/). | ||
## 5.0.5 | ||
* Make browser’s version faster by increasing size a little (by Samuel Elgozi). | ||
## 5.0.4 | ||
@@ -5,0 +8,0 @@ * Fixed CLI docs (by @ilyaboka). |
// This file replaces `index.js` in bundlers like webpack or Rollup, | ||
// according to `browser` config in `package.json`. | ||
import { urlAlphabet } from './url-alphabet/index.js' | ||
export { urlAlphabet } from './url-alphabet/index.js' | ||
@@ -50,23 +52,12 @@ | ||
export let nanoid = (size = 21) => | ||
crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => { | ||
// It is incorrect to use bytes exceeding the alphabet size. | ||
// The following mask reduces the random byte in the 0-255 value | ||
// range to the 0-63 value range. Therefore, adding hacks, such | ||
// as empty string fallback or magic numbers, is unneccessary because | ||
// the bitmask trims bytes down to the alphabet size. | ||
byte &= 63 | ||
if (byte < 36) { | ||
// `0-9a-z` | ||
id += byte.toString(36) | ||
} else if (byte < 62) { | ||
// `A-Z` | ||
id += (byte - 26).toString(36).toUpperCase() | ||
} else if (byte > 62) { | ||
id += '-' | ||
} else { | ||
id += '_' | ||
} | ||
return id | ||
}, '') | ||
export let nanoid = (size = 21) => { | ||
let id = '' | ||
let bytes = crypto.getRandomValues(new Uint8Array(size)) | ||
while (size--) { | ||
// Using the bitwise AND operator to "cap" the value of | ||
// the random byte from 255 to 63, in that way we can make sure | ||
// that the value will be a valid index for the "chars" string. | ||
id += urlAlphabet[bytes[size] & 63] | ||
} | ||
return id | ||
} |
@@ -1,1 +0,1 @@ | ||
export let nanoid=(t=21)=>crypto.getRandomValues(new Uint8Array(t)).reduce(((t,e)=>t+=(e&=63)<36?e.toString(36):e<62?(e-26).toString(36).toUpperCase():e>62?"-":"_"),""); | ||
let a="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";export let nanoid=(e=21)=>{let t="",r=crypto.getRandomValues(new Uint8Array(e));for(let n=0;n<e;n++)t+=a[63&r[n]];return t}; |
{ | ||
"name": "@nichoth/nanoid", | ||
"version": "5.0.7", | ||
"description": "A tiny (109 bytes), secure URL-friendly unique string ID generator", | ||
"version": "5.0.8", | ||
"description": "A tiny (116 bytes), secure URL-friendly unique string ID generator", | ||
"keywords": [ | ||
@@ -17,4 +17,3 @@ "uuid", | ||
"test:size": "pnpm clean && size-limit", | ||
"test": "pnpm run /^test:/", | ||
"postversion": "git push && git push --tags && npm publish" | ||
"test": "pnpm run /^test:/" | ||
}, | ||
@@ -33,3 +32,3 @@ "type": "module", | ||
"license": "MIT", | ||
"repository": "github:nichoth/nanoid", | ||
"repository": "ai/nanoid", | ||
"exports": { | ||
@@ -46,9 +45,7 @@ ".": { | ||
}, | ||
"bin": { | ||
"@nichoth/nanoid": "./bin/nanoid.js" | ||
}, | ||
"bin": "./bin/nanoid.js", | ||
"sideEffects": false, | ||
"types": "./index.d.ts", | ||
"devDependencies": { | ||
"@babel/core": "^7.23.5", | ||
"@babel/core": "^7.23.9", | ||
"@logux/eslint-config": "^52.0.2", | ||
@@ -58,13 +55,13 @@ "@lukeed/uuid": "^2.0.1", | ||
"@originjs/vite-plugin-commonjs": "^1.0.3", | ||
"@size-limit/file": "^11.0.0", | ||
"@size-limit/webpack": "^11.0.0", | ||
"@types/node": "^20.10.3", | ||
"@size-limit/file": "^11.0.2", | ||
"@size-limit/webpack": "^11.0.2", | ||
"@types/node": "^20.11.16", | ||
"benchmark": "^2.1.4", | ||
"better-node-test": "^0.4.1", | ||
"c8": "^8.0.1", | ||
"better-node-test": "^0.5.0", | ||
"c8": "^9.1.0", | ||
"clean-publish": "^4.2.0", | ||
"eslint": "^8.55.0", | ||
"eslint": "^8.56.0", | ||
"eslint-config-standard": "^17.1.0", | ||
"eslint-plugin-import": "^2.29.0", | ||
"eslint-plugin-n": "^16.3.1", | ||
"eslint-plugin-import": "^2.29.1", | ||
"eslint-plugin-n": "^16.6.2", | ||
"eslint-plugin-node-import": "^1.0.4", | ||
@@ -78,8 +75,8 @@ "eslint-plugin-perfectionist": "^2.5.0", | ||
"shortid": "^2.2.16", | ||
"size-limit": "^11.0.0", | ||
"terser": "^5.25.0", | ||
"size-limit": "^11.0.2", | ||
"terser": "^5.27.0", | ||
"uid": "^2.0.2", | ||
"uid-safe": "^2.1.5", | ||
"uuid": "^9.0.1", | ||
"vite": "^5.0.5" | ||
"vite": "^5.0.12" | ||
}, | ||
@@ -90,3 +87,3 @@ "size-limit": [ | ||
"import": "{ nanoid }", | ||
"limit": "109 B" | ||
"limit": "116 B" | ||
}, | ||
@@ -93,0 +90,0 @@ { |
@@ -13,3 +13,3 @@ # Nano ID | ||
- **Ringan.** Hanya 109 bytes (diperkecil dan brotlied). Tidak ada ketergantungan (dependencies) apapun. [Size Limit](https://github.com/ai/size-limit) mengatur ukuran dari generator ini. | ||
- **Ringan.** Hanya 116 bytes (diperkecil dan brotlied). Tidak ada ketergantungan (dependencies) apapun. [Size Limit](https://github.com/ai/size-limit) mengatur ukuran dari generator ini. | ||
- **Aman.** Nano ID menggunakan RNG yang terdapat pada perangkat keras. Dapat digunakan dalam lingkungan seperti klaster. | ||
@@ -16,0 +16,0 @@ - **ID yang pendek.** Nano ID menggunakan alfabet yang lebih banyak ketimbang UUID (`A-Za-z0-9_-`), karenanya ukuran ID menjadi berkurang dari 36 menjadi 21 simbol. |
@@ -13,3 +13,3 @@ # Nano ID | ||
* **Small.** 109 bytes (minified and brotlied). No dependencies. | ||
* **Small.** 116 bytes (minified and brotlied). No dependencies. | ||
[Size Limit] controls the size. | ||
@@ -37,4 +37,2 @@ * **Safe.** It uses hardware random generator. Can be used in clusters. | ||
## fork | ||
This is a fork of [ai/nanoid](https://github.com/ai/nanoid); it is functionally equivalent. | ||
@@ -41,0 +39,0 @@ ## Table of Contents |
@@ -14,3 +14,3 @@ # Nano ID | ||
- **Лёгкий.** 109 байт (после минификации и Brotli). Без зависимостей. | ||
- **Лёгкий.** 116 байт (после минификации и Brotli). Без зависимостей. | ||
[Size Limit] следит за размером. | ||
@@ -17,0 +17,0 @@ - **Безопасный.** Использует аппаратный генератор случайных чисел. |
@@ -12,3 +12,3 @@ # Nano ID | ||
* **小巧.** 109字节 (经过压缩和Brotli处理)。没有依赖。[Size Limit] 控制大小。 | ||
* **小巧.** 116字节 (经过压缩和Brotli处理)。没有依赖。[Size Limit] 控制大小。 | ||
* **安全.** 它使用硬件随机生成器。可在集群中使用。 | ||
@@ -15,0 +15,0 @@ * **紧凑.** 它使用比 UUID(`A-Za-z0-9_-`)更大的字母表。因此,ID 大小从36个符号减少到21个符号。 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
85211
326
445