source: trip-planner-front/node_modules/lodash/isEmpty.js@ eed0bf8

Last change on this file since eed0bf8 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.0 KB
RevLine 
[6a3a178]1var baseKeys = require('./_baseKeys'),
2 getTag = require('./_getTag'),
3 isArguments = require('./isArguments'),
4 isArray = require('./isArray'),
5 isArrayLike = require('./isArrayLike'),
6 isBuffer = require('./isBuffer'),
7 isPrototype = require('./_isPrototype'),
8 isTypedArray = require('./isTypedArray');
9
10/** `Object#toString` result references. */
11var mapTag = '[object Map]',
12 setTag = '[object Set]';
13
14/** Used for built-in method references. */
15var objectProto = Object.prototype;
16
17/** Used to check objects for own properties. */
18var hasOwnProperty = objectProto.hasOwnProperty;
19
20/**
21 * Checks if `value` is an empty object, collection, map, or set.
22 *
23 * Objects are considered empty if they have no own enumerable string keyed
24 * properties.
25 *
26 * Array-like values such as `arguments` objects, arrays, buffers, strings, or
27 * jQuery-like collections are considered empty if they have a `length` of `0`.
28 * Similarly, maps and sets are considered empty if they have a `size` of `0`.
29 *
30 * @static
31 * @memberOf _
32 * @since 0.1.0
33 * @category Lang
34 * @param {*} value The value to check.
35 * @returns {boolean} Returns `true` if `value` is empty, else `false`.
36 * @example
37 *
38 * _.isEmpty(null);
39 * // => true
40 *
41 * _.isEmpty(true);
42 * // => true
43 *
44 * _.isEmpty(1);
45 * // => true
46 *
47 * _.isEmpty([1, 2, 3]);
48 * // => false
49 *
50 * _.isEmpty({ 'a': 1 });
51 * // => false
52 */
53function isEmpty(value) {
54 if (value == null) {
55 return true;
56 }
57 if (isArrayLike(value) &&
58 (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' ||
59 isBuffer(value) || isTypedArray(value) || isArguments(value))) {
60 return !value.length;
61 }
62 var tag = getTag(value);
63 if (tag == mapTag || tag == setTag) {
64 return !value.size;
65 }
66 if (isPrototype(value)) {
67 return !baseKeys(value).length;
68 }
69 for (var key in value) {
70 if (hasOwnProperty.call(value, key)) {
71 return false;
72 }
73 }
74 return true;
75}
76
77module.exports = isEmpty;
Note: See TracBrowser for help on using the repository browser.