UNPKG

d2-ui

Version:
39 lines (30 loc) 1.34 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = isEmpty; var _isArray = require('./isArray'); var _isArray2 = _interopRequireDefault(_isArray); var _lodash = require('lodash.ismap'); var _lodash2 = _interopRequireDefault(_lodash); var _lodash3 = require('lodash.isset'); var _lodash4 = _interopRequireDefault(_lodash3); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * Check if a value is concidered _empty_. An _empty_ value is an empty `Set`, `Map` or `Array`. * Depending on if the `allowEmptyString` flag, empty strings are also considered _empty_ * * @param {*} param Value to check * @param {boolean} allowEmptyString When set to true an empty string will not be considered _empty_. * @returns {boolean} Returns `true` when the value is _empty_, otherwise false * * @example * isEmpty(''); // Returns: true * isEmpty('', true); // Returns: false * isEmpty(null); // Returns: true * isEmpty(new Map()); // Returns: true */ function isEmpty(param, allowEmptyString) { return param == null || (!allowEmptyString ? param === '' : false) || (0, _isArray2.default)(param) && param.length === 0 || ((0, _lodash2.default)(param) || (0, _lodash4.default)(param)) && param.size === 0; } //# sourceMappingURL=isEmpty.js.map