(prefix: keyof typeof prefixes, direction: "descending" | "ascending", given?: string)
| 28 | } |
| 29 | |
| 30 | function generateID(prefix: keyof typeof prefixes, direction: "descending" | "ascending", given?: string): string { |
| 31 | if (!given) { |
| 32 | return create(prefixes[prefix], direction) |
| 33 | } |
| 34 | |
| 35 | if (!given.startsWith(prefixes[prefix])) { |
| 36 | throw new Error(`ID ${given} does not start with ${prefixes[prefix]}`) |
| 37 | } |
| 38 | return given |
| 39 | } |
| 40 | |
| 41 | function randomBase62(length: number): string { |
| 42 | const chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" |
no test coverage detected