Skip to main content
Module

x/pazza/mod.ts>satisfy

Parser combinators library designed for Deno, but also works on browsers and Node.js.
Go to Latest
function satisfy
import { satisfy } from "https://deno.land/x/pazza@v0.3.0/mod.ts";

Pick next character from input and pass it to provided predicate. If the predicate passes, return a successful parsing result with that character. If not, return a parsing error.

satisfy((char) => char === "a")("a").output === "a";
satisfy((char) => char === "a")("b").ok === false;

Type Parameters

I extends string

Parameters

predicate: (item: I[0]) => boolean

predicate which tests next character

Returns

IParser<I[0], ErrorKind.Satisfy, I>

Pick next byte from input and pass it to provided predicate. If the predicate passes, return a successful parsing result with that byte. If not, return a parsing error.

satisfy((byte) => byte === 10)(Uint8Array.of(10)).output === 10;
satisfy((byte) => byte === 10)(Uint8Array.of(13)).ok === false;

Type Parameters

I extends Uint8Array

Parameters

predicate: (item: I[0]) => boolean

predicate which tests next byte (8-bit unsigned integer)

Returns

IParser<I[0], ErrorKind.Satisfy, I>