UNPKG

@formily/shared

Version:
83 lines 2.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isEmpty = exports.isValid = exports.isUndef = void 0; var instanceof_1 = require("./instanceof"); var has = Object.prototype.hasOwnProperty; var toString = Object.prototype.toString; var isUndef = function (val) { return val === undefined; }; exports.isUndef = isUndef; var isValid = function (val) { return val !== undefined && val !== null; }; exports.isValid = isValid; function isEmpty(val, strict) { if (strict === void 0) { strict = false; } // Null and Undefined... if (val == null) { return true; } // Booleans... if (typeof val === 'boolean') { return false; } // Numbers... if (typeof val === 'number') { return false; } // Strings... if (typeof val === 'string') { return val.length === 0; } // Functions... if (typeof val === 'function') { return val.length === 0; } // Arrays... if (Array.isArray(val)) { if (val.length === 0) { return true; } for (var i = 0; i < val.length; i++) { if (strict) { if (val[i] !== undefined && val[i] !== null) { return false; } } else { if (val[i] !== undefined && val[i] !== null && val[i] !== '' && val[i] !== 0) { return false; } } } return true; } // Errors... if ((0, instanceof_1.instOf)(val, 'Error')) { return val.message === ''; } // Objects... if (val.toString === toString) { switch (val.toString()) { // Maps, Sets, Files and Errors... case '[object File]': case '[object Map]': case '[object Set]': { return val.size === 0; } // Plain objects... case '[object Object]': { for (var key in val) { if (has.call(val, key)) { return false; } } return true; } } } // Anything else... return false; } exports.isEmpty = isEmpty; //# sourceMappingURL=isEmpty.js.map