Repository navigation
feat: add matches and isMatch functions - #386
Merged
Merged
Conversation
- SameValueZero for primitives - Type guards for Date/RegExp/Map/Set - DFS for Set matching - Array partial match
…ymbolKeys - Use DeepPartial<T> & RejectSymbolKeys<T> for partial matching and Symbol rejection - Add DeepWiden<T> to widen literals to base types
matches() iterated only the pattern's top-level entries, so a top-level Date/RegExp/Map/Set/Array/primitive pattern (which has no enumerable string keys) matched every input vacuously. Delegate those to isMatch so they are compared by value, while keeping a fast path for the common plain-object pattern that hoists Object.keys out of the predicate hot path (~2.5x faster than always delegating on a 100k-item filter).
ppeeou
added a commit
that referenced
this pull request
Jun 17, 2026
* feat: add isMatch function * feat: add matches function * feat: add matches and isMatch spec description * fix: correct isMatch for NaN, types, Set/Array - SameValueZero for primitives - Type guards for Date/RegExp/Map/Set - DFS for Set matching - Array partial match * fix: enhance pattern type safety with DeepPartial, DeepWiden, RejectSymbolKeys - Use DeepPartial<T> & RejectSymbolKeys<T> for partial matching and Symbol rejection - Add DeepWiden<T> to widen literals to base types * docs: add Symbol key handling details and new examples to matches and isMatch docs * docs: align isMatch array matching descriptions * fix: compare top-level non-object patterns in matches by value matches() iterated only the pattern's top-level entries, so a top-level Date/RegExp/Map/Set/Array/primitive pattern (which has no enumerable string keys) matched every input vacuously. Delegate those to isMatch so they are compared by value, while keeping a fast path for the common plain-object pattern that hoists Object.keys out of the predicate hot path (~2.5x faster than always delegating on a 100k-item filter). Co-authored-by: boy672820 <boy672820@gmail.com>
This was referenced Aug 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #380
Based on the original PR #383 (@boy672820), with an added bug fix for
top-level non-object patterns in
matchesand a hot-path performanceimprovement.
Summary
matches— creates a predicate that checks whether an input matchesall properties in a pattern
isMatch— performs a partial deep comparison between two valuesFeatures
order-independent)
filter,find,some, andeveryAdditional changes (on top of the original PR)
matchesonly iterated the pattern's top-level entries, so atop-level
Date/RegExp/Map/Set/Array/primitive pattern (which has noenumerable string keys) matched every input vacuously.
e.g. previously
matches(new Date("2024"))(new Date("2025")) === true→now
false.isMatch, while the common plain-object pattern uses a fast path thathoists
Object.keysout of the predicate (computed once at predicatecreation instead of on every call) — ~2.5x faster than always delegating
on a 100k-item
filter.contract, consistency with
isMatch).