source: trip-planner-front/node_modules/nanoid/async/index.native.js@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 759 bytes
Line 
1import { getRandomBytesAsync } from 'expo-random'
2import { urlAlphabet } from '../url-alphabet/index.js'
3let random = getRandomBytesAsync
4let customAlphabet = (alphabet, size) => {
5 let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
6 let step = Math.ceil((1.6 * mask * size) / alphabet.length)
7 let tick = id =>
8 random(step).then(bytes => {
9 let i = step
10 while (i--) {
11 id += alphabet[bytes[i] & mask] || ''
12 if (id.length === size) return id
13 }
14 return tick(id)
15 })
16 return () => tick('')
17}
18let nanoid = (size = 21) =>
19 random(size).then(bytes => {
20 let id = ''
21 while (size--) {
22 id += urlAlphabet[bytes[size] & 63]
23 }
24 return id
25 })
26export { nanoid, customAlphabet, random }
Note: See TracBrowser for help on using the repository browser.