Skip to main content
Module

x/ts_matches/src/parsers/nill-parser.ts

Being able to pattern match in typescript
Go to Latest
File
import { IParser, OnParse } from "./interfaces.ts";export class NilParser implements IParser<unknown, null | undefined> { constructor( readonly description = { name: "Null", children: [], extras: [], } as const, ) {} parse<C, D>( a: unknown, onParse: OnParse<unknown, null | undefined, C, D>, ): C | D { if (a === null || a === undefined) return onParse.parsed(a);
return onParse.invalid({ value: a, keys: [], parser: this, }); }}