-
Notifications
You must be signed in to change notification settings - Fork 0
/
nanoid_custom.txt
57 lines (43 loc) · 996 Bytes
/
nanoid_custom.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* @HISTORY
* Created 08-28-2024 by Nick Cheatwood
*
* @PURPOSE
* Generates a nanoid using specified length and custom alphabet
*
* @NOTES
* See: https://github.com/ai/nanoid
*
* @PARAMETERS
* id_length: the length of the nanoid to be generated
* alphabet: the custom alphabet to use when generating the nanoid
*
* @USAGE
* nanoid_custom( 21 ; "_-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" )
*/
Let([
/* Length of the ID */
len = id_length;
/* Custom alphabet */
alphabet = alphabet;
/* Length of the custom alphabet */
charCount = Length ( alphabet );
/* Generate fn */
Generate = While (
/* Init variables */
[ i = 1 ; result = "" ];
/* Iterator (execute while this statement is truthy) */
i <= len;
[
/* Build nanoid using random character from alphabet */
result = result & Middle(alphabet; Int ( Random * charCount ) + 1 ; 1 );
/* Increment index */
i = i + 1
];
/* Result */
result
) /* End While() */
];
/* Generate nanoid */
Generate
)