Skip to content
Myr

Improve 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 9d29231 · Browse files · 2 files+39 added−15 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+39 added−15 removed

  • other:+39 added−15 removed

2 files+39 added−15 removed

modified:README-cn.md+27 added-2 removed
105 unmodified lines
106107[ID 碰撞概率计算器]: https://alex7kom.github.io/nano-nanoid-cc/108109110### React Native 和 Web Workers110### React Native111112React Native 和 Web Worker 无法获取安全的随机生成器。112```js113const generateSecureRandom = require('react-native-securerandom').generateSecureRandom114const format = require('nanoid/async/format')115const url = require('nanoid/url')116117async function createUser () {118 user.id = await format(generateSecureRandom, url, 21);119}120```121122123### Mongoose124125```js126const mySchema = new Schema({127 _id: {128 type: String,129 default: () => nanoid(10)130 }131})132```133134135### Web Workers136137Web Worker 无法获取安全的随机生成器。138139安全性对于 ID 来说是非常重要的,ID 应当是不可被预测的。比如说 “通过链接获取” 的链接生成。140141如果你不需要不可预测的 ID,但你需要支持 React Native 或 Web Workers,你可以使用不安全的 ID 生成器。142
99 unmodified lines
modified:README.md+12 added-13 removed
163 unmodified lines
164165[a native random generator]: https://github.com/rh389/react-native-securerandom166167168### Mongoose169170```js171const mySchema = new Schema({172 _id: {173 type: String,174 default: () => nanoid(10)175 }176})177```178179180### Web Workers181182Web Workers don’t have access to a secure random generator.183
109 unmodified lines
293 user.id = await format(random, url, 10)294}295```296285## Mongoose Unique Id286```js287const nanoId = require('nanoid');288const mongoose = require('mongoose');289const Schema = mongoose.Schema;290291const mySchema = new Schema({292 _id: {293 type: String,294 default: () => nanoId()295 }296}297```297## Tools298299* [ID size calculator] to choice smaller ID size depends on your case.300* [`nanoid-dictionary`] with popular alphabets to use with `nanoid/generate`.
29 unmodified lines