import { match } from "https://deno.land/x/rimbu@0.13.5/deep/index.ts";
Returns true if the given value
object matches the given matcher
, false otherwise.
Examples
Example 1
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
Parameters
source: T
- the value to match (should be a plain object)
- 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