isEmpty

Check if the given value is empty.

Usage Scenarios

  • Data Validation: When processing user input or API responses, verify if a value is empty before further processing.
  • Form Handling: Check if form fields are empty before submission.
  • Conditional Rendering: Determine whether to render content based on empty state.

Examples

import { isEmpty } from 'funtool';

isEmpty(null); // ✅ true
isEmpty(undefined); // ✅ true
isEmpty(''); // ✅ true
isEmpty('   '); // ✅ true
isEmpty(NaN); // ✅ true
isEmpty([]); // ✅ true
isEmpty({}); // ✅ true
isEmpty(new Date('invalid date')); // ✅ true

isEmpty('hello'); // ❌ false
isEmpty(123); // ❌ false
isEmpty([1, 2, 3]); // ❌ false
isEmpty({ key: 'value' }); // ❌ false
isEmpty(new Date()); // ❌ false

Signature

function isEmpty(v: any): boolean

Parameters

  • v (any): The value to check for emptiness.

Returns

  • (boolean): Returns true if the value is empty, otherwise returns false.