main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
766 bytes
|
Line | |
---|
1 | import isArray from './isArray.js';
|
---|
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 | */
|
---|
36 | function castArray() {
|
---|
37 | if (!arguments.length) {
|
---|
38 | return [];
|
---|
39 | }
|
---|
40 | var value = arguments[0];
|
---|
41 | return isArray(value) ? value : [value];
|
---|
42 | }
|
---|
43 |
|
---|
44 | export default castArray;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.