Enter a search term above to see results...
On This Page
Types Utilities
The Types utilities provide a set of functions for checking and manipulating data types in JavaScript. These functions help in writing more robust and type-safe code.
Functions
isObject
function isObject(x)Checks if the given value is an object.
Parameters
| Name | Type | Description |
|---|---|---|
| x | any | Any value to check |
Returns
boolean - True if the value is an object, false otherwise.
Example
import { isObject } from '@semantic-ui/utils';
console.log(isObject({})); // trueconsole.log(isObject([])); // trueconsole.log(isObject(null)); // falseisPlainObject
function isPlainObject(x)Checks if the given value is a plain JavaScript object (created using object literal notation or Object.create(null)).
Parameters
| Name | Type | Description |
|---|---|---|
| x | any | Any value to check |
Returns
boolean - True if the value is a plain object, false otherwise.
Example
import { isPlainObject } from '@semantic-ui/utils';
console.log(isPlainObject({})); // trueconsole.log(isPlainObject([])); // falseconsole.log(isPlainObject(new Date())); // falseisString
function isString(x)Checks if the given value is a string.
Parameters
| Name | Type | Description |
|---|---|---|
| x | any | Any value to check |
Returns
boolean - True if the value is a string, false otherwise.
Example
import { isString } from '@semantic-ui/utils';
console.log(isString("hello")); // trueconsole.log(isString(new String("hello"))); // trueconsole.log(isString(123)); // falseisBoolean
function isBoolean(x)Checks if the given value is a boolean.
Parameters
| Name | Type | Description |
|---|---|---|
| x | any | Any value to check |
Returns
boolean - True if the value is a boolean, false otherwise.
Example
import { isBoolean } from '@semantic-ui/utils';
console.log(isBoolean(true)); // trueconsole.log(isBoolean(false)); // trueconsole.log(isBoolean(1)); // falseisNumber
function isNumber(x)Checks if the given value is a number.
Parameters
| Name | Type | Description |
|---|---|---|
| x | any | Any value to check |
Returns
boolean - True if the value is a number, false otherwise.
Example
import { isNumber } from '@semantic-ui/utils';
console.log(isNumber(123)); // trueconsole.log(isNumber(NaN)); // trueconsole.log(isNumber("123")); // falseisArray
function isArray(x)Checks if the given value is an array.
Parameters
| Name | Type | Description |
|---|---|---|
| x | any | Any value to check |
Returns
boolean - True if the value is an array, false otherwise.
Example
import { isArray } from '@semantic-ui/utils';
console.log(isArray([])); // trueconsole.log(isArray([1, 2, 3])); // trueconsole.log(isArray({})); // falseisBinary
function isBinary(x)Checks if the given value is a binary (Uint8Array).
Parameters
| Name | Type | Description |
|---|---|---|
| x | any | Any value to check |
Returns
boolean - True if the value is a binary, false otherwise.
Example
import { isBinary } from '@semantic-ui/utils';
console.log(isBinary(new Uint8Array())); // trueconsole.log(isBinary(new ArrayBuffer(8))); // falseisFunction
function isFunction(x)Checks if the given value is a function.
Parameters
| Name | Type | Description |
|---|---|---|
| x | any | Any value to check |
Returns
boolean - True if the value is a function, false otherwise.
Example
import { isFunction } from '@semantic-ui/utils';
console.log(isFunction(() => {})); // trueconsole.log(isFunction(function() {})); // trueconsole.log(isFunction({})); // falseisPromise
function isPromise(x)Checks if the given value is a Promise.
Parameters
| Name | Type | Description |
|---|---|---|
| x | any | Any value to check |
Returns
boolean - True if the value is a Promise, false otherwise.
Example
import { isPromise } from '@semantic-ui/utils';
console.log(isPromise(Promise.resolve())); // trueconsole.log(isPromise({ then: () => {} })); // trueconsole.log(isPromise({})); // falseisArguments
function isArguments(obj)Checks if the given value is an arguments object.
Parameters
| Name | Type | Description |
|---|---|---|
| obj | any | Any value to check |
Returns
boolean - True if the value is an arguments object, false otherwise.
Example
import { isArguments } from '@semantic-ui/utils';
function test() { console.log(isArguments(arguments)); // true}
console.log(isArguments([])); // falseisDOM
function isDOM(element)Checks if the given value is a DOM element.
Parameters
| Name | Type | Description |
|---|---|---|
| element | any | Any value to check |
Returns
boolean - True if the value is a DOM element, false otherwise.
Example
import { isDOM } from '@semantic-ui/utils';
console.log(isDOM(document.body)); // trueconsole.log(isDOM(document.createElement('div'))); // trueconsole.log(isDOM({})); // falseisNode
function isNode(el)Checks if the given value is a DOM node.
Parameters
| Name | Type | Description |
|---|---|---|
| el | any | Any value to check |
Returns
boolean - True if the value is a DOM node, false otherwise.
Example
import { isNode } from '@semantic-ui/utils';
console.log(isNode(document.createElement('div'))); // trueconsole.log(isNode({})); // falseisEmpty
function isEmpty(x)Checks if the given value is empty’ish (null, undefined, empty string, empty array, or empty object).
This is useful in scenarios where you want to treat any general empty value as non existent.
Parameters
| Name | Type | Description |
|---|---|---|
| x | any | Any value to check |
Returns
boolean - True if the value is empty, false otherwise.
Example
import { isEmpty } from '@semantic-ui/utils';
console.log(isEmpty(null)); // trueconsole.log(isEmpty([])); // trueconsole.log(isEmpty({})); // trueconsole.log(isEmpty("")); // trueconsole.log(isEmpty([1, 2, 3])); // falseisClassInstance
function isClassInstance(obj)Checks if the given object is an instance of a custom class (not a built-in object).
Built-in Types Exclusion This helper is specifically for determining whether a variable is an instance of a custom class. It will return
falsefor built-in types like Object, Array, Date, etc., focusing on identifying instances of custom classes.
Parameters
| Name | Type | Description |
|---|---|---|
| obj | any | The object to check |
Returns
boolean - True if the object is an instance of a custom class, false otherwise.
Example
import { isClassInstance } from '@semantic-ui/utils';
class MyClass {}const myInstance = new MyClass();
console.log(isClassInstance(myInstance)); // trueconsole.log(isClassInstance({})); // falseconsole.log(isClassInstance(new Date())); // falseisSet
function isSet(x)Checks if the given value is a Set instance.
Parameters
| Name | Type | Description |
|---|---|---|
| x | any | Any value to check |
Returns
boolean - True if the value is a Set, false otherwise.
Example
import { isSet } from '@semantic-ui/utils';
console.log(isSet(new Set())); // trueconsole.log(isSet(new Set([1, 2, 3]))); // trueconsole.log(isSet([])); // falseconsole.log(isSet(new Map())); // falseType Safety Use
isSet()before calling Set-specific methods likeadd(),has(), ordelete()to ensure type safety in your code.
isMap
function isMap(x)Checks if the given value is a Map instance.
Parameters
| Name | Type | Description |
|---|---|---|
| x | any | Any value to check |
Returns
boolean - True if the value is a Map, false otherwise.
Example
import { isMap } from '@semantic-ui/utils';
console.log(isMap(new Map())); // trueconsole.log(isMap(new Map([['a', 1]]))); // trueconsole.log(isMap({})); // falseconsole.log(isMap(new Set())); // false
// Distinguish from objects with Map-like methodsconst mapLike = { set: () => {}, get: () => {}, size: 0 };console.log(isMap(mapLike)); // falseInstance Checking
isMap()usesinstanceof Mapto distinguish real Map instances from plain objects that might have similar method names.