minimal adjustments
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / lodash.flatten / index.js
1 /**
2  * lodash (Custom Build) <https://lodash.com/>
3  * Build: `lodash modularize exports="npm" -o ./`
4  * Copyright jQuery Foundation and other contributors <https://jquery.org/>
5  * Released under MIT license <https://lodash.com/license>
6  * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
7  * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
8  */
9
10 /** Used as references for various `Number` constants. */
11 var MAX_SAFE_INTEGER = 9007199254740991;
12
13 /** `Object#toString` result references. */
14 var argsTag = '[object Arguments]',
15     funcTag = '[object Function]',
16     genTag = '[object GeneratorFunction]';
17
18 /** Detect free variable `global` from Node.js. */
19 var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
20
21 /** Detect free variable `self`. */
22 var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
23
24 /** Used as a reference to the global object. */
25 var root = freeGlobal || freeSelf || Function('return this')();
26
27 /**
28  * Appends the elements of `values` to `array`.
29  *
30  * @private
31  * @param {Array} array The array to modify.
32  * @param {Array} values The values to append.
33  * @returns {Array} Returns `array`.
34  */
35 function arrayPush(array, values) {
36   var index = -1,
37       length = values.length,
38       offset = array.length;
39
40   while (++index < length) {
41     array[offset + index] = values[index];
42   }
43   return array;
44 }
45
46 /** Used for built-in method references. */
47 var objectProto = Object.prototype;
48
49 /** Used to check objects for own properties. */
50 var hasOwnProperty = objectProto.hasOwnProperty;
51
52 /**
53  * Used to resolve the
54  * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
55  * of values.
56  */
57 var objectToString = objectProto.toString;
58
59 /** Built-in value references. */
60 var Symbol = root.Symbol,
61     propertyIsEnumerable = objectProto.propertyIsEnumerable,
62     spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined;
63
64 /**
65  * The base implementation of `_.flatten` with support for restricting flattening.
66  *
67  * @private
68  * @param {Array} array The array to flatten.
69  * @param {number} depth The maximum recursion depth.
70  * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
71  * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
72  * @param {Array} [result=[]] The initial result value.
73  * @returns {Array} Returns the new flattened array.
74  */
75 function baseFlatten(array, depth, predicate, isStrict, result) {
76   var index = -1,
77       length = array.length;
78
79   predicate || (predicate = isFlattenable);
80   result || (result = []);
81
82   while (++index < length) {
83     var value = array[index];
84     if (depth > 0 && predicate(value)) {
85       if (depth > 1) {
86         // Recursively flatten arrays (susceptible to call stack limits).
87         baseFlatten(value, depth - 1, predicate, isStrict, result);
88       } else {
89         arrayPush(result, value);
90       }
91     } else if (!isStrict) {
92       result[result.length] = value;
93     }
94   }
95   return result;
96 }
97
98 /**
99  * Checks if `value` is a flattenable `arguments` object or array.
100  *
101  * @private
102  * @param {*} value The value to check.
103  * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
104  */
105 function isFlattenable(value) {
106   return isArray(value) || isArguments(value) ||
107     !!(spreadableSymbol && value && value[spreadableSymbol]);
108 }
109
110 /**
111  * Flattens `array` a single level deep.
112  *
113  * @static
114  * @memberOf _
115  * @since 0.1.0
116  * @category Array
117  * @param {Array} array The array to flatten.
118  * @returns {Array} Returns the new flattened array.
119  * @example
120  *
121  * _.flatten([1, [2, [3, [4]], 5]]);
122  * // => [1, 2, [3, [4]], 5]
123  */
124 function flatten(array) {
125   var length = array ? array.length : 0;
126   return length ? baseFlatten(array, 1) : [];
127 }
128
129 /**
130  * Checks if `value` is likely an `arguments` object.
131  *
132  * @static
133  * @memberOf _
134  * @since 0.1.0
135  * @category Lang
136  * @param {*} value The value to check.
137  * @returns {boolean} Returns `true` if `value` is an `arguments` object,
138  *  else `false`.
139  * @example
140  *
141  * _.isArguments(function() { return arguments; }());
142  * // => true
143  *
144  * _.isArguments([1, 2, 3]);
145  * // => false
146  */
147 function isArguments(value) {
148   // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
149   return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
150     (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
151 }
152
153 /**
154  * Checks if `value` is classified as an `Array` object.
155  *
156  * @static
157  * @memberOf _
158  * @since 0.1.0
159  * @category Lang
160  * @param {*} value The value to check.
161  * @returns {boolean} Returns `true` if `value` is an array, else `false`.
162  * @example
163  *
164  * _.isArray([1, 2, 3]);
165  * // => true
166  *
167  * _.isArray(document.body.children);
168  * // => false
169  *
170  * _.isArray('abc');
171  * // => false
172  *
173  * _.isArray(_.noop);
174  * // => false
175  */
176 var isArray = Array.isArray;
177
178 /**
179  * Checks if `value` is array-like. A value is considered array-like if it's
180  * not a function and has a `value.length` that's an integer greater than or
181  * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
182  *
183  * @static
184  * @memberOf _
185  * @since 4.0.0
186  * @category Lang
187  * @param {*} value The value to check.
188  * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
189  * @example
190  *
191  * _.isArrayLike([1, 2, 3]);
192  * // => true
193  *
194  * _.isArrayLike(document.body.children);
195  * // => true
196  *
197  * _.isArrayLike('abc');
198  * // => true
199  *
200  * _.isArrayLike(_.noop);
201  * // => false
202  */
203 function isArrayLike(value) {
204   return value != null && isLength(value.length) && !isFunction(value);
205 }
206
207 /**
208  * This method is like `_.isArrayLike` except that it also checks if `value`
209  * is an object.
210  *
211  * @static
212  * @memberOf _
213  * @since 4.0.0
214  * @category Lang
215  * @param {*} value The value to check.
216  * @returns {boolean} Returns `true` if `value` is an array-like object,
217  *  else `false`.
218  * @example
219  *
220  * _.isArrayLikeObject([1, 2, 3]);
221  * // => true
222  *
223  * _.isArrayLikeObject(document.body.children);
224  * // => true
225  *
226  * _.isArrayLikeObject('abc');
227  * // => false
228  *
229  * _.isArrayLikeObject(_.noop);
230  * // => false
231  */
232 function isArrayLikeObject(value) {
233   return isObjectLike(value) && isArrayLike(value);
234 }
235
236 /**
237  * Checks if `value` is classified as a `Function` object.
238  *
239  * @static
240  * @memberOf _
241  * @since 0.1.0
242  * @category Lang
243  * @param {*} value The value to check.
244  * @returns {boolean} Returns `true` if `value` is a function, else `false`.
245  * @example
246  *
247  * _.isFunction(_);
248  * // => true
249  *
250  * _.isFunction(/abc/);
251  * // => false
252  */
253 function isFunction(value) {
254   // The use of `Object#toString` avoids issues with the `typeof` operator
255   // in Safari 8-9 which returns 'object' for typed array and other constructors.
256   var tag = isObject(value) ? objectToString.call(value) : '';
257   return tag == funcTag || tag == genTag;
258 }
259
260 /**
261  * Checks if `value` is a valid array-like length.
262  *
263  * **Note:** This method is loosely based on
264  * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
265  *
266  * @static
267  * @memberOf _
268  * @since 4.0.0
269  * @category Lang
270  * @param {*} value The value to check.
271  * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
272  * @example
273  *
274  * _.isLength(3);
275  * // => true
276  *
277  * _.isLength(Number.MIN_VALUE);
278  * // => false
279  *
280  * _.isLength(Infinity);
281  * // => false
282  *
283  * _.isLength('3');
284  * // => false
285  */
286 function isLength(value) {
287   return typeof value == 'number' &&
288     value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
289 }
290
291 /**
292  * Checks if `value` is the
293  * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
294  * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
295  *
296  * @static
297  * @memberOf _
298  * @since 0.1.0
299  * @category Lang
300  * @param {*} value The value to check.
301  * @returns {boolean} Returns `true` if `value` is an object, else `false`.
302  * @example
303  *
304  * _.isObject({});
305  * // => true
306  *
307  * _.isObject([1, 2, 3]);
308  * // => true
309  *
310  * _.isObject(_.noop);
311  * // => true
312  *
313  * _.isObject(null);
314  * // => false
315  */
316 function isObject(value) {
317   var type = typeof value;
318   return !!value && (type == 'object' || type == 'function');
319 }
320
321 /**
322  * Checks if `value` is object-like. A value is object-like if it's not `null`
323  * and has a `typeof` result of "object".
324  *
325  * @static
326  * @memberOf _
327  * @since 4.0.0
328  * @category Lang
329  * @param {*} value The value to check.
330  * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
331  * @example
332  *
333  * _.isObjectLike({});
334  * // => true
335  *
336  * _.isObjectLike([1, 2, 3]);
337  * // => true
338  *
339  * _.isObjectLike(_.noop);
340  * // => false
341  *
342  * _.isObjectLike(null);
343  * // => false
344  */
345 function isObjectLike(value) {
346   return !!value && typeof value == 'object';
347 }
348
349 module.exports = flatten;