Skip to content
Myr

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 file

Take it

The walk stopped after 200 commits: lines older than cdc3edc point at it.

Add JSR supportAndrey Sitnikbefore adoption5014f1e

lines 1–2why, one step back
1/* @ts-self-types="./index.d.ts" */
2

Fix alphabet duplicationAndrey Sitnikbefore adoption0501d9c

line 3why, one step back
3import { urlAlphabet } from '../url-alphabet/index.js'

Update size limitAndrey Sitnikbefore adoptioncdc3edc

lines 4–8why, one step back
4
5export 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 back
9 // `> 0` stops a negative size from looping forever.

Update size limitAndrey Sitnikbefore adoptioncdc3edc

line 10why, one step back
10 let i = size | 0

fix(non-secure): clamp negative size with a smaller guard (#600)spokodevbefore adoption6de05d7

line 11why, one step back
11 while (i-- > 0) {

Update size limitAndrey Sitnikbefore adoptioncdc3edc

lines 12–21why, one step back
12 // `| 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 back
22 // `> 0` stops a negative size from looping forever.

Update size limitAndrey Sitnikbefore adoptioncdc3edc

line 23why, one step back
23 let i = size | 0

fix(non-secure): clamp negative size with a smaller guard (#600)spokodevbefore adoption6de05d7

line 24why, one step back
24 while (i-- > 0) {

Update size limitAndrey Sitnikbefore adoptioncdc3edc

lines 25–29why, one step back
25 // `| 0` is more compact and faster than `Math.floor()`.
26 id += urlAlphabet[(Math.random() * 64) | 0]27 }28 return id29}