source: trip-planner-front/node_modules/lodash/castArray.js@ 6a3a178

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

initial commit

  • Property mode set to 100644
File size: 768 bytes
Line 
1var isArray = require('./isArray');
2
3/**
4 * Casts `value` as an array if it's not one.
5 *
6 * @static
7 * @memberOf _
8 * @since 4.4.0
9 * @category Lang
10 * @param {*} value The value to inspect.
11 * @returns {Array} Returns the cast array.
12 * @example
13 *
14 * _.castArray(1);
15 * // => [1]
16 *
17 * _.castArray({ 'a': 1 });
18 * // => [{ 'a': 1 }]
19 *
20 * _.castArray('abc');
21 * // => ['abc']
22 *
23 * _.castArray(null);
24 * // => [null]
25 *
26 * _.castArray(undefined);
27 * // => [undefined]
28 *
29 * _.castArray();
30 * // => []
31 *
32 * var array = [1, 2, 3];
33 * console.log(_.castArray(array) === array);
34 * // => true
35 */
36function castArray() {
37 if (!arguments.length) {
38 return [];
39 }
40 var value = arguments[0];
41 return isArray(value) ? value : [value];
42}
43
44module.exports = castArray;
Note: See TracBrowser for help on using the repository browser.