@radiantabyss/vue 3.3.19 → 4.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.
@@ -1,67 +0,0 @@
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 = window.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
- clone(item) {
63
- return JSON.parse(JSON.stringify(item));
64
- },
65
- };
66
-
67
- export default self;
@@ -1,363 +0,0 @@
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 = window.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 = window.handleEmpty(items);
33
- if ( not_empty !== true ) {
34
- return not_empty;
35
- }
36
-
37
- let new_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 = window.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 = window.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 = window.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 = window.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 = window.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 = window.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 = window.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 = window.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 = window.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;