
Enter a search term above to see results...
Enter a search term above to see results...
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.
function isObject(x)
Checks if the given value is an object.
Name | Type | Description |
---|---|---|
x | any | Any value to check |
boolean
- True if the value is an object, false otherwise.
import { isObject } from '@semantic-ui/utils';
console.log(isObject({})); // trueconsole.log(isObject([])); // trueconsole.log(isObject(null)); // false
function isPlainObject(x)
Checks if the given value is a plain JavaScript object (created using object literal notation or Object.create(null)).
Name | Type | Description |
---|---|---|
x | any | Any value to check |
boolean
- True if the value is a plain object, false otherwise.
import { isPlainObject } from '@semantic-ui/utils';
console.log(isPlainObject({})); // trueconsole.log(isPlainObject([])); // falseconsole.log(isPlainObject(new Date())); // false
function isString(x)
Checks if the given value is a string.
Name | Type | Description |
---|---|---|
x | any | Any value to check |
boolean
- True if the value is a string, false otherwise.
import { isString } from '@semantic-ui/utils';
console.log(isString("hello")); // trueconsole.log(isString(new String("hello"))); // trueconsole.log(isString(123)); // false
function isBoolean(x)
Checks if the given value is a boolean.
Name | Type | Description |
---|---|---|
x | any | Any value to check |
boolean
- True if the value is a boolean, false otherwise.
import { isBoolean } from '@semantic-ui/utils';
console.log(isBoolean(true)); // trueconsole.log(isBoolean(false)); // trueconsole.log(isBoolean(1)); // false
function isNumber(x)
Checks if the given value is a number.
Name | Type | Description |
---|---|---|
x | any | Any value to check |
boolean
- True if the value is a number, false otherwise.
import { isNumber } from '@semantic-ui/utils';
console.log(isNumber(123)); // trueconsole.log(isNumber(NaN)); // trueconsole.log(isNumber("123")); // false
function isArray(x)
Checks if the given value is an array.
Name | Type | Description |
---|---|---|
x | any | Any value to check |
boolean
- True if the value is an array, false otherwise.
import { isArray } from '@semantic-ui/utils';
console.log(isArray([])); // trueconsole.log(isArray([1, 2, 3])); // trueconsole.log(isArray({})); // false
function isBinary(x)
Checks if the given value is a binary (Uint8Array).
Name | Type | Description |
---|---|---|
x | any | Any value to check |
boolean
- True if the value is a binary, false otherwise.
import { isBinary } from '@semantic-ui/utils';
console.log(isBinary(new Uint8Array())); // trueconsole.log(isBinary(new ArrayBuffer(8))); // false
function isFunction(x)
Checks if the given value is a function.
Name | Type | Description |
---|---|---|
x | any | Any value to check |
boolean
- True if the value is a function, false otherwise.
import { isFunction } from '@semantic-ui/utils';
console.log(isFunction(() => {})); // trueconsole.log(isFunction(function() {})); // trueconsole.log(isFunction({})); // false
function isPromise(x)
Checks if the given value is a Promise.
Name | Type | Description |
---|---|---|
x | any | Any value to check |
boolean
- True if the value is a Promise, false otherwise.
import { isPromise } from '@semantic-ui/utils';
console.log(isPromise(Promise.resolve())); // trueconsole.log(isPromise({ then: () => {} })); // trueconsole.log(isPromise({})); // false
function isArguments(obj)
Checks if the given value is an arguments object.
Name | Type | Description |
---|---|---|
obj | any | Any value to check |
boolean
- True if the value is an arguments object, false otherwise.
import { isArguments } from '@semantic-ui/utils';
function test() { console.log(isArguments(arguments)); // true}
console.log(isArguments([])); // false
function isDOM(element)
Checks if the given value is a DOM element.
Name | Type | Description |
---|---|---|
element | any | Any value to check |
boolean
- True if the value is a DOM element, false otherwise.
import { isDOM } from '@semantic-ui/utils';
console.log(isDOM(document.body)); // trueconsole.log(isDOM(document.createElement('div'))); // trueconsole.log(isDOM({})); // false
function isNode(el)
Checks if the given value is a DOM node.
Name | Type | Description |
---|---|---|
el | any | Any value to check |
boolean
- True if the value is a DOM node, false otherwise.
import { isNode } from '@semantic-ui/utils';
console.log(isNode(document.createElement('div'))); // trueconsole.log(isNode({})); // false
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.
Name | Type | Description |
---|---|---|
x | any | Any value to check |
boolean
- True if the value is empty, false otherwise.
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])); // false
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.
Name | Type | Description |
---|---|---|
obj | any | The object to check |
boolean
- True if the object is an instance of a custom class, false otherwise.
import { isClassInstance } from '@semantic-ui/utils';
class MyClass {}const myInstance = new MyClass();
console.log(isClassInstance(myInstance)); // trueconsole.log(isClassInstance({})); // falseconsole.log(isClassInstance(new Date())); // false