Skip to content

JSTypeChecker

A JS Type Checker with protection levels.

Diagram

100%Ctrl + wheel to zoom

Properties

This class exposes no public properties.

Methods

.setProtectionLevel(level: ProtectionLevel)

ArgumentTypeDescription
levelProtectionLevelSet validation strictness.

.getProtectionLevel()

Returns the current ProtectionLevel.

.for(args: unknown[])

ArgumentTypeDescription
argsunknown[]Values to validate.

Returns an object with:

ts
{
  check: (types: JSTypeOrArray[]) => boolean;
}

References

.addCustomHandler(name: string, handler: (value: unknown) => boolean)

ArgumentTypeDescription
namestringHandler name.
handler(value: unknown) => booleanType-check function.

Registers a custom type handler.

Example

ts
const checker = new JSTypeChecker();
checker.setProtectionLevel("boundary");
checker.addCustomHandler("positiveNumber", (value) => typeof value === "number" && value > 0);
const isValid = checker.for([42]).check(["positiveNumber"]); // true