match-conditions

Match a condition object against a key-value collection using a domain specific syntax.

Usage no npm install needed!

<script type="module">
  import matchConditions from 'https://cdn.skypack.dev/match-conditions';
</script>

README

match-conditions

Match a set of conditions for a collection of key-value pairs. Conditions are able to access nested keys.

Install

yarn add match-conditions

Usage

import { normalizeCondition, matchValuesWithCondition } from 'match-conditions'

// true
matchValuesWithCondition(
  normalizeCondition({
    a: '2'
  }),
  {
    a: '2'
  }
)

// false
matchValuesWithCondition(
  normalizeCondition({
    a: '3'
  }),
  {
    a: '2'
  }
)

// true
matchValuesWithCondition(
  normalizeCondition({
    any: {
      a: '3 | 2',
      b: 'c'
    }
  }),
  {
    a: '2',
    b: 'a'
  }
)