Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/rimbu/deep/internal.ts>Deep.match

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

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', { a: (v) => v > 0 }, { b: { c: true } }]) // => true
match(input, { b: { c: (v, parent, root) => v && parent.d.length > 0 && root.a > 0 } })
 // => true

Type Parameters

T
optional
C extends Partial<T> = Partial<T>

Parameters

source: T
  • the value to match (should be a plain object)
matcher: Match<T, C>
  • a matcher object or a function taking the matcher API and returning a match object
optional
failureLog: Match.FailureLog
  • (optional) a string array that can be passed to collect reasons why the match failed

Returns

boolean