UNPKG

@kelvininc/ui-components

Version:
163 lines (143 loc) 4.78 kB
'use strict'; var _Set = require('./_Set-BIUoGFN6.js'); var _Map = require('./_Map-DiT24PAz.js'); var isObject = require('./isObject-COPdF2vE.js'); /* Built-in method references that are verified to be native. */ var WeakMap = _Map.getNative(isObject.root, 'WeakMap'); /* Built-in method references for those with the same name as other `lodash` methods. */ var nativeKeys = _Set.overArg(Object.keys, Object); /** Used for built-in method references. */ var objectProto$1 = Object.prototype; /** Used to check objects for own properties. */ var hasOwnProperty$1 = objectProto$1.hasOwnProperty; /** * The base implementation of `_.keys` which doesn't treat sparse arrays as dense. * * @private * @param {Object} object The object to query. * @returns {Array} Returns the array of property names. */ function baseKeys(object) { if (!_Set.isPrototype(object)) { return nativeKeys(object); } var result = []; for (var key in Object(object)) { if (hasOwnProperty$1.call(object, key) && key != 'constructor') { result.push(key); } } return result; } /* Built-in method references that are verified to be native. */ var DataView = _Map.getNative(isObject.root, 'DataView'); /* Built-in method references that are verified to be native. */ var Promise$1 = _Map.getNative(isObject.root, 'Promise'); /** `Object#toString` result references. */ var mapTag$1 = '[object Map]', objectTag = '[object Object]', promiseTag = '[object Promise]', setTag$1 = '[object Set]', weakMapTag = '[object WeakMap]'; var dataViewTag = '[object DataView]'; /** Used to detect maps, sets, and weakmaps. */ var dataViewCtorString = _Map.toSource(DataView), mapCtorString = _Map.toSource(_Map.Map), promiseCtorString = _Map.toSource(Promise$1), setCtorString = _Map.toSource(_Set.Set), weakMapCtorString = _Map.toSource(WeakMap); /** * Gets the `toStringTag` of `value`. * * @private * @param {*} value The value to query. * @returns {string} Returns the `toStringTag`. */ exports.getTag = isObject.baseGetTag; // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6. if ((DataView && exports.getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) || (_Map.Map && exports.getTag(new _Map.Map) != mapTag$1) || (Promise$1 && exports.getTag(Promise$1.resolve()) != promiseTag) || (_Set.Set && exports.getTag(new _Set.Set) != setTag$1) || (WeakMap && exports.getTag(new WeakMap) != weakMapTag)) { exports.getTag = function(value) { var result = isObject.baseGetTag(value), Ctor = result == objectTag ? value.constructor : undefined, ctorString = Ctor ? _Map.toSource(Ctor) : ''; if (ctorString) { switch (ctorString) { case dataViewCtorString: return dataViewTag; case mapCtorString: return mapTag$1; case promiseCtorString: return promiseTag; case setCtorString: return setTag$1; case weakMapCtorString: return weakMapTag; } } return result; }; } /** `Object#toString` result references. */ var mapTag = '[object Map]', setTag = '[object Set]'; /** Used for built-in method references. */ var objectProto = Object.prototype; /** Used to check objects for own properties. */ var hasOwnProperty = objectProto.hasOwnProperty; /** * Checks if `value` is an empty object, collection, map, or set. * * Objects are considered empty if they have no own enumerable string keyed * properties. * * Array-like values such as `arguments` objects, arrays, buffers, strings, or * jQuery-like collections are considered empty if they have a `length` of `0`. * Similarly, maps and sets are considered empty if they have a `size` of `0`. * * @static * @memberOf _ * @since 0.1.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is empty, else `false`. * @example * * _.isEmpty(null); * // => true * * _.isEmpty(true); * // => true * * _.isEmpty(1); * // => true * * _.isEmpty([1, 2, 3]); * // => false * * _.isEmpty({ 'a': 1 }); * // => false */ function isEmpty(value) { if (value == null) { return true; } if (_Set.isArrayLike(value) && (_Map.isArray(value) || typeof value == 'string' || typeof value.splice == 'function' || _Set.isBuffer(value) || _Set.isTypedArray(value) || _Set.isArguments(value))) { return !value.length; } var tag = exports.getTag(value); if (tag == mapTag || tag == setTag) { return !value.size; } if (_Set.isPrototype(value)) { return !baseKeys(value).length; } for (var key in value) { if (hasOwnProperty.call(value, key)) { return false; } } return true; } exports.baseKeys = baseKeys; exports.isEmpty = isEmpty;