is-falsy
Checks if a value is falsy. Returns true for JavaScript falsy values: false, 0, -0, 0n, "", null, undefined, and NaN. Useful for type-safe falsy checks and filtering operations.
Installation
npx fragmen add boolean/is-falsySource Code
/**
* Checks if a value is falsy.
*
* Returns true for JavaScript falsy values: false, 0, -0, 0n, "", null, undefined, and NaN.
* Useful for type-safe falsy checks and filtering operations.
*
* @tags pure, validation, type-checking
* @param {unknown} value The value to check for falsiness.
* @returns {boolean} True if the value is falsy, false otherwise.
*
* @example
* ```typescript
* isFalsy(false); // true
* isFalsy(0); // true
* isFalsy(''); // true
* isFalsy(null); // true
* isFalsy(undefined); // true
* isFalsy('hello'); // false
* isFalsy(1); // false
* isFalsy([]); // false
* ```
*/
export function isFalsy(value: unknown): boolean {
return !value;
}
Examples
isFalsy(false); // true
isFalsy(0); // true
isFalsy(''); // true
isFalsy(null); // true
isFalsy(undefined); // true
isFalsy('hello'); // false
isFalsy(1); // false
isFalsy([]); // false
Related Utilities
is-truthy
booleanChecks if a value is truthy. Returns true for all JavaScript truthy values (anything that is not falsy). Complementary function to isFalsy, useful for filtering and validation.
safe-parse
jsonSafely parses a JSON string, returning undefined if parsing fails. Provides error-safe JSON parsing without throwing exceptions. Useful when working with untrusted input or when you want to handle parsing failures gracefully rather than with try-catch blocks.
has-path
objectChecks if a nested property path exists in an object. Safely traverses nested object properties using a dot-notation path string or an array of keys. Returns true if the path exists (even if the final value is undefined), false if any part of the path is missing.
is-empty
validationChecks if a value is empty (null, undefined, empty string, empty array, or empty object). A comprehensive emptiness check that handles multiple JavaScript types. Useful for form validation, data cleaning, and conditional rendering.
is-equal
validationDeep comparison of two values for equality. Recursively compares objects, arrays, dates, and primitives for deep equality. Handles circular references, special objects (Date, RegExp, Map, Set), and all primitive types. Useful for comparing complex data structures.
chunk
arraySplits an array into chunks of a specified size. Creates a new array containing subarrays (chunks) of the original array, each with a maximum length of the specified size. The last chunk may contain fewer elements if the array length is not evenly divisible by the chunk size.
Quick Actions
Tags
Parameters
valueunknownThe value to check for falsiness.
Returns
booleanTrue if the value is falsy, false otherwise.