@planjs/utils
Version:
🔧 Common tools collection
44 lines (33 loc) • 898 B
JavaScript
import { isArrayLike } from './is-Array';
import getType from './get-type';
import isPrototype from './is-Prototype';
import isArguments from './is-Arguments';
import isTypedArray from './is-TypedArray';
var hasOwnProperty = Object.prototype.hasOwnProperty;
/**
* 检查是否空对象
* @param value
* @category Is
*/
function isEmpty(value) {
if (value == null) {
return true;
} // array
if (isArrayLike(value) && (Array.isArray(value) || typeof value === 'string' || isTypedArray(value) || isArguments(value))) {
return !value.length;
} // map
var type = getType(value);
if (type === 'Map' || type === 'Set') {
return !value.size;
} // object
if (isPrototype(value)) {
return !Object.keys(value).length;
}
for (var key in value) {
if (hasOwnProperty.call(value, key)) {
return false;
}
}
return true;
}
export default isEmpty;