diff --git a/src/async/serializeAsync.ts b/src/async/serializeAsync.ts index f2e63c7f..3f8e6dd8 100644 --- a/src/async/serializeAsync.ts +++ b/src/async/serializeAsync.ts @@ -1,6 +1,6 @@ import { TsonCircularReferenceError } from "../errors.js"; import { assert } from "../internals/assert.js"; -import { GetNonce, getNonceDefault } from "../internals/getNonce.js"; +import { GetNonce, getDefaultNonce } from "../internals/getNonce.js"; import { mapOrReturn } from "../internals/mapOrReturn.js"; import { TsonAllTypes, @@ -192,7 +192,7 @@ type TsonAsyncSerializer = ( export function createAsyncTsonSerialize( opts: TsonAsyncOptions, ): TsonAsyncSerializer { - const getNonce: GetNonce = (opts.nonce ?? getNonceDefault) as GetNonce; + const getNonce: GetNonce = (opts.nonce ?? getDefaultNonce) as GetNonce; return (value) => { const nonce = getNonce(); const [walk, iterator] = walkerFactory(nonce, opts.types); diff --git a/src/internals/getNonce.crypto.test.ts b/src/internals/getNonce.crypto.test.ts index d5beeaba..6022c36a 100644 --- a/src/internals/getNonce.crypto.test.ts +++ b/src/internals/getNonce.crypto.test.ts @@ -6,9 +6,9 @@ test("with crypto", async () => { global.crypto = { randomUUID: () => "test", } as any; - const { getNonceDefault } = await import("./getNonce.js"); + const { getDefaultNonce } = await import("./getNonce.js"); - expect(getNonceDefault()).toBe("test"); + expect(getDefaultNonce()).toBe("test"); global.crypto = before; }); diff --git a/src/internals/getNonce.nocrypto.test.ts b/src/internals/getNonce.nocrypto.test.ts index db6d2511..1d6f5022 100644 --- a/src/internals/getNonce.nocrypto.test.ts +++ b/src/internals/getNonce.nocrypto.test.ts @@ -5,9 +5,9 @@ test("without crypto", async () => { global.crypto = undefined as any; - const { getNonceDefault } = await import("./getNonce.js"); + const { getDefaultNonce } = await import("./getNonce.js"); - expect(getNonceDefault().length).toBeGreaterThan(20); + expect(getDefaultNonce().length).toBeGreaterThan(20); global.crypto = before; }); diff --git a/src/internals/getNonce.ts b/src/internals/getNonce.ts index 3d0ba006..e3b0abe4 100644 --- a/src/internals/getNonce.ts +++ b/src/internals/getNonce.ts @@ -4,7 +4,7 @@ const randomString = () => Math.random().toString(36).slice(2); export type GetNonce = () => TsonNonce; -export const getNonceDefault: GetNonce = +export const getDefaultNonce: GetNonce = typeof crypto === "object" && typeof crypto.randomUUID === "function" ? () => crypto.randomUUID() as TsonNonce : () => diff --git a/src/sync/serialize.ts b/src/sync/serialize.ts index 49809a46..bc1d2d6f 100644 --- a/src/sync/serialize.ts +++ b/src/sync/serialize.ts @@ -1,5 +1,5 @@ import { TsonCircularReferenceError } from "../errors.js"; -import { GetNonce, getNonceDefault } from "../internals/getNonce.js"; +import { GetNonce, getDefaultNonce } from "../internals/getNonce.js"; import { mapOrReturn } from "../internals/mapOrReturn.js"; import { TsonAllTypes, @@ -40,7 +40,7 @@ function getHandlers(opts: TsonOptions) { const getNonce: GetNonce = opts.nonce ? (opts.nonce as GetNonce) - : getNonceDefault; + : getDefaultNonce; return [getNonce, nonPrimitives, byPrimitive] as const; }