Skip to content

Commit 8276496

Browse files
committed
fix(core): avoid BigInt literals in decodeKsuid for pre-ES2020 consumers
Consumer packages (e.g. @internal/zod-worker) typecheck core's source under a target below ES2020, where BigInt literals (123n) raise TS2737. Use BigInt(...) calls, which those targets accept.
1 parent 3bc28f5 commit 8276496

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

packages/core/src/v3/isomorphic/friendlyId.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,19 @@ export function decodeKsuid(idOrFriendlyId: string): DecodedKsuid {
9393
);
9494
}
9595

96-
let n = 0n;
96+
let n = BigInt(0);
9797
for (const ch of body) {
9898
const digit = BASE62_ALPHABET.indexOf(ch);
9999
if (digit < 0) {
100100
throw new Error(`Invalid base62 character in KSUID body: ${ch}`);
101101
}
102-
n = n * 62n + BigInt(digit);
102+
n = n * BigInt(62) + BigInt(digit);
103103
}
104104

105105
const bytes = new Uint8Array(KSUID_TOTAL_BYTES);
106106
for (let i = KSUID_TOTAL_BYTES - 1; i >= 0; i--) {
107-
bytes[i] = Number(n & 0xffn);
108-
n >>= 8n;
107+
bytes[i] = Number(n & BigInt(0xff));
108+
n >>= BigInt(8);
109109
}
110110

111111
const timestampSeconds =

0 commit comments

Comments
 (0)