@tidyjs/tidy 2.4.1 → 2.4.5
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/dist/es/arrange.js +1 -1
- package/dist/es/arrange.js.map +1 -1
- package/dist/es/fullJoin.js +16 -4
- package/dist/es/fullJoin.js.map +1 -1
- package/dist/es/groupBy.js +5 -3
- package/dist/es/groupBy.js.map +1 -1
- package/dist/es/helpers/isObject.js +7 -0
- package/dist/es/helpers/isObject.js.map +1 -0
- package/dist/es/leftJoin.js +8 -1
- package/dist/es/leftJoin.js.map +1 -1
- package/dist/lib/arrange.js +1 -1
- package/dist/lib/arrange.js.map +1 -1
- package/dist/lib/fullJoin.js +16 -4
- package/dist/lib/fullJoin.js.map +1 -1
- package/dist/lib/groupBy.js +5 -3
- package/dist/lib/groupBy.js.map +1 -1
- package/dist/lib/helpers/isObject.js +11 -0
- package/dist/lib/helpers/isObject.js.map +1 -0
- package/dist/lib/leftJoin.js +8 -1
- package/dist/lib/leftJoin.js.map +1 -1
- package/dist/tidy.d.ts +1 -1
- package/dist/umd/tidy.js +34 -9
- package/dist/umd/tidy.js.map +1 -1
- package/dist/umd/tidy.min.js +1 -1
- package/dist/umd/tidy.min.js.map +1 -1
- package/package.json +2 -2
package/dist/umd/tidy.js
CHANGED
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
|
|
85
85
|
function arrange(comparators) {
|
|
86
86
|
const _arrange = (items) => {
|
|
87
|
-
const comparatorFns = singleOrArray(comparators).map((comp) => typeof comp === "function" ? comp : asc(comp));
|
|
87
|
+
const comparatorFns = singleOrArray(comparators).map((comp) => typeof comp === "function" ? comp.length === 1 ? asc(comp) : comp : asc(comp));
|
|
88
88
|
return items.slice().sort((a, b) => {
|
|
89
89
|
for (const comparator of comparatorFns) {
|
|
90
90
|
const result = comparator(a, b);
|
|
@@ -301,6 +301,11 @@
|
|
|
301
301
|
|
|
302
302
|
const identity = (d) => d;
|
|
303
303
|
|
|
304
|
+
function isObject(obj) {
|
|
305
|
+
const type = typeof obj;
|
|
306
|
+
return obj != null && (type === "object" || type === "function");
|
|
307
|
+
}
|
|
308
|
+
|
|
304
309
|
function groupBy(groupKeys, fns, options) {
|
|
305
310
|
if (typeof fns === "function") {
|
|
306
311
|
fns = [fns];
|
|
@@ -368,11 +373,12 @@
|
|
|
368
373
|
const keyCache = new Map();
|
|
369
374
|
return (d) => {
|
|
370
375
|
const keyValue = keyFn(d);
|
|
371
|
-
|
|
372
|
-
|
|
376
|
+
const keyValueOf = isObject(keyValue) ? keyValue.valueOf() : keyValue;
|
|
377
|
+
if (keyCache.has(keyValueOf)) {
|
|
378
|
+
return keyCache.get(keyValueOf);
|
|
373
379
|
}
|
|
374
380
|
const keyWithName = [key, keyValue];
|
|
375
|
-
keyCache.set(
|
|
381
|
+
keyCache.set(keyValueOf, keyWithName);
|
|
376
382
|
return keyWithName;
|
|
377
383
|
};
|
|
378
384
|
});
|
|
@@ -633,10 +639,17 @@
|
|
|
633
639
|
|
|
634
640
|
function leftJoin(itemsToJoin, options) {
|
|
635
641
|
const _leftJoin = (items) => {
|
|
642
|
+
if (!itemsToJoin.length)
|
|
643
|
+
return items;
|
|
636
644
|
const byMap = (options == null ? void 0 : options.by) == null ? autodetectByMap(items, itemsToJoin) : makeByMap(options.by);
|
|
645
|
+
const joinObjectKeys = Object.keys(itemsToJoin[0]);
|
|
637
646
|
const joined = items.flatMap((d) => {
|
|
638
647
|
const matches = itemsToJoin.filter((j) => isMatch(d, j, byMap));
|
|
639
|
-
|
|
648
|
+
if (matches.length) {
|
|
649
|
+
return matches.map((j) => ({...d, ...j}));
|
|
650
|
+
}
|
|
651
|
+
const undefinedFill = Object.fromEntries(joinObjectKeys.filter((key) => d[key] == null).map((key) => [key, void 0]));
|
|
652
|
+
return {...d, ...undefinedFill};
|
|
640
653
|
});
|
|
641
654
|
return joined;
|
|
642
655
|
};
|
|
@@ -645,8 +658,13 @@
|
|
|
645
658
|
|
|
646
659
|
function fullJoin(itemsToJoin, options) {
|
|
647
660
|
const _fullJoin = (items) => {
|
|
661
|
+
if (!itemsToJoin.length)
|
|
662
|
+
return items;
|
|
663
|
+
if (!items.length)
|
|
664
|
+
return itemsToJoin;
|
|
648
665
|
const byMap = (options == null ? void 0 : options.by) == null ? autodetectByMap(items, itemsToJoin) : makeByMap(options.by);
|
|
649
666
|
const matchMap = new Map();
|
|
667
|
+
const joinObjectKeys = Object.keys(itemsToJoin[0]);
|
|
650
668
|
const joined = items.flatMap((d) => {
|
|
651
669
|
const matches = itemsToJoin.filter((j) => {
|
|
652
670
|
const matched = isMatch(d, j, byMap);
|
|
@@ -655,11 +673,18 @@
|
|
|
655
673
|
}
|
|
656
674
|
return matched;
|
|
657
675
|
});
|
|
658
|
-
|
|
676
|
+
if (matches.length) {
|
|
677
|
+
return matches.map((j) => ({...d, ...j}));
|
|
678
|
+
}
|
|
679
|
+
const undefinedFill = Object.fromEntries(joinObjectKeys.filter((key) => d[key] == null).map((key) => [key, void 0]));
|
|
680
|
+
return {...d, ...undefinedFill};
|
|
659
681
|
});
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
682
|
+
if (matchMap.size < itemsToJoin.length) {
|
|
683
|
+
const leftEmptyObject = Object.fromEntries(Object.keys(items[0]).map((key) => [key, void 0]));
|
|
684
|
+
for (const item of itemsToJoin) {
|
|
685
|
+
if (!matchMap.has(item)) {
|
|
686
|
+
joined.push({...leftEmptyObject, ...item});
|
|
687
|
+
}
|
|
663
688
|
}
|
|
664
689
|
}
|
|
665
690
|
return joined;
|