Skip to main content
Module

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

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