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

Commit

Permalink
guard
Browse files Browse the repository at this point in the history
  • Loading branch information
KATT committed Sep 30, 2023
1 parent 4ac46ec commit b64f5a5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ export * from "./tsonRegExp.js";
export * from "./tsonSet.js";
export * from "./tsonMap.js";
export * from "./tsonUndefined.js";
export * from "./tsonUnknown.js";
export * from "./tsonUnknownObjectGuard.js";
export * from "./tsonNumber.js";
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ import { assert, expect, test } from "vitest";
import { expectError } from "../testUtils.js";
import { createTupleson } from "../tson.js";
import { tsonSet } from "./tsonSet.js";
import { UnknownObjectGuardError, tsonUnknown } from "./tsonUnknown.js";
import {
UnknownObjectGuardError,
tsonUnknownObjectGuard,
} from "./tsonUnknownObjectGuard.js";

test("guard unwanted objects", () => {
// Sets are okay, but not Maps
const t = createTupleson({
types: [
tsonSet,
// defined last so it runs last
tsonUnknown,
tsonUnknownObjectGuard,
],
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ export class UnknownObjectGuardError extends Error {
}
}

export const tsonUnknown: TsonType<unknown, never> = {
/**
* Guard against unknown complex objects
* @remark Make sure to define this last in the list of types

Check failure on line 16 in src/handlers/tsonUnknownObjectGuard.ts

View workflow job for this annotation

GitHub Actions / lint

Invalid JSDoc tag name "remark"
* @throws {UnknownObjectGuardError} if an unknown object is found
*/
export const tsonUnknownObjectGuard: TsonType<unknown, never> = {
test: (v) => {
if (v && typeof v === "object" && !Array.isArray(v) && !isPlainObject(v)) {
throw new UnknownObjectGuardError(v);
Expand Down

0 comments on commit b64f5a5

Please sign in to comment.