@baleada/logic 0.21.1 → 0.21.2
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/lib/index.cjs +20 -16
- package/lib/index.d.ts +5 -3
- package/lib/index.js +20 -16
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -2704,6 +2704,10 @@ class Navigateable {
|
|
|
2704
2704
|
const defaultOptions$1 = {
|
|
2705
2705
|
initialPicks: []
|
|
2706
2706
|
};
|
|
2707
|
+
const defaultPickOptions = {
|
|
2708
|
+
replace: "none",
|
|
2709
|
+
allowsDuplicates: false
|
|
2710
|
+
};
|
|
2707
2711
|
class Pickable {
|
|
2708
2712
|
constructor(array, options = {}) {
|
|
2709
2713
|
this.setArray(array);
|
|
@@ -2762,37 +2766,37 @@ class Pickable {
|
|
|
2762
2766
|
return this.pick(indexOrIndices);
|
|
2763
2767
|
}
|
|
2764
2768
|
pick(indexOrIndices, options = {}) {
|
|
2765
|
-
const { replace
|
|
2769
|
+
const { replace, allowsDuplicates } = { ...defaultPickOptions, ...options };
|
|
2766
2770
|
this.computedPicks = new Pipeable(indexOrIndices).pipe(ensureIndices, this.toPossiblePicks, (possiblePicks) => {
|
|
2767
2771
|
if (replace === "all") {
|
|
2768
|
-
return toUnique(possiblePicks);
|
|
2772
|
+
return allowsDuplicates ? possiblePicks : toUnique(possiblePicks);
|
|
2769
2773
|
}
|
|
2770
|
-
const
|
|
2774
|
+
const maybeWithoutDuplicates = allowsDuplicates ? possiblePicks : createFilter((possiblePick) => typeof lazyCollections.find((pick) => pick === possiblePick)(this.picks || []) !== "number")(possiblePicks);
|
|
2771
2775
|
switch (replace) {
|
|
2772
2776
|
case "none":
|
|
2773
|
-
return createConcat(this.picks || [],
|
|
2777
|
+
return createConcat(this.picks || [], maybeWithoutDuplicates)([]);
|
|
2774
2778
|
case "fifo":
|
|
2775
|
-
if (
|
|
2779
|
+
if (maybeWithoutDuplicates.length === 0) {
|
|
2776
2780
|
return this.picks;
|
|
2777
2781
|
}
|
|
2778
|
-
if (
|
|
2779
|
-
return
|
|
2782
|
+
if (maybeWithoutDuplicates.length === this.picks.length) {
|
|
2783
|
+
return maybeWithoutDuplicates;
|
|
2780
2784
|
}
|
|
2781
|
-
if (
|
|
2782
|
-
return createSlice(
|
|
2785
|
+
if (maybeWithoutDuplicates.length > this.picks.length) {
|
|
2786
|
+
return createSlice(maybeWithoutDuplicates.length - this.picks.length)(maybeWithoutDuplicates);
|
|
2783
2787
|
}
|
|
2784
|
-
return new Pipeable(this.picks).pipe(createSlice(
|
|
2788
|
+
return new Pipeable(this.picks).pipe(createSlice(maybeWithoutDuplicates.length), createConcat(maybeWithoutDuplicates));
|
|
2785
2789
|
case "lifo":
|
|
2786
|
-
if (
|
|
2790
|
+
if (maybeWithoutDuplicates.length === 0) {
|
|
2787
2791
|
return this.picks;
|
|
2788
2792
|
}
|
|
2789
|
-
if (
|
|
2790
|
-
return
|
|
2793
|
+
if (maybeWithoutDuplicates.length === this.picks.length) {
|
|
2794
|
+
return maybeWithoutDuplicates;
|
|
2791
2795
|
}
|
|
2792
|
-
if (
|
|
2793
|
-
return createSlice(0,
|
|
2796
|
+
if (maybeWithoutDuplicates.length > this.picks.length) {
|
|
2797
|
+
return createSlice(0, maybeWithoutDuplicates.length - this.picks.length + 1)(maybeWithoutDuplicates);
|
|
2794
2798
|
}
|
|
2795
|
-
return new Pipeable(this.picks).pipe(createSlice(0, this.picks.length -
|
|
2799
|
+
return new Pipeable(this.picks).pipe(createSlice(0, this.picks.length - maybeWithoutDuplicates.length), createConcat(maybeWithoutDuplicates));
|
|
2796
2800
|
}
|
|
2797
2801
|
});
|
|
2798
2802
|
this.computedFirst = Math.min(...this.picks);
|
package/lib/index.d.ts
CHANGED
|
@@ -607,6 +607,10 @@ declare type PickableOptions = {
|
|
|
607
607
|
initialPicks?: number | number[];
|
|
608
608
|
};
|
|
609
609
|
declare type PickableStatus = 'ready' | 'picked' | 'omitted';
|
|
610
|
+
declare type PickOptions = {
|
|
611
|
+
replace?: 'none' | 'all' | 'fifo' | 'lifo';
|
|
612
|
+
allowsDuplicates?: boolean;
|
|
613
|
+
};
|
|
610
614
|
declare class Pickable<Item> {
|
|
611
615
|
constructor(array: Item[], options?: PickableOptions);
|
|
612
616
|
private computedStatus;
|
|
@@ -630,9 +634,7 @@ declare class Pickable<Item> {
|
|
|
630
634
|
private toPossiblePicks;
|
|
631
635
|
setArray(array: Item[]): this;
|
|
632
636
|
setPicks(indexOrIndices: number | number[]): this;
|
|
633
|
-
pick(indexOrIndices: number | number[], options?:
|
|
634
|
-
replace?: 'none' | 'all' | 'fifo' | 'lifo';
|
|
635
|
-
}): this;
|
|
637
|
+
pick(indexOrIndices: number | number[], options?: PickOptions): this;
|
|
636
638
|
private picked;
|
|
637
639
|
omit(indexOrIndices?: number | number[], options?: {
|
|
638
640
|
reference?: 'array' | 'picks';
|
package/lib/index.js
CHANGED
|
@@ -2693,6 +2693,10 @@ class Navigateable {
|
|
|
2693
2693
|
const defaultOptions$1 = {
|
|
2694
2694
|
initialPicks: []
|
|
2695
2695
|
};
|
|
2696
|
+
const defaultPickOptions = {
|
|
2697
|
+
replace: "none",
|
|
2698
|
+
allowsDuplicates: false
|
|
2699
|
+
};
|
|
2696
2700
|
class Pickable {
|
|
2697
2701
|
constructor(array, options = {}) {
|
|
2698
2702
|
this.setArray(array);
|
|
@@ -2751,37 +2755,37 @@ class Pickable {
|
|
|
2751
2755
|
return this.pick(indexOrIndices);
|
|
2752
2756
|
}
|
|
2753
2757
|
pick(indexOrIndices, options = {}) {
|
|
2754
|
-
const { replace
|
|
2758
|
+
const { replace, allowsDuplicates } = { ...defaultPickOptions, ...options };
|
|
2755
2759
|
this.computedPicks = new Pipeable(indexOrIndices).pipe(ensureIndices, this.toPossiblePicks, (possiblePicks) => {
|
|
2756
2760
|
if (replace === "all") {
|
|
2757
|
-
return toUnique(possiblePicks);
|
|
2761
|
+
return allowsDuplicates ? possiblePicks : toUnique(possiblePicks);
|
|
2758
2762
|
}
|
|
2759
|
-
const
|
|
2763
|
+
const maybeWithoutDuplicates = allowsDuplicates ? possiblePicks : createFilter((possiblePick) => typeof find((pick) => pick === possiblePick)(this.picks || []) !== "number")(possiblePicks);
|
|
2760
2764
|
switch (replace) {
|
|
2761
2765
|
case "none":
|
|
2762
|
-
return createConcat(this.picks || [],
|
|
2766
|
+
return createConcat(this.picks || [], maybeWithoutDuplicates)([]);
|
|
2763
2767
|
case "fifo":
|
|
2764
|
-
if (
|
|
2768
|
+
if (maybeWithoutDuplicates.length === 0) {
|
|
2765
2769
|
return this.picks;
|
|
2766
2770
|
}
|
|
2767
|
-
if (
|
|
2768
|
-
return
|
|
2771
|
+
if (maybeWithoutDuplicates.length === this.picks.length) {
|
|
2772
|
+
return maybeWithoutDuplicates;
|
|
2769
2773
|
}
|
|
2770
|
-
if (
|
|
2771
|
-
return createSlice(
|
|
2774
|
+
if (maybeWithoutDuplicates.length > this.picks.length) {
|
|
2775
|
+
return createSlice(maybeWithoutDuplicates.length - this.picks.length)(maybeWithoutDuplicates);
|
|
2772
2776
|
}
|
|
2773
|
-
return new Pipeable(this.picks).pipe(createSlice(
|
|
2777
|
+
return new Pipeable(this.picks).pipe(createSlice(maybeWithoutDuplicates.length), createConcat(maybeWithoutDuplicates));
|
|
2774
2778
|
case "lifo":
|
|
2775
|
-
if (
|
|
2779
|
+
if (maybeWithoutDuplicates.length === 0) {
|
|
2776
2780
|
return this.picks;
|
|
2777
2781
|
}
|
|
2778
|
-
if (
|
|
2779
|
-
return
|
|
2782
|
+
if (maybeWithoutDuplicates.length === this.picks.length) {
|
|
2783
|
+
return maybeWithoutDuplicates;
|
|
2780
2784
|
}
|
|
2781
|
-
if (
|
|
2782
|
-
return createSlice(0,
|
|
2785
|
+
if (maybeWithoutDuplicates.length > this.picks.length) {
|
|
2786
|
+
return createSlice(0, maybeWithoutDuplicates.length - this.picks.length + 1)(maybeWithoutDuplicates);
|
|
2783
2787
|
}
|
|
2784
|
-
return new Pipeable(this.picks).pipe(createSlice(0, this.picks.length -
|
|
2788
|
+
return new Pipeable(this.picks).pipe(createSlice(0, this.picks.length - maybeWithoutDuplicates.length), createConcat(maybeWithoutDuplicates));
|
|
2785
2789
|
}
|
|
2786
2790
|
});
|
|
2787
2791
|
this.computedFirst = Math.min(...this.picks);
|