Skip to main content
Module

x/fuzzy_octo_guacamole/is-matching.ts>isMatching

A playground for testing CI setup that deploys on Deno and NPM
Go to Latest
function isMatching
import { isMatching } from "https://deno.land/x/fuzzy_octo_guacamole@v2.0.0/is-matching.ts";

isMatching takes pattern and returns a type guard function, cheching if a value matches this pattern.

Read isMatching documentation on GitHub

Examples

const hasName = isMatching({ name: P.string })

declare let input: unknown

if (hasName(input)) { // input inferred as { name: string } return input.name }

Type Parameters

p extends Pattern<any>

Parameters

pattern: p

Returns

(value: any) => value is MatchedValue<any, P.infer<p>>

isMatching takes pattern and a value and checks if the value matches this pattern.

Read isMatching documentation on GitHub

Examples

declare let input: unknown

if (isMatching({ name: P.string }, input)) { // input inferred as { name: string } return input.name }

Type Parameters

p extends Pattern<any>

Parameters

pattern: p
value: any

Returns

value is MatchedValue<any, P.infer<p>>