Skip to content
Myr

Clean up docs

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Andrey Sitnik · committed by Andrey Sitnik · parent 9dcbd55 · Browse files · 2 files+55 added−23 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+55 added−23 removed

  • other:+55 added−23 removed

2 files+55 added−23 removed

modified:README.md+26 added-16 removed
39 unmodified lines
40- [Comparison with UUID](#comparison-with-uuid)41- [Benchmark](#benchmark)42- [Security](#security)43- [Install](#install)44 - [ESM](#esm)45 - [CommonJS](#commonjs)46 - [CDN](#cdn)47- [API](#api)48 - [Blocking](#blocking)49 - [Non-Secure](#non-secure)50 - [Custom Alphabet or Size](#custom-alphabet-or-size)
79 unmodified lines
130131132## Install133131```bash132npm install nanoid133```134134### ESM135136Nano ID 5 works with ESM projects (with `import`) in tests or Node.js scripts.137138For quick hacks, you can load Nano ID from CDN. Though, it is not recommended139to be used in production because of the lower loading performance.140141```js142import { nanoid } from 'https://cdn.jsdelivr.net/npm/nanoid/nanoid.js'138```bash139npm install nanoid140```141142### CommonJS146Nano ID 5 can be used with CommonJS in one of the following ways:143148- You can use `require()` to import Nano ID. You need to use latest Node.js 22.12 (works out-of-the-box) or Node.js 20 (with `--experimental-require-module`)144Nano ID can be used with CommonJS in one of the following ways:145146- You can use `require()` to import Nano ID. You need to use latest Node.js147 22.12 (works out-of-the-box) or Node.js 20148 (with `--experimental-require-module`).149150- For Node.js 16 or newer you can dynamically import Nano ID as follows:150- For Node.js 18 you can dynamically import Nano ID as follows:151152 ```js152 let nanoid;153 153 let nanoid154 module.exports.createID = async () => {155 if (!nanoid) ({ nanoid } = await import('nanoid'));156 const id = nanoid() // => "V1StGXR8_Z5jdHi6B-myT"155 if (!nanoid) ({ nanoid } = await import('nanoid'))156 return nanoid() // => "V1StGXR8_Z5jdHi6B-myT"157 }158 ```159160- You can use Nano ID 3.x (we still support it):161162 ```bash163 npm install nanoid@3164 ```165166### CDN167168For quick hacks, you can load Nano ID from CDN. Though, it is not recommended169to be used in production because of the lower loading performance.170171```js172import { nanoid } from 'https://cdn.jsdelivr.net/npm/nanoid/nanoid.js'173```174175## API176177Nano ID has 2 APIs: normal and non-secure.178
295 unmodified lines
modified:README.ru.md+29 added-7 removed
43 unmodified lines
44- [Сравнение с UUID](#сравнение-с-uuid)45- [Сравнение производительности](#сравнение-производительности)46- [Безопасность](#безопасность)47- [Подключение](#подключение)48 - [ESM](#esm)49 - [CommonJS](#commonjs)50 - [CDN](#cdn)51- [API](#api)52 - [Блокирующий](#блокирующий)53 - [Небезопасный](#небезопасный)54 - [Смена алфавита или длины](#смена-алфавита-или-длины)
82 unmodified lines
137138139## Подключение140141### ESM142143Nano ID 5 работает с ESM-проектами (`import`) в тестах или скриптах для Node.js.144145```bash146npm install nanoid147```148142Nano ID 5 работает с ESM-проектами (`import`) в тестах или скриптах для Node.js.143Для CommonJS `require()` вам нужна последняя версия Node.js 22.12144(работает из коробки) или Node.js 20 (с флагом `--experimental-require-module`):149### CommonJS150146Для Node.js 18 возьмите Nano ID 3.x (мы его всё ещё поддерживаем):151На проектах с CommonJS вы можете использовать:152148```bash149npm install nanoid@3150```153- `require()` будет работать в последней версия Node.js 22.12 (из коробки)154 или Node.js 20 (с флагом `--experimental-require-module`).155156- В более старых версиях Node.js можно использовать динамический импорт:157158 ```js159 let nanoid160 module.exports.createID = async () => {161 if (!nanoid) ({ nanoid } = await import('nanoid'))162 return nanoid() // => "V1StGXR8_Z5jdHi6B-myT"163 }164 ```165166- Или можно просто взять Nano ID 3.x (мы его всё ещё поддерживаем):167168 ```bash169 npm install nanoid@3170 ```171172### CDN173174Для быстрого прототипирования вы можете подключить Nano ID с CDN без установки.175Не используйте этот способ на реальном сайте, так как он сильно бьёт176по скорости загрузки сайта.177
272 unmodified lines