Types Utilities API reference for type checking and manipulation functions type Guide

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

NameTypeDescription
xanyAny value to check

Returns

boolean - True if the value is an object, false otherwise.

Example

import { isObject } from '@semantic-ui/utils';
console.log(isObject({})); // true
console.log(isObject([])); // true
console.log(isObject(null)); // false

isPlainObject

function isPlainObject(x)

Checks if the given value is a plain JavaScript object (created using object literal notation or Object.create(null)).

Parameters

NameTypeDescription
xanyAny 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({})); // true
console.log(isPlainObject([])); // false
console.log(isPlainObject(new Date())); // false

isString

function isString(x)

Checks if the given value is a string.

Parameters

NameTypeDescription
xanyAny 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")); // true
console.log(isString(new String("hello"))); // true
console.log(isString(123)); // false

isBoolean

function isBoolean(x)

Checks if the given value is a boolean.

Parameters

NameTypeDescription
xanyAny 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)); // true
console.log(isBoolean(false)); // true
console.log(isBoolean(1)); // false

isNumber

function isNumber(x)

Checks if the given value is a number.

Parameters

NameTypeDescription
xanyAny 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)); // true
console.log(isNumber(NaN)); // true
console.log(isNumber("123")); // false

isArray

function isArray(x)

Checks if the given value is an array.

Parameters

NameTypeDescription
xanyAny value to check

Returns

boolean - True if the value is an array, false otherwise.

Example

import { isArray } from '@semantic-ui/utils';
console.log(isArray([])); // true
console.log(isArray([1, 2, 3])); // true
console.log(isArray({})); // false

isBinary

function isBinary(x)

Checks if the given value is a binary (Uint8Array).

Parameters

NameTypeDescription
xanyAny 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())); // true
console.log(isBinary(new ArrayBuffer(8))); // false

isFunction

function isFunction(x)

Checks if the given value is a function.

Parameters

NameTypeDescription
xanyAny value to check

Returns

boolean - True if the value is a function, false otherwise.

Example

import { isFunction } from '@semantic-ui/utils';
console.log(isFunction(() => {})); // true
console.log(isFunction(function() {})); // true
console.log(isFunction({})); // false

isPromise

function isPromise(x)

Checks if the given value is a Promise.

Parameters

NameTypeDescription
xanyAny 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())); // true
console.log(isPromise({ then: () => {} })); // true
console.log(isPromise({})); // false

isArguments

function isArguments(obj)

Checks if the given value is an arguments object.

Parameters

NameTypeDescription
objanyAny 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([])); // false

isDOM

function isDOM(element)

Checks if the given value is a DOM element.

Parameters

NameTypeDescription
elementanyAny 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)); // true
console.log(isDOM(document.createElement('div'))); // true
console.log(isDOM({})); // false

isNode

function isNode(el)

Checks if the given value is a DOM node.

Parameters

NameTypeDescription
elanyAny 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'))); // true
console.log(isNode({})); // false

isEmpty

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

NameTypeDescription
xanyAny value to check

Returns

boolean - True if the value is empty, false otherwise.

Example

import { isEmpty } from '@semantic-ui/utils';
console.log(isEmpty(null)); // true
console.log(isEmpty([])); // true
console.log(isEmpty({})); // true
console.log(isEmpty("")); // true
console.log(isEmpty([1, 2, 3])); // false

isClassInstance

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 false for built-in types like Object, Array, Date, etc., focusing on identifying instances of custom classes.

Parameters

NameTypeDescription
objanyThe 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)); // true
console.log(isClassInstance({})); // false
console.log(isClassInstance(new Date())); // false