UNPKG

sussy-util

Version:
41 lines (40 loc) 1.37 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 (a === null || a === void 0) return false; if ((Classes_1.IsSomething.isString(a) && a.length > 0) || Classes_1.IsSomething.isBoolean(a) || Classes_1.IsSomething.isNumber(a) || Classes_1.IsSomething.isFunction(a) || (Classes_1.IsSomething.isRegExp(a) && a.source.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 (Object.prototype.hasOwnProperty.call(a, key)) { if (hasValue(a[key])) { return true; } } } } return false; }; exports.default = hasValue;