@radiantabyss/neutralino 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +32 -0
- package/src/Bootstrap.js +31 -0
- package/src/ContextMenu.js +18 -0
- package/src/IPC.js +28 -0
- package/src/Invoke.js +13 -0
- package/src/Models.js +19 -0
- package/src/Request.js +173 -0
- package/src/Response.js +15 -0
- package/src/Routing/Actions.js +47 -0
- package/src/Routing/Middleware.js +45 -0
- package/src/Routing/Route.js +84 -0
- package/src/Routing/RouteCrud.js +19 -0
- package/src/Routing/RouteFiles.js +1 -0
- package/src/Routing/Router.js +109 -0
- package/src/Support/Config.js +40 -0
- package/src/Support/Env.js +46 -0
- package/src/Support/Helpers.js +98 -0
- package/src/Support/Item.js +63 -0
- package/src/Support/Items.js +363 -0
- package/src/Support/Str.js +209 -0
- package/src/Validator.js +27 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
let self = {
|
|
2
|
+
async load(file_path) {
|
|
3
|
+
let content = await Neutralino.filesystem.readFile(file_path);
|
|
4
|
+
content = content.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
5
|
+
|
|
6
|
+
let env = {};
|
|
7
|
+
let lines = content.split('\n');
|
|
8
|
+
|
|
9
|
+
for ( let line of lines ) {
|
|
10
|
+
line = line.trim();
|
|
11
|
+
|
|
12
|
+
if (!line || line.startsWith('#')) {
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Find the first = sign
|
|
17
|
+
const equal_index = line.indexOf('=');
|
|
18
|
+
if ( equal_index === -1 ) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Extract key and value
|
|
23
|
+
const key = line.substring(0, equal_index).trim();
|
|
24
|
+
let value = line.substring(equal_index + 1).trim();
|
|
25
|
+
|
|
26
|
+
// Remove quotes if present
|
|
27
|
+
if ( (value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'")) ) {
|
|
28
|
+
value = value.slice(1, -1);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Handle escaped characters in quoted strings
|
|
32
|
+
value = value.replace(/\\n/g, '\n')
|
|
33
|
+
.replace(/\\r/g, '\r')
|
|
34
|
+
.replace(/\\t/g, '\t')
|
|
35
|
+
.replace(/\\\\/g, '\\')
|
|
36
|
+
.replace(/\\"/g, '"')
|
|
37
|
+
.replace(/\\'/g, "'");
|
|
38
|
+
|
|
39
|
+
env[key] = value;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return env;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default self;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
let self = {
|
|
2
|
+
dmp(text) {
|
|
3
|
+
console.log(text);
|
|
4
|
+
},
|
|
5
|
+
|
|
6
|
+
handleEmpty(items) {
|
|
7
|
+
if ( items === false ) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if ( items === null ) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if ( Array.isArray(items) && !items.length ) {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if ( !Array.isArray(items) && !Object.keys(items).length ) {
|
|
20
|
+
return {};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return true;
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
array_unique(arr) {
|
|
27
|
+
return [...new Set(arr)];
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
decode_json(string) {
|
|
31
|
+
if ( typeof string == 'string') {
|
|
32
|
+
return JSON.parse(string);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return string;
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
encode_json(array, null_if_empty = true, return_empty_array = true) {
|
|
39
|
+
if ( typeof array == 'string' ) {
|
|
40
|
+
return array;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if ( array === null ) {
|
|
44
|
+
return null_if_empty ? null : JSON.stringify(return_empty_array ? [] : {});
|
|
45
|
+
}
|
|
46
|
+
else if ( Array.isArray(array) && !array.length ) {
|
|
47
|
+
return null_if_empty ? null : JSON.stringify([]);
|
|
48
|
+
}
|
|
49
|
+
else if ( array == '{}' ) {
|
|
50
|
+
return null_if_empty ? null : JSON.stringify({});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return JSON.stringify(array, (key, value) => (typeof value === "string" && value !== '' && !isNaN(value) ? Number(value) : value));
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
async custom_logger(e) {
|
|
57
|
+
if ( typeof e == 'object' ) {
|
|
58
|
+
e = e.toString();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let path = `${APP_PATH}/error.log`;
|
|
62
|
+
|
|
63
|
+
let date = new Date();
|
|
64
|
+
let timestamp = `${date.getFullYear()}-${Str.leading_zero(date.getMonth() + 1)}-${Str.leading_zero(date.getDate())}`+
|
|
65
|
+
` ${Str.leading_zero(date.getHours())}:${Str.leading_zero(date.getMinutes())}`;
|
|
66
|
+
|
|
67
|
+
await Neutralino.filesystem.appendFile(path, `[${timestamp}] ${e}`);
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
async file_exists(path) {
|
|
71
|
+
try {
|
|
72
|
+
await Neutralino.filesystem.getStats(path);
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
async ensure_dir(path) {
|
|
81
|
+
try {
|
|
82
|
+
await Neutralino.filesystem.createDirectory(path);
|
|
83
|
+
}
|
|
84
|
+
catch {}
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
async is_folder_empty(path) {
|
|
88
|
+
try {
|
|
89
|
+
let entries = await Neutralino.filesystem.readDirectory(path);
|
|
90
|
+
return entries.length == 0;
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export default self;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
let self = {
|
|
2
|
+
patch(item, data) {
|
|
3
|
+
return self.setKeys(item, Object.keys(data), Object.values(data));
|
|
4
|
+
},
|
|
5
|
+
|
|
6
|
+
setKey(item, key, value) {
|
|
7
|
+
return self.setKeys(item, key, value);
|
|
8
|
+
},
|
|
9
|
+
|
|
10
|
+
setKeys(item, keys, values) {
|
|
11
|
+
let not_empty = handleEmpty(item);
|
|
12
|
+
if ( not_empty !== true ) {
|
|
13
|
+
item = {};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if ( Array.isArray(keys) && !Array.isArray(values) ) {
|
|
17
|
+
let array_values = [];
|
|
18
|
+
for ( let key of keys ) {
|
|
19
|
+
array_values.push(values);
|
|
20
|
+
}
|
|
21
|
+
values = array_values;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if ( !Array.isArray(keys) ) {
|
|
25
|
+
keys = [keys];
|
|
26
|
+
values = [values];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
for ( let i = 0; i < keys.length; i++ ) {
|
|
30
|
+
item[keys[i]] = values[i];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return {...item};
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
removeEmptyKeys(item) {
|
|
37
|
+
let new_item = Array.isArray(item) ? [] : {};
|
|
38
|
+
let count = Array.isArray(item) ? item.length : Object.keys(item).length;
|
|
39
|
+
for ( let i = 0; i < count; i++ ) {
|
|
40
|
+
let index = Array.isArray(item) ? i : Object.keys(item)[i];
|
|
41
|
+
|
|
42
|
+
if ( item[index] !== '' ) {
|
|
43
|
+
new_item[index] = item[index];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return new_item;
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
deleteKeys(item, keys) {
|
|
51
|
+
for ( let key of keys ) {
|
|
52
|
+
delete item[key];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return {...item};
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
deleteKey(item, key) {
|
|
59
|
+
return self.deleteKeys(item, [key]);
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export default self;
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
const self = {
|
|
2
|
+
pluck(items, key = 'id') {
|
|
3
|
+
let plucked = [];
|
|
4
|
+
for (let i = 0; i < items.length; i++) {
|
|
5
|
+
plucked.push(items[i][key]);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return plucked;
|
|
9
|
+
},
|
|
10
|
+
|
|
11
|
+
spread(items) {
|
|
12
|
+
return JSON.parse(JSON.stringify(items));
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
keyBy(items, key = 'id') {
|
|
16
|
+
let not_empty = handleEmpty(items);
|
|
17
|
+
if ( not_empty !== true ) {
|
|
18
|
+
return not_empty;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let new_items = {};
|
|
22
|
+
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
23
|
+
for ( let i = 0; i < count; i++ ) {
|
|
24
|
+
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
25
|
+
new_items[items[index][key]] = items[index];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return new_items;
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
groupBy(items, key = 'id') {
|
|
32
|
+
let not_empty = handleEmpty(items);
|
|
33
|
+
if ( not_empty !== true ) {
|
|
34
|
+
return not_empty;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let new_items = Array.isArray(items) ? [] : {};
|
|
38
|
+
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
39
|
+
for ( let i = 0; i < count; i++ ) {
|
|
40
|
+
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
41
|
+
|
|
42
|
+
if (typeof new_items[items[index][key]] === 'undefined') {
|
|
43
|
+
new_items[items[index][key]] = [];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
new_items[items[index][key]].push(items[index]);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return new_items;
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
find(items, ids) {
|
|
53
|
+
let not_empty = handleEmpty(items);
|
|
54
|
+
if ( not_empty !== true ) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
let single = false;
|
|
59
|
+
if ( !Array.isArray(ids) ) {
|
|
60
|
+
if ( typeof ids === 'string' ) {
|
|
61
|
+
ids = parseInt(ids);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
ids = [ids];
|
|
65
|
+
single = true;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
let new_items = Array.isArray(items) ? [] : {};
|
|
69
|
+
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
70
|
+
for ( let i = 0; i < count; i++ ) {
|
|
71
|
+
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
72
|
+
|
|
73
|
+
if ( ids.includes(parseInt(items[index].id)) ) {
|
|
74
|
+
if ( Array.isArray(items) ) {
|
|
75
|
+
new_items.push(items[index]);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
new_items[index] = items[index];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if ( single ) {
|
|
84
|
+
if ( Array.isArray(new_items) && new_items.length ) {
|
|
85
|
+
return new_items[0];
|
|
86
|
+
}
|
|
87
|
+
else if ( !Array.isArray(new_items) && Object.keys(new_items).length ) {
|
|
88
|
+
return new_items[Object.keys(new_items)[0]];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return new_items;
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
findByKey(items, key, value = true, single = false) {
|
|
98
|
+
let not_empty = handleEmpty(items);
|
|
99
|
+
if ( not_empty !== true ) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
let new_items = Array.isArray(items) ? [] : {};
|
|
104
|
+
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
105
|
+
for ( let i = 0; i < count; i++ ) {
|
|
106
|
+
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
107
|
+
|
|
108
|
+
if ( items[index][key] == value ) {
|
|
109
|
+
if ( Array.isArray(items) ) {
|
|
110
|
+
new_items.push(items[index]);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
new_items[index] = items[index];
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if ( single ) {
|
|
119
|
+
if ( Array.isArray(new_items) && new_items.length ) {
|
|
120
|
+
return new_items[0];
|
|
121
|
+
}
|
|
122
|
+
else if ( !Array.isArray(new_items) && Object.keys(new_items).length ) {
|
|
123
|
+
return new_items[Object.keys(new_items)[0]];
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return new_items;
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
add(items, item, at_first_position = false) {
|
|
133
|
+
let not_empty = handleEmpty(items);
|
|
134
|
+
if ( not_empty !== true ) {
|
|
135
|
+
items = [];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if ( at_first_position ) {
|
|
139
|
+
items.unshift(item);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
items.push(item);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return items;
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
addMany(items, added, at_first_position = false) {
|
|
149
|
+
let not_empty = handleEmpty(items);
|
|
150
|
+
if ( not_empty !== true ) {
|
|
151
|
+
items = [];
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if ( at_first_position ) {
|
|
155
|
+
return added.concat(items);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
return items.concat(added);
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
|
|
162
|
+
patch(items, data) {
|
|
163
|
+
if ( !data.id ) {
|
|
164
|
+
throw 'ID is required.';
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
let id = data.id;
|
|
168
|
+
delete data.id;
|
|
169
|
+
|
|
170
|
+
return self.setKeys(items, id, Object.keys(data), Object.values(data));
|
|
171
|
+
},
|
|
172
|
+
|
|
173
|
+
replace(items, item) {
|
|
174
|
+
let not_empty = handleEmpty(items);
|
|
175
|
+
if ( not_empty !== true ) {
|
|
176
|
+
return not_empty;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
let new_items = Array.isArray(items) ? [] : {};
|
|
180
|
+
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
181
|
+
for ( let i = 0; i < count; i++ ) {
|
|
182
|
+
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
183
|
+
|
|
184
|
+
if ( items[index].id == item.id ) {
|
|
185
|
+
new_items[index] = item;
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
new_items[index] = items[index];
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return new_items;
|
|
193
|
+
},
|
|
194
|
+
|
|
195
|
+
delete(items, ids) {
|
|
196
|
+
let not_empty = handleEmpty(items);
|
|
197
|
+
if ( not_empty !== true ) {
|
|
198
|
+
return not_empty;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if ( !Array.isArray(ids) ) {
|
|
202
|
+
if ( typeof ids === 'string' ) {
|
|
203
|
+
ids = parseInt(ids);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
ids = [ids];
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
let new_items = Array.isArray(items) ? [] : {};
|
|
210
|
+
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
211
|
+
for ( let i = 0; i < count; i++ ) {
|
|
212
|
+
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
213
|
+
|
|
214
|
+
if ( ids.includes(parseInt(items[index].id)) ) {
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if ( Array.isArray(items) ) {
|
|
219
|
+
new_items.push(items[index]);
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
new_items[index] = items[index];
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return new_items;
|
|
227
|
+
},
|
|
228
|
+
|
|
229
|
+
deleteByKey(items, key, value) {
|
|
230
|
+
let not_empty = handleEmpty(items);
|
|
231
|
+
if ( not_empty !== true ) {
|
|
232
|
+
return not_empty;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
let new_items = Array.isArray(items) ? [] : {};
|
|
236
|
+
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
237
|
+
for ( let i = 0; i < count; i++ ) {
|
|
238
|
+
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
239
|
+
|
|
240
|
+
if ( items[index][key] != value ) {
|
|
241
|
+
new_items[index] = items[index];
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return new_items;
|
|
246
|
+
},
|
|
247
|
+
|
|
248
|
+
setKey(items, id, key, value) {
|
|
249
|
+
return self.setKeys(items, id, key, value);
|
|
250
|
+
},
|
|
251
|
+
|
|
252
|
+
setKeys(items, ids, keys, values) {
|
|
253
|
+
let not_empty = handleEmpty(items);
|
|
254
|
+
if ( not_empty !== true ) {
|
|
255
|
+
return not_empty;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if ( !Array.isArray(ids) ) {
|
|
259
|
+
if ( typeof ids === 'string' ) {
|
|
260
|
+
ids = parseInt(ids);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
ids = [ids];
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if ( Array.isArray(keys) && !Array.isArray(values) ) {
|
|
267
|
+
let array_values = [];
|
|
268
|
+
for ( let key of keys ) {
|
|
269
|
+
array_values.push(values);
|
|
270
|
+
}
|
|
271
|
+
values = array_values;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if ( !Array.isArray(keys) ) {
|
|
275
|
+
keys = [keys];
|
|
276
|
+
values = [values];
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
280
|
+
for ( let i = 0; i < count; i++ ) {
|
|
281
|
+
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
282
|
+
|
|
283
|
+
if ( ids.includes(parseInt(items[index].id)) ) {
|
|
284
|
+
for ( let j = 0; j < keys.length; j++ ) {
|
|
285
|
+
items[i][keys[j]] = values[j];
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return items;
|
|
291
|
+
},
|
|
292
|
+
|
|
293
|
+
toggleKey(items, id, key) {
|
|
294
|
+
return self.toggleKeys(items, id, key);
|
|
295
|
+
},
|
|
296
|
+
|
|
297
|
+
toggleKeys(items, ids, keys) {
|
|
298
|
+
let not_empty = handleEmpty(items);
|
|
299
|
+
if ( not_empty !== true ) {
|
|
300
|
+
return not_empty;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if ( !Array.isArray(ids) ) {
|
|
304
|
+
if ( typeof ids === 'string' ) {
|
|
305
|
+
ids = parseInt(ids);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
ids = [ids];
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if ( !Array.isArray(keys) ) {
|
|
312
|
+
keys = [keys];
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
316
|
+
for ( let i = 0; i < count; i++ ) {
|
|
317
|
+
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
318
|
+
|
|
319
|
+
if ( ids.includes(parseInt(items[index].id)) ) {
|
|
320
|
+
for ( let j = 0; j < keys.length; j++ ) {
|
|
321
|
+
items[index][keys[j]] = !items[index][keys[j]];
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
return items;
|
|
327
|
+
},
|
|
328
|
+
|
|
329
|
+
sort(items, from, to) {
|
|
330
|
+
const copy = [...items];
|
|
331
|
+
const valueToMove = copy.splice(from, 1)[0];
|
|
332
|
+
copy.splice(to, 0, valueToMove);
|
|
333
|
+
|
|
334
|
+
return copy;
|
|
335
|
+
},
|
|
336
|
+
|
|
337
|
+
next(items, current, key = 'id') {
|
|
338
|
+
for ( let i = 0; i < items.length; i++ ) {
|
|
339
|
+
if ( items[i][key] == current[key] && i < items.length - 1 ) {
|
|
340
|
+
return items[i + 1];
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
return false;
|
|
345
|
+
},
|
|
346
|
+
|
|
347
|
+
prev(items, current, key = 'id') {
|
|
348
|
+
for ( let i = items.length - 1; i >= 0; i-- ) {
|
|
349
|
+
if ( items[i][key] == current[key] && i > 0 ) {
|
|
350
|
+
return items[i - 1];
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
return false;
|
|
355
|
+
},
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
window.pluck = self.pluck;
|
|
359
|
+
window.spread = self.spread;
|
|
360
|
+
window.keyBy = self.keyBy;
|
|
361
|
+
window.groupBy = self.groupBy;
|
|
362
|
+
|
|
363
|
+
export default self;
|