index.js
This file
Path
non-secure/index.js
29 lines · 860 bytes · JavaScript
Last changed by
Fix alphabet duplicationAndrey Sitnikbefore adoption0501d9c
History of this fileTake it
The walk stopped after 200 commits: lines older than cdc3edc point at it.
Add JSR supportAndrey Sitnikbefore adoption5014f1e
lines 1–2why, one step back1/* @ts-self-types="./index.d.ts" */2Fix alphabet duplicationAndrey Sitnikbefore adoption0501d9c
line 3why, one step back3import { urlAlphabet } from '../url-alphabet/index.js'Update size limitAndrey Sitnikbefore adoptioncdc3edc
lines 4–8why, one step back45export let customAlphabet = (alphabet, defaultSize = 21) => {6 return (size = defaultSize) => {7 let id = ''8 // A compact alternative for `for (var i = 0; i < step; i++)`.fix(non-secure): clamp negative size with a smaller guard (#600)spokodevbefore adoption6de05d7
line 9why, one step back9 // `> 0` stops a negative size from looping forever.Update size limitAndrey Sitnikbefore adoptioncdc3edc
line 10why, one step back10 let i = size | 0fix(non-secure): clamp negative size with a smaller guard (#600)spokodevbefore adoption6de05d7
line 11why, one step back11 while (i-- > 0) {Update size limitAndrey Sitnikbefore adoptioncdc3edc
lines 12–21why, one step back12 // `| 0` is more compact and faster than `Math.floor()`.13 id += alphabet[(Math.random() * alphabet.length) | 0]14 }15 return id16 }17}1819export let nanoid = (size = 21) => {20 let id = ''21 // A compact alternative for `for (var i = 0; i < step; i++)`.fix(non-secure): clamp negative size with a smaller guard (#600)spokodevbefore adoption6de05d7
line 22why, one step back22 // `> 0` stops a negative size from looping forever.Update size limitAndrey Sitnikbefore adoptioncdc3edc
line 23why, one step back23 let i = size | 0fix(non-secure): clamp negative size with a smaller guard (#600)spokodevbefore adoption6de05d7
line 24why, one step back24 while (i-- > 0) {Update size limitAndrey Sitnikbefore adoptioncdc3edc
lines 25–29why, one step back25 // `| 0` is more compact and faster than `Math.floor()`.26 id += urlAlphabet[(Math.random() * 64) | 0]27 }28 return id29}