-
-
Notifications
You must be signed in to change notification settings - Fork 0
unifiers matchInstanceOf()
Eugene Lazutkin edited this page Apr 3, 2026
·
3 revisions
Matches values based on instanceof checks.
This unifier matches values against constructors using the instanceof operator. Can match a single constructor or multiple constructors.
import matchInstanceOf from 'deep6/unifiers/matchInstanceOf.js';
import unify from 'deep6/unify.js';
unify(new Date(), matchInstanceOf(Date)); // truthy
unify([], matchInstanceOf(Array)); // truthy
unify([], matchInstanceOf([Array, Set, Map])); // truthyArguments:
-
types— a required constructor function or array of constructor functions to check against.
Returns a MatchInstanceOf unifier instance.
Extends Unifier.
-
types— array of constructors to match against.
-
unify(val, ls, rs)— checks ifval instanceof Typefor any type.- Returns
trueifvalis an instance of any configured type. - Returns
falseifvalis falsy, a Variable, or not an instance.
- Returns
import matchInstanceOf from 'deep6/unifiers/matchInstanceOf.js';
import {match} from 'deep6';
// Match Date instances
match(new Date(), matchInstanceOf(Date)); // true
match('2024-01-01', matchInstanceOf(Date)); // false
// Match collection types
const isCollection = matchInstanceOf([Array, Set, Map]);
match([], isCollection); // true
match(new Set(), isCollection); // true
match({}, isCollection); // false
// Match custom classes
class User {}
class Admin {}
const isUserType = matchInstanceOf([User, Admin]);
match(new User(), isUserType); // true
match(new Admin(), isUserType); // true