Skip to main content
Module

x/rimbu/mod.ts>match

Rimbu is a TypeScript library focused on immutable, performant, and type-safe collections and other tools.
Go to Latest
function match
import { match } from "https://deno.land/x/rimbu@0.11.6/mod.ts";

Returns true if the given value object matches the given matcher, false otherwise.

Examples

Example 1

const input = { a: 1, b: { c: true, d: 'a' } }
match(input, { a: 1 }) // => true
match(input, { a: 2 }) // => false
match(input, { a: v => v > 10 }) // => false
match(input, { b: { c: true }}) // => true
match(input, ({ every }) => every({ a: v => v > 0 }, { b: { c: true } } )) // => true
match(input, { b: { c: (v, parent, root) => v && parent.d.length > 0 && root.a > 0 } })
 // => true

Parameters

value: T & PlainObj<T>
  • the value to match (should be a plain object)
matcher: Match<T> | ((matchApi: Match.Api) => Match<T>)
  • a matcher object or a function taking the matcher API and returning a match object

Returns

boolean