Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(ulid): prepare for noUncheckedIndexedAccess #4147

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions ulid/_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export function encodeTime(now: number, len: number = TIME_LEN): string {
export function encodeRandom(len: number): string {
let str = "";
const randomBytes = crypto.getRandomValues(new Uint8Array(len));
for (let i = 0; i < len; i++) {
str += ENCODING[randomBytes[i] % ENCODING_LEN];
for (const randomByte of randomBytes) {
str += ENCODING[randomByte % ENCODING_LEN];
}
return str;
}
Expand All @@ -43,16 +43,16 @@ export function incrementBase32(str: string): string {
let charIndex;
const maxCharIndex = ENCODING_LEN - 1;
while (--index >= 0) {
char = str[index];
char = str[index]!;
charIndex = ENCODING.indexOf(char);
if (charIndex === -1) {
throw new Error("incorrectly encoded string");
}
if (charIndex === maxCharIndex) {
str = replaceCharAt(str, index, ENCODING[0]);
str = replaceCharAt(str, index, ENCODING[0]!);
iuioiua marked this conversation as resolved.
Show resolved Hide resolved
continue;
}
return replaceCharAt(str, index, ENCODING[charIndex + 1]);
return replaceCharAt(str, index, ENCODING[charIndex + 1]!);
}
throw new Error("cannot increment this string");
}
Expand Down