UNPKG

api-helper-kit

Version:
29 lines (24 loc) 647 B
/** * Check if a variable is empty * @param {any} value - The variable to check * @returns {boolean} - Returns true if the variable is empty, false otherwise */ function isEmpty(value) { // Check for null, undefined, or an empty string if (value === null || value === undefined || value === "") { return true; } // Check for an empty array if (Array.isArray(value) && value.length === 0) { return true; } // Check for an empty object if (typeof value === "object" && !Array.isArray(value)) { return Object.keys(value).length === 0; } // Non-empty return false; } module.exports = { isEmpty: isEmpty, };