1 | "use strict";
|
2 |
|
3 | exports.__esModule = true;
|
4 | exports.toItemArray = toItemArray;
|
5 | exports.chunk = chunk;
|
6 | exports.groupBySortedKeys = groupBySortedKeys;
|
7 | exports.has = exports.makeArray = void 0;
|
8 |
|
9 | var _tinyWarning = _interopRequireDefault(require("tiny-warning"));
|
10 |
|
11 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
12 |
|
13 |
|
14 | function toItemArray(a) {
|
15 | if (Array.isArray(a)) return a;
|
16 | return [];
|
17 | }
|
18 |
|
19 | const makeArray = (obj, excludeNull = true) => {
|
20 | const result = [];
|
21 | return excludeNull ? obj == null ? result : result.concat(obj) : result.concat(obj);
|
22 | };
|
23 |
|
24 | exports.makeArray = makeArray;
|
25 |
|
26 | const has = (o, key) => o ? Object.prototype.hasOwnProperty.call(o, key) : false;
|
27 |
|
28 | exports.has = has;
|
29 |
|
30 | function chunk(array, chunkSize) {
|
31 | let index = 0;
|
32 | let length = array ? array.length : 0;
|
33 | let result = [];
|
34 | chunkSize = Math.max(+chunkSize || 1, 1);
|
35 |
|
36 | while (index < length) result.push(array.slice(index, index += chunkSize));
|
37 |
|
38 | return result;
|
39 | }
|
40 |
|
41 | function groupBySortedKeys(groupBy, data, _keys = []) {
|
42 | const iter = typeof groupBy === 'function' ? groupBy : item => item[groupBy];
|
43 | (0, _tinyWarning.default)(typeof groupBy !== 'string' || !data.length || has(data[0], groupBy), `[React Widgets] You seem to be trying to group this list by a ` + `property \`${groupBy}\` that doesn't exist in the dataset items, this may be a typo`);
|
44 | const groups = new Map();
|
45 | data.forEach(item => {
|
46 | let group = iter(item);
|
47 | if (groups.has(group)) groups.get(group).push(item);else groups.set(group, [item]);
|
48 | });
|
49 | return Array.from(groups);
|
50 | } |
\ | No newline at end of file |