Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
get nonce
Browse files Browse the repository at this point in the history
  • Loading branch information
KATT committed Oct 2, 2023
1 parent 0e6b9f0 commit 86d3459
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/internals/getNonce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { TsonNonce } from "../types.js";

const randomString = () => Math.random().toString(36).slice(2);

type GetNonce = () => TsonNonce;
export type GetNonce = () => TsonNonce;

// istanbul ignore next
export const getNonce: GetNonce =
Expand Down
8 changes: 4 additions & 4 deletions src/serialize.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any, eslint-comments/disable-enable-pair */
import { CircularReferenceError } from "./errors.js";
import { getNonce } from "./internals/getNonce.js";
import { GetNonce, getNonce } from "./internals/getNonce.js";
import { mapOrReturn } from "./internals/mapOrReturn.js";
import {
TsonAllTypes,
Expand Down Expand Up @@ -123,10 +123,10 @@ export function createTsonSerialize(opts: TsonOptions): TsonSerializeFn {
return walk;
};

const nonceFn: GetNonce = opts.nonce ? (opts.nonce as GetNonce) : getNonce;

return ((obj): TsonSerialized => {
const nonce: TsonNonce = maybeNonce
? (maybeNonce() as TsonNonce)
: getNonce();
const nonce = nonceFn();

const json = walker(nonce)(obj);

Expand Down

0 comments on commit 86d3459

Please sign in to comment.