TypesCategory.ts overview
Enum classifying JavaScript values into ten runtime categories, plus a fromValue constructor and per-category predicates.
Mental model
Typehas 10 cases:String,Number,Bigint,Boolean,Symbol,Null,Undefined,Record,Array,Function.Recordis the computer-science meaning (a string-keyed object), not the TypeScriptRecord<K, V>utility — arrays and functions get their own categories despite being objects at the JS level.fromValuenormalizes any JavaScript value to one of these categories;isPrimitive/isNonPrimitivegroup the categories accordingly.
Common tasks
- Classify a value:
fromValue - Group test:
isPrimitive,isNonPrimitive - Per-category test:
isString,isNumber,isBigint,isBoolean,isSymbol,isNull,isUndefined,isFunction,isArray,isRecord
Quickstart
Example (Classify and dispatch on category)
import * as MTypesCategory from "@parischap/effect-lib/MTypesCategory"
console.log(MTypesCategory.fromValue("hi") === MTypesCategory.Type.String) // true
console.log(MTypesCategory.isNonPrimitive(MTypesCategory.fromValue([1, 2]))) // true
Exports Grouped by Category
Constructors
fromValue
Builds the category of u.
- Returns the matching
Typevariant for any JavaScript value. nulland arrays each get their own category, even thoughtypeofreports them as'object'.
Signature
declare const fromValue: (u: unknown) => Type
Predicates
isArray
Returns true if self represents an array. false otherwise
Signature
declare const isArray: Predicate.Predicate<Type>
isBigint
Returns true if self represents a bigint. false otherwise
Signature
declare const isBigint: Predicate.Predicate<Type>
isBoolean
Returns true if self represents a boolean. false otherwise
Signature
declare const isBoolean: Predicate.Predicate<Type>
isFunction
Returns true if self represents a function. false otherwise
Signature
declare const isFunction: Predicate.Predicate<Type>
isNonPrimitive
Returns true if self represents a non-primitive. false otherwise
Signature
declare const isNonPrimitive: Predicate.Predicate<Type>
isNull
Returns true if self is null. false otherwise
Signature
declare const isNull: Predicate.Predicate<Type>
isNumber
Returns true if self represents a number. false otherwise
Signature
declare const isNumber: Predicate.Predicate<Type>
isPrimitive
Returns true if self represents a primitive. false otherwise
Signature
declare const isPrimitive: Predicate.Predicate<Type>
isRecord
Returns true if self represents a record. false otherwise
Signature
declare const isRecord: Predicate.Predicate<Type>
isString
Returns true if self represents a string. false otherwise
Signature
declare const isString: Predicate.Predicate<Type>
isSymbol
Returns true if self represents a symbol. false otherwise
Signature
declare const isSymbol: Predicate.Predicate<Type>
isUndefined
Returns true if self is undefined. false otherwise
Signature
declare const isUndefined: Predicate.Predicate<Type>