@vime/core
Version:
Customizable, extensible, accessible and framework agnostic media player.
88 lines (87 loc) • 2.73 kB
JavaScript
/**
* No-operation (noop).
*/
// eslint-disable-next-line @typescript-eslint/no-empty-function
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export const noop = (..._) => {
// ...
};
/**
* Checks if `value` is `null`.
*
* @param value - The value to check.
*/
export const isNull = (value) => value === null;
/**
* Checks if `value` is `undefined`.
*
* @param value - The value to check.
*/
export const isUndefined = (value) => typeof value === 'undefined';
/**
* Checks if `value` is `null` or `undefined`.
*
* @param value - The value to check.
*/
export const isNil = (value) => isNull(value) || isUndefined(value);
/**
* Returns the constructor of the given `value`.
*
* @param value - The value to return the constructor of.
*/
export const getConstructor = (value) =>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
!isNil(value) ? value.constructor : undefined;
/**
* Checks if `value` is classified as a `Object` object.
*
* @param value - The value to check.
*/
export const isObject = (value) => getConstructor(value) === Object;
/**
* Checks if `value` is classified as a `Number` object.
*
* @param value - The value to check.
*/
export const isNumber = (value) => getConstructor(value) === Number && !Number.isNaN(value);
/**
* Checks if `value` is classified as a `String` object.
*
* @param value - The value to check.
*/
export const isString = (value) => getConstructor(value) === String;
/**
* Checks if `value` is classified as a `Boolean` object.
*
* @param value - The value to check.
*/
export const isBoolean = (value) => getConstructor(value) === Boolean;
/**
* Checks if `value` is classified as a `Function` object.
*
* @param value - The value to check.
*/
// eslint-disable-next-line @typescript-eslint/ban-types
export const isFunction = (value) => getConstructor(value) === Function;
/**
* Checks if `value` is classified as an `Array` object.
*
* @param value - The value to check.
*/
export const isArray = (value) => Array.isArray(value);
/**
* Checks if `value` is an instanceof the given `constructor`.
*
* @param value - The value to check.
* @param constructor - The constructor to check against.
*/
export const isInstanceOf = (value, constructor) => Boolean(value && constructor && value instanceof constructor);
/**
* Checks if the `value` prototype chain includes the given `object`.
*
* @param value - The value whose prototype chain to check.
* @param object - The object to search for in the prototype chain.
*/
export const isPrototypeOf = (
// eslint-disable-next-line @typescript-eslint/ban-types
value, object) => Boolean(value && object && Object.isPrototypeOf.call(object.prototype, value));