From c922c7d5321c9db96112eb5e96a6a5a250fb0d8a Mon Sep 17 00:00:00 2001 From: Simon Holloway Date: Wed, 10 Jan 2024 15:47:11 +0000 Subject: [PATCH] refactor(ulid): prepare for `noUncheckedIndexedAccess` --- ulid/_util.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ulid/_util.ts b/ulid/_util.ts index d4a9af71b8a1..ab8383140bbb 100644 --- a/ulid/_util.ts +++ b/ulid/_util.ts @@ -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; } @@ -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]!); continue; } - return replaceCharAt(str, index, ENCODING[charIndex + 1]); + return replaceCharAt(str, index, ENCODING[charIndex + 1]!); } throw new Error("cannot increment this string"); }