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