ptnm
v1.0.0
Published
Object Pattern Matching
Readme
ptnm
Object Pattern Matching
- zero production dependencies
- tiny code footprint
- production battle-tested in Pear
Usage
ptnm matches a pattern object against a message object.
A match succeeds when all enumerable own properties in the pattern exist in the message and are strictly equal, recursively.
Extra properties in the message are ignored.
- Non-coercive matching (
===) - Own properties only (non-enumerable/inherited pattern keys ignored)
- No cycle detection by design - do not pass circular objects
Include
const match = require('ptnm')import match from 'ptnm'Basic
match({ a: 1, b: 2 }, { a: 1 }) // trueNested
match(
{ a: { b: 1, c: 2 } },
{ a: { b: 1 } }
)
// trueMissing or unequal values
match(
{ a: 1 },
{ a: 2 }
)
// false
match(
{},
{ a: 1 }
)
// falseLicense
Apache-2.0
