1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.asArray = asArray;
|
7 | exports.removeFromArray = removeFromArray;
|
8 | exports.isPopulatedArray = isPopulatedArray;
|
9 | exports.toggleItem = toggleItem;
|
10 |
|
11 | function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
12 |
|
13 | function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
|
14 |
|
15 | function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
|
16 |
|
17 | function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
18 |
|
19 | var isArray = Array.isArray;
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | function asArray(value) {
|
26 | if (isArray(value)) {
|
27 | return value;
|
28 | }
|
29 |
|
30 | return [value];
|
31 | }
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | function removeFromArray(array, value) {
|
43 | var index = array.indexOf(value);
|
44 | var length = 1;
|
45 | array.splice(index, length);
|
46 | }
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 | function isPopulatedArray(array) {
|
54 | return Boolean(isArray(array) && array.length);
|
55 | }
|
56 |
|
57 | function toggleItem(array, item) {
|
58 | if (array.includes(item)) {
|
59 | return array.filter(function (thisId) {
|
60 | return thisId !== item;
|
61 | });
|
62 | }
|
63 |
|
64 | return [].concat(_toConsumableArray(array), [item]);
|
65 | } |
\ | No newline at end of file |