JSTypeChecker
A JS Type Checker with protection levels.
Diagram
Properties
This class exposes no public properties.
Methods
.setProtectionLevel(level: ProtectionLevel)
| Argument | Type | Description |
|---|---|---|
level | ProtectionLevel | Set validation strictness. |
.getProtectionLevel()
Returns the current ProtectionLevel.
.for(args: unknown[])
| Argument | Type | Description |
|---|---|---|
args | unknown[] | Values to validate. |
Returns an object with:
ts
{
check: (types: JSTypeOrArray[]) => boolean;
}References
.addCustomHandler(name: string, handler: (value: unknown) => boolean)
| Argument | Type | Description |
|---|---|---|
name | string | Handler name. |
handler | (value: unknown) => boolean | Type-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