ai / nanoid

A tiny (124 bytes), secure, URL-friendly, unique string ID generator for JavaScript
https://zelark.github.io/nano-id-cc/
MIT License
24.33k stars 788 forks source link

Documentation should reflect that customAlphabet is a generator #377

Closed theredwillow closed 2 years ago

theredwillow commented 2 years ago

The readme states that "customAlphabet allows you to create nanoid with your own alphabet and ID size."

This language is not inherently obvious that it is a generator (i.e. a function that creates a function).

The example does help, but this is such a commonly used function that I believe many people will accidentally look over the call (i.e. ()) used.

import { customAlphabet } from 'nanoid'
const nanoid = customAlphabet('1234567890abcdef', 10)
model.id = nanoid() //=> "4f90d13a42"
ai commented 2 years ago

What changes do you suggest?

theredwillow commented 2 years ago

"customAlphabet returns a function that allows you to create nanoid with your own alphabet and ID size"

ai commented 2 years ago

Sure! Good suggestion. Please send PR to save your name in the project’s history.

theredwillow commented 2 years ago

https://github.com/ai/nanoid/pull/378

ai commented 2 years ago

Thanks