(str: string)
| 60 | } |
| 61 | |
| 62 | export function incrementBase32(str: string): string { |
| 63 | let done: string | undefined = undefined, |
| 64 | index = str.length, |
| 65 | char: string, |
| 66 | charIndex: number, |
| 67 | output = str; |
| 68 | const maxCharIndex = ENCODING_LEN - 1; |
| 69 | while (!done && index-- >= 0) { |
| 70 | char = output[index]; |
| 71 | charIndex = ENCODING.indexOf(char); |
| 72 | if (charIndex === -1) { |
| 73 | throw new ULIDError( |
| 74 | ULIDErrorCode.Base32IncorrectEncoding, |
| 75 | "Incorrectly encoded string" |
| 76 | ); |
| 77 | } |
| 78 | if (charIndex === maxCharIndex) { |
| 79 | output = replaceCharAt(output, index, ENCODING[0]); |
| 80 | continue; |
| 81 | } |
| 82 | done = replaceCharAt(output, index, ENCODING[charIndex + 1]); |
| 83 | } |
| 84 | if (typeof done === "string") { |
| 85 | return done; |
| 86 | } |
| 87 | throw new ULIDError(ULIDErrorCode.Base32IncorrectEncoding, "Failed incrementing string"); |
| 88 | } |
no test coverage detected