UNPKG

@gvray/eskit

Version:

A rich and colorful toolkit about typescript and javascript.

35 lines 1.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * Checks if a value is defined (not undefined or null). * 检查值是否已定义(非undefined或null)。 * * @typeParam T - The type of the value to check / 要检查的值的类型 * @param val - The value to check / 要检查的值 * @returns True if the value is defined / 如果值已定义则返回true * * @example * ```typescript * isDefined(1) // true * isDefined('hello') // true * isDefined(false) // true * isDefined(0) // true * isDefined('') // true * isDefined([]) // true * isDefined({}) // true * isDefined(null) // false * isDefined(undefined) // false * isDefined(void 0) // false * * // Useful for filtering arrays * const arr = [1, null, 'test', undefined, 0] * const filtered = arr.filter(isDefined) // [1, 'test', 0] * ``` * * @since 1.0.0 */ var isDefined = function (val) { return val !== undefined && val !== null; }; exports.default = isDefined; //# sourceMappingURL=isDefined.js.map