UNPKG

sussy-util

Version:
35 lines (34 loc) 1.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const Classes_1 = require("../Classes"); /** * Returns true if a value exists, false if empty. Works with deeply nested values using object paths. * @param {any} a - any * @returns A function that takes a parameter and returns a boolean. */ const hasValue = (a) => { if ((Classes_1.IsSomething.isString(a) && a.length > 0) || Classes_1.IsSomething.isBoolean(a) || a === null || Classes_1.IsSomething.isNumber(a) || Classes_1.IsSomething.isFunction(a) || (Classes_1.IsSomething.isRegExp(a) && a.length > 0)) { return true; } if (Classes_1.IsSomething.isArray(a)) { for (const iterator of a) { if (hasValue(iterator)) { return true; } } } if (a instanceof Classes_1.Set || a instanceof Classes_1.Stack || a instanceof Classes_1.Collection) { return hasValue(a.toArray()); } if (typeof a === 'object' && !Classes_1.IsSomething.isArray(a)) { for (const key in a) { if (a.hasOwnProperty(key)) { if (hasValue(a[key])) { return true; } } } } return false; }; exports.default = hasValue;