-
-
Notifications
You must be signed in to change notification settings - Fork 0
unifiers matchTypeOf()
Eugene Lazutkin edited this page Apr 3, 2026
·
3 revisions
Matches values based on their JavaScript type (typeof result).
This unifier matches values against type names returned by typeof. Can match a single type or multiple types.
import matchTypeOf from 'deep6/unifiers/matchTypeOf.js';
import unify from 'deep6/unify.js';
unify('hello', matchTypeOf('string')); // truthy
unify(42, matchTypeOf('string')); // false
unify(42, matchTypeOf(['string', 'number'])); // truthyArguments:
-
types— a required type name string or array of type name strings. Valid types are:'string','number','boolean','undefined','object','function','symbol','bigint'.
Returns a MatchTypeOf unifier instance.
Extends Unifier.
-
types— array of type names to match against.
-
unify(val, ls, rs)— checks iftypeof valis in the types array.- Returns
trueif the type matches. - Returns
falseifvalis a Variable or type doesn't match.
- Returns
import matchTypeOf from 'deep6/unifiers/matchTypeOf.js';
import {match} from 'deep6';
// Match primitive types
const isPrimitive = matchTypeOf(['string', 'number', 'boolean', 'bigint']);
match(42, isPrimitive); // true
match('hello', isPrimitive); // true
match({}, isPrimitive); // false
// Match any object type
const isObject = matchTypeOf('object');
match({}, isObject); // true
match(null, isObject); // true (typeof null === 'object')