@applicaster/zapp-react-native-utils 14.0.0-alpha.1101330035 → 14.0.0-alpha.1152359078
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/actionsExecutor/ActionExecutorContext.tsx +0 -1
- package/actionsExecutor/ScreenActions.ts +20 -19
- package/analyticsUtils/AnalyticPlayerListener.ts +5 -2
- package/analyticsUtils/AnalyticsEvents/sendHeaderClickEvent.ts +1 -1
- package/analyticsUtils/AnalyticsEvents/sendMenuClickEvent.ts +2 -1
- package/analyticsUtils/__tests__/analyticsUtils.test.js +0 -11
- package/analyticsUtils/index.tsx +3 -4
- package/analyticsUtils/manager.ts +1 -1
- package/analyticsUtils/playerAnalyticsTracker.ts +2 -1
- package/appUtils/HooksManager/Hook.ts +4 -4
- package/appUtils/HooksManager/index.ts +11 -1
- package/appUtils/accessibilityManager/const.ts +13 -0
- package/appUtils/accessibilityManager/hooks.ts +35 -1
- package/appUtils/accessibilityManager/index.ts +150 -29
- package/appUtils/accessibilityManager/utils.ts +24 -0
- package/appUtils/contextKeysManager/contextResolver.ts +29 -1
- package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +8 -0
- package/appUtils/focusManager/__tests__/focusManager.test.js +1 -1
- package/appUtils/focusManager/events.ts +2 -0
- package/appUtils/focusManager/index.ios.ts +27 -0
- package/appUtils/focusManager/index.ts +86 -11
- package/appUtils/focusManager/treeDataStructure/Tree/index.js +1 -1
- package/appUtils/focusManagerAux/utils/index.ts +112 -3
- package/appUtils/focusManagerAux/utils/utils.ios.ts +35 -0
- package/appUtils/platform/platformUtils.ts +33 -3
- package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +94 -4
- package/appUtils/playerManager/OverlayObserver/utils.ts +32 -20
- package/appUtils/playerManager/conts.ts +21 -0
- package/arrayUtils/__tests__/allTruthy.test.ts +24 -0
- package/arrayUtils/__tests__/anyThruthy.test.ts +24 -0
- package/arrayUtils/index.ts +6 -1
- package/componentsUtils/__tests__/isTabsScreen.test.ts +38 -0
- package/componentsUtils/index.ts +4 -1
- package/configurationUtils/__tests__/manifestKeyParser.test.ts +0 -1
- package/configurationUtils/index.ts +1 -1
- package/focusManager/FocusManager.ts +78 -4
- package/focusManager/aux/index.ts +98 -0
- package/focusManager/utils.ts +12 -6
- package/index.d.ts +1 -10
- package/manifestUtils/defaultManifestConfigurations/player.js +188 -2
- package/manifestUtils/index.js +4 -0
- package/manifestUtils/keys.js +33 -0
- package/manifestUtils/sharedConfiguration/screenPicker/stylesFields.js +6 -0
- package/manifestUtils/sharedConfiguration/screenPicker/utils.js +1 -0
- package/navigationUtils/__tests__/mapContentTypesToRivers.test.ts +130 -0
- package/navigationUtils/index.ts +26 -21
- package/package.json +2 -3
- package/playerUtils/PlayerTTS/PlayerTTS.ts +359 -0
- package/playerUtils/PlayerTTS/index.ts +1 -0
- package/playerUtils/getPlayerActionButtons.ts +1 -1
- package/playerUtils/usePlayerTTS.ts +21 -0
- package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +15 -14
- package/reactHooks/cell-click/__tests__/index.test.js +3 -0
- package/reactHooks/debugging/__tests__/index.test.js +0 -1
- package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +47 -90
- package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +57 -37
- package/reactHooks/feed/index.ts +2 -0
- package/reactHooks/feed/useBatchLoading.ts +15 -8
- package/reactHooks/feed/useFeedLoader.tsx +39 -53
- package/reactHooks/feed/useInflatedUrl.ts +23 -29
- package/reactHooks/feed/useLoadPipesDataDispatch.ts +63 -0
- package/reactHooks/feed/usePipesCacheReset.ts +2 -2
- package/reactHooks/flatList/useSequentialRenderItem.tsx +3 -3
- package/reactHooks/layout/__tests__/index.test.tsx +3 -1
- package/reactHooks/layout/index.ts +1 -1
- package/reactHooks/layout/useDimensions/__tests__/useDimensions.test.ts +34 -36
- package/reactHooks/layout/useDimensions/useDimensions.ts +2 -3
- package/reactHooks/layout/useLayoutVersion.ts +5 -5
- package/reactHooks/navigation/index.ts +5 -7
- package/reactHooks/navigation/useScreenStateStore.ts +3 -3
- package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +4 -0
- package/reactHooks/state/index.ts +1 -1
- package/reactHooks/state/useHomeRiver.ts +4 -2
- package/reactHooks/state/useRivers.ts +7 -8
- package/screenPickerUtils/index.ts +13 -0
- package/storage/ScreenSingleValueProvider.ts +25 -22
- package/storage/ScreenStateMultiSelectProvider.ts +26 -23
- package/testUtils/index.tsx +7 -8
- package/time/BackgroundTimer.ts +1 -1
- package/utils/__tests__/endsWith.test.ts +30 -0
- package/utils/__tests__/find.test.ts +36 -0
- package/utils/__tests__/mapAccum.test.ts +73 -0
- package/utils/__tests__/omit.test.ts +19 -0
- package/utils/__tests__/path.test.ts +33 -0
- package/utils/__tests__/pathOr.test.ts +37 -0
- package/utils/__tests__/startsWith.test.ts +30 -0
- package/utils/__tests__/take.test.ts +40 -0
- package/utils/endsWith.ts +9 -0
- package/utils/find.ts +3 -0
- package/utils/index.ts +23 -1
- package/utils/mapAccum.ts +23 -0
- package/utils/omit.ts +5 -0
- package/utils/path.ts +5 -0
- package/utils/pathOr.ts +5 -0
- package/utils/startsWith.ts +9 -0
- package/utils/take.ts +5 -0
|
@@ -2,6 +2,7 @@ import { BehaviorSubject } from "rxjs";
|
|
|
2
2
|
import { SingleValueProvider } from "./StorageSingleSelectProvider";
|
|
3
3
|
import { createLogger } from "../logger";
|
|
4
4
|
import { bridgeLogger } from "../../zapp-react-native-bridge/logger";
|
|
5
|
+
import { useScreenStateStore } from "../reactHooks/navigation/useScreenStateStore";
|
|
5
6
|
|
|
6
7
|
export const { log_debug, log_error } = createLogger({
|
|
7
8
|
category: "ScreenSingleValueProvider",
|
|
@@ -22,7 +23,7 @@ export class ScreenSingleValueProvider implements SingleValueProvider {
|
|
|
22
23
|
public static getProvider(
|
|
23
24
|
key: string,
|
|
24
25
|
screenRoute: string,
|
|
25
|
-
screenStateStore:
|
|
26
|
+
screenStateStore: ReturnType<typeof useScreenStateStore>
|
|
26
27
|
): SingleValueProvider {
|
|
27
28
|
if (!key) {
|
|
28
29
|
throw new Error("ScreenSingleValueProvider: Key is required");
|
|
@@ -66,7 +67,7 @@ export class ScreenSingleValueProvider implements SingleValueProvider {
|
|
|
66
67
|
private constructor(
|
|
67
68
|
private key: string,
|
|
68
69
|
route: string,
|
|
69
|
-
private screenStateStore:
|
|
70
|
+
private screenStateStore: ReturnType<typeof useScreenStateStore>
|
|
70
71
|
) {
|
|
71
72
|
if (!key) {
|
|
72
73
|
throw new Error("ScreenSingleValueProvider: Key is required");
|
|
@@ -88,7 +89,9 @@ export class ScreenSingleValueProvider implements SingleValueProvider {
|
|
|
88
89
|
log_debug("ScreenSingleValueProvider: Initializing", { key, route });
|
|
89
90
|
}
|
|
90
91
|
|
|
91
|
-
private updateStore(
|
|
92
|
+
private updateStore(
|
|
93
|
+
screenStateStore: ReturnType<typeof useScreenStateStore>
|
|
94
|
+
): void {
|
|
92
95
|
this.cleanup();
|
|
93
96
|
this.screenStateStore = screenStateStore;
|
|
94
97
|
this.setupScreenStateSubscription();
|
|
@@ -100,25 +103,25 @@ export class ScreenSingleValueProvider implements SingleValueProvider {
|
|
|
100
103
|
(state) => ({
|
|
101
104
|
value: state.data[this.key],
|
|
102
105
|
exists: this.key in state.data,
|
|
103
|
-
})
|
|
104
|
-
(current, previous) => {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
106
|
+
})
|
|
107
|
+
// (current, previous) => {
|
|
108
|
+
// if (!current.exists && previous.exists) {
|
|
109
|
+
// log_debug(
|
|
110
|
+
// `ScreenSingleValueProvider: Key deleted from store: ${this.key}`
|
|
111
|
+
// );
|
|
112
|
+
|
|
113
|
+
// // TODO: If we need to handle deletion, we can do it here
|
|
114
|
+
// }
|
|
115
|
+
|
|
116
|
+
// if (current.value !== previous.value) {
|
|
117
|
+
// this.valueSubject.next(current.value || null);
|
|
118
|
+
|
|
119
|
+
// log_debug(`ScreenSingleValueProvider: Key updated: ${this.key}`, {
|
|
120
|
+
// previous: previous.value,
|
|
121
|
+
// current: current.value,
|
|
122
|
+
// });
|
|
123
|
+
// }
|
|
124
|
+
// }
|
|
122
125
|
);
|
|
123
126
|
|
|
124
127
|
log_debug(
|
|
@@ -2,6 +2,7 @@ import { MultiSelectProvider } from "./StorageMultiSelectProvider";
|
|
|
2
2
|
import { BehaviorSubject } from "rxjs";
|
|
3
3
|
import { createLogger } from "../logger";
|
|
4
4
|
import { bridgeLogger } from "../../zapp-react-native-bridge/logger";
|
|
5
|
+
import { useScreenStateStore } from "../reactHooks/navigation/useScreenStateStore";
|
|
5
6
|
|
|
6
7
|
export const { log_debug, log_error } = createLogger({
|
|
7
8
|
category: "ScreenMultiSelectProvider",
|
|
@@ -22,7 +23,7 @@ export class ScreenMultiSelectProvider implements MultiSelectProvider {
|
|
|
22
23
|
public static getProvider(
|
|
23
24
|
key: string,
|
|
24
25
|
screenRoute: string,
|
|
25
|
-
screenStateStore:
|
|
26
|
+
screenStateStore: ReturnType<typeof useScreenStateStore>
|
|
26
27
|
): MultiSelectProvider {
|
|
27
28
|
if (!key) {
|
|
28
29
|
throw new Error("ScreenMultiSelectProvider: Key is required");
|
|
@@ -66,7 +67,7 @@ export class ScreenMultiSelectProvider implements MultiSelectProvider {
|
|
|
66
67
|
private constructor(
|
|
67
68
|
private key: string,
|
|
68
69
|
route: string,
|
|
69
|
-
private screenStateStore:
|
|
70
|
+
private screenStateStore: ReturnType<typeof useScreenStateStore>
|
|
70
71
|
) {
|
|
71
72
|
if (!key) {
|
|
72
73
|
throw new Error("ScreenMultiSelectProvider: Key is required");
|
|
@@ -88,7 +89,9 @@ export class ScreenMultiSelectProvider implements MultiSelectProvider {
|
|
|
88
89
|
log_debug("ScreenMultiSelectProvider: Initializing", { key, route });
|
|
89
90
|
}
|
|
90
91
|
|
|
91
|
-
private updateStore(
|
|
92
|
+
private updateStore(
|
|
93
|
+
screenStateStore: ReturnType<typeof useScreenStateStore>
|
|
94
|
+
): void {
|
|
92
95
|
if (screenStateStore === this.screenStateStore) {
|
|
93
96
|
return;
|
|
94
97
|
}
|
|
@@ -104,26 +107,26 @@ export class ScreenMultiSelectProvider implements MultiSelectProvider {
|
|
|
104
107
|
(state) => ({
|
|
105
108
|
value: state.data[this.key],
|
|
106
109
|
exists: this.key in state.data,
|
|
107
|
-
})
|
|
108
|
-
(current, previous) => {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
110
|
+
})
|
|
111
|
+
// (current, previous) => {
|
|
112
|
+
// if (!current.exists && previous.exists) {
|
|
113
|
+
// log_debug(
|
|
114
|
+
// `ScreenMultiSelectProvider: Key deleted from store: ${this.key}`
|
|
115
|
+
// );
|
|
116
|
+
|
|
117
|
+
// // TODO: If we need to handle deletion, we can do it here
|
|
118
|
+
// }
|
|
119
|
+
|
|
120
|
+
// if (current.value !== previous.value) {
|
|
121
|
+
// const items = this.parseStoredValue(current.value);
|
|
122
|
+
// this.itemSubject.next(items);
|
|
123
|
+
|
|
124
|
+
// log_debug(`ScreenMultiSelectProvider: Key updated: ${this.key}`, {
|
|
125
|
+
// previous: this.parseStoredValue(previous.value),
|
|
126
|
+
// current: items,
|
|
127
|
+
// });
|
|
128
|
+
// }
|
|
129
|
+
// }
|
|
127
130
|
);
|
|
128
131
|
|
|
129
132
|
log_debug(
|
package/testUtils/index.tsx
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { SafeAreaProvider } from "react-native-safe-area-context";
|
|
2
|
+
import { render } from "@testing-library/react-native";
|
|
3
3
|
import React, { PropsWithChildren } from "react";
|
|
4
|
-
import
|
|
5
|
-
|
|
4
|
+
import configureStore from "redux-mock-store";
|
|
6
5
|
import { Provider } from "react-redux";
|
|
6
|
+
import { View } from "react-native";
|
|
7
7
|
import thunk from "redux-thunk";
|
|
8
|
-
import
|
|
9
|
-
|
|
8
|
+
import * as R from "ramda";
|
|
9
|
+
|
|
10
10
|
import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
|
|
11
11
|
|
|
12
|
-
import { render } from "@testing-library/react-native";
|
|
13
|
-
import { AnalyticsProvider } from "../analyticsUtils";
|
|
14
12
|
import { ThemeContext } from "../theme";
|
|
13
|
+
import { AnalyticsProvider } from "../analyticsUtils";
|
|
15
14
|
|
|
16
15
|
export { getByTestId } from "./getByTestId";
|
|
17
16
|
|
package/time/BackgroundTimer.ts
CHANGED
|
@@ -11,7 +11,7 @@ class BackgroundTimer {
|
|
|
11
11
|
this.uniqueId = 0;
|
|
12
12
|
this.callbacks = {};
|
|
13
13
|
|
|
14
|
-
const EventEmitter = platformSelect({
|
|
14
|
+
const EventEmitter: typeof DeviceEventEmitter | undefined = platformSelect({
|
|
15
15
|
android: DeviceEventEmitter,
|
|
16
16
|
android_tv: DeviceEventEmitter,
|
|
17
17
|
amazon: DeviceEventEmitter, // probably does not exist and uses android_tv
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { endsWith } from "../endsWith";
|
|
2
|
+
|
|
3
|
+
describe("endsWith", () => {
|
|
4
|
+
it("returns false when str is null", () => {
|
|
5
|
+
expect(endsWith("a", null)).toBe(false);
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it("returns false when str is undefined", () => {
|
|
9
|
+
expect(endsWith("a", undefined)).toBe(false);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("returns true when string ends with target", () => {
|
|
13
|
+
expect(endsWith("lo", "hello")).toBe(true);
|
|
14
|
+
expect(endsWith("", "hello")).toBe(true); // empty target always matches
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("returns false when string does not end with target", () => {
|
|
18
|
+
expect(endsWith("yo", "hello")).toBe(false);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("works with single character target", () => {
|
|
22
|
+
expect(endsWith("o", "hello")).toBe(true);
|
|
23
|
+
expect(endsWith("x", "hello")).toBe(false);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("is case-sensitive", () => {
|
|
27
|
+
expect(endsWith("Lo", "hello")).toBe(false);
|
|
28
|
+
expect(endsWith("lo", "hello")).toBe(true);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { find } from "../find";
|
|
2
|
+
|
|
3
|
+
test("example 1", () => {
|
|
4
|
+
const predicate = <T>(_: T, index: number): boolean => index === 0;
|
|
5
|
+
const xs = ["1", "2", "2", "3", "4"];
|
|
6
|
+
|
|
7
|
+
expect(find(predicate, xs)).toBe("1");
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
test("example 2", () => {
|
|
11
|
+
const predicate = <T>(_: T, index: number): boolean => index === 0;
|
|
12
|
+
const xs: string[] = [];
|
|
13
|
+
|
|
14
|
+
expect(find(predicate, xs)).toBe(undefined);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test("example 3", () => {
|
|
18
|
+
const predicate = () => false;
|
|
19
|
+
const xs = ["1", "2", "2", "3"];
|
|
20
|
+
|
|
21
|
+
expect(find(predicate, xs)).toBe(undefined);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("example 4", () => {
|
|
25
|
+
const predicate = <T>(_: T, index: number): boolean => index === 1;
|
|
26
|
+
const xs = ["1", "2", "2", "3"];
|
|
27
|
+
|
|
28
|
+
expect(find(predicate, xs)).toBe("2");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("example 5", () => {
|
|
32
|
+
const predicate = <T>(_: T, index: number): boolean => index === 2;
|
|
33
|
+
const xs = ["1", "2.1", "2", "3", "2", "4"];
|
|
34
|
+
|
|
35
|
+
expect(find(predicate, xs)).toBe("2");
|
|
36
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { mapAccum } from "../mapAccum";
|
|
2
|
+
|
|
3
|
+
describe("mapAccum", () => {
|
|
4
|
+
it("using standard ramda test", () => {
|
|
5
|
+
const digits = ["1", "2", "3", "4"];
|
|
6
|
+
const appender = (a, b) => [a + b, a + b];
|
|
7
|
+
|
|
8
|
+
const [acc, result] = mapAccum(appender, 0, digits); //= > ['01234', ['01', '012', '0123', '01234']]
|
|
9
|
+
expect(acc).toBe("01234");
|
|
10
|
+
expect(result).toEqual(["01", "012", "0123", "01234"]);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("maps and accumulates over an array", () => {
|
|
14
|
+
const fn = (acc, x) => [acc + x, x * 2];
|
|
15
|
+
const [acc, result] = mapAccum(fn, 0, [1, 2, 3]);
|
|
16
|
+
|
|
17
|
+
expect(acc).toBe(6); // final accumulator (0 + 1 + 2 + 3)
|
|
18
|
+
expect(result).toEqual([2, 4, 6]); // mapped values (acc + x*2 at each step)
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("returns initial accumulator for empty array", () => {
|
|
22
|
+
const fn = (acc, x) => [acc + x, acc * x];
|
|
23
|
+
const [acc, result] = mapAccum(fn, 10, []);
|
|
24
|
+
|
|
25
|
+
expect(acc).toBe(10);
|
|
26
|
+
expect(result).toEqual([]);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("accumulates strings correctly", () => {
|
|
30
|
+
const fn = (acc, x) => [acc + x, acc + x];
|
|
31
|
+
const [acc, result] = mapAccum(fn, "A", ["B", "C", "D"]);
|
|
32
|
+
|
|
33
|
+
expect(acc).toBe("ABCD");
|
|
34
|
+
expect(result).toEqual(["AB", "ABC", "ABCD"]);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("works with objects as accumulator", () => {
|
|
38
|
+
const fn = (acc, x) => {
|
|
39
|
+
const newAcc = { sum: acc.sum + x };
|
|
40
|
+
|
|
41
|
+
return [newAcc, newAcc.sum];
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const [acc, result] = mapAccum(fn, { sum: 0 }, [1, 2, 3]);
|
|
45
|
+
|
|
46
|
+
expect(acc).toEqual({ sum: 6 });
|
|
47
|
+
expect(result).toEqual([1, 3, 6]);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("is curried", () => {
|
|
51
|
+
const fn = (acc, x) => [acc + x, x * 2];
|
|
52
|
+
const mapWithFn = mapAccum(fn);
|
|
53
|
+
const withInit = mapWithFn(2);
|
|
54
|
+
const [acc, result] = withInit([1, 2, 3]);
|
|
55
|
+
|
|
56
|
+
expect(acc).toBe(8);
|
|
57
|
+
expect(result).toEqual([2, 4, 6]);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("does not mutate the original array", () => {
|
|
61
|
+
const arr = [1, 2, 3];
|
|
62
|
+
mapAccum((acc, x) => [acc + x, acc + x], 0, arr);
|
|
63
|
+
expect(arr).toEqual([1, 2, 3]);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("handles mixed types in accumulator and result", () => {
|
|
67
|
+
const fn = (acc, x) => [acc + x.length, acc + "-" + x];
|
|
68
|
+
const [acc, result] = mapAccum(fn, 0, ["a", "bb", "ccc"]);
|
|
69
|
+
|
|
70
|
+
expect(acc).toBe(6);
|
|
71
|
+
expect(result).toEqual(["0-a", "1-bb", "3-ccc"]);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { omit } from "../omit";
|
|
2
|
+
|
|
3
|
+
test("example 1", () => {
|
|
4
|
+
const path = ["a", "b", "c"];
|
|
5
|
+
const record = { a: 1, b: 2, c: 3 };
|
|
6
|
+
|
|
7
|
+
const output = {};
|
|
8
|
+
|
|
9
|
+
expect(omit(path, record)).toEqual(output);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test("example 2", () => {
|
|
13
|
+
const path = ["a", "b"];
|
|
14
|
+
const record = { a: 1, b: 2, c: 3 };
|
|
15
|
+
|
|
16
|
+
const output = { c: 3 };
|
|
17
|
+
|
|
18
|
+
expect(omit(path, record)).toEqual(output);
|
|
19
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { path } from "../path";
|
|
2
|
+
|
|
3
|
+
test("example 1", () => {
|
|
4
|
+
const route = ["a", "b", "c"];
|
|
5
|
+
const xs = { a: { b: { c: 1 } } };
|
|
6
|
+
|
|
7
|
+
const output = 1;
|
|
8
|
+
|
|
9
|
+
expect(path(route, xs)).toEqual(output);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test("example 2", () => {
|
|
13
|
+
const route = ["a", "b"];
|
|
14
|
+
const xs = { a: { b: { c: 1 } } };
|
|
15
|
+
|
|
16
|
+
const output = { c: 1 };
|
|
17
|
+
|
|
18
|
+
expect(path(route, xs)).toEqual(output);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test("example 3", () => {
|
|
22
|
+
const route = ["a", "b", "x"];
|
|
23
|
+
const xs = { a: { b: { c: 1 } } };
|
|
24
|
+
|
|
25
|
+
expect(path(route, xs)).toBeUndefined();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("example 4", () => {
|
|
29
|
+
const route = ["a", "b", "c"];
|
|
30
|
+
const xs = undefined;
|
|
31
|
+
|
|
32
|
+
expect(path(route, xs)).toBeUndefined();
|
|
33
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { pathOr } from "../pathOr";
|
|
2
|
+
|
|
3
|
+
test("example 1", () => {
|
|
4
|
+
const defaultValue = "defaultValue";
|
|
5
|
+
const path = ["a", "b", "c"];
|
|
6
|
+
const xs = { a: { b: { c: 1 } } };
|
|
7
|
+
|
|
8
|
+
const output = 1;
|
|
9
|
+
|
|
10
|
+
expect(pathOr(defaultValue, path, xs)).toEqual(output);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test("example 2", () => {
|
|
14
|
+
const defaultValue = "defaultValue";
|
|
15
|
+
const path = ["a", "b"];
|
|
16
|
+
const xs = { a: { b: { c: 1 } } };
|
|
17
|
+
|
|
18
|
+
const output = { c: 1 };
|
|
19
|
+
|
|
20
|
+
expect(pathOr(defaultValue, path, xs)).toEqual(output);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("example 3", () => {
|
|
24
|
+
const defaultValue = "defaultValue";
|
|
25
|
+
const path = ["a", "b", "x"];
|
|
26
|
+
const xs = { a: { b: { c: 1 } } };
|
|
27
|
+
|
|
28
|
+
expect(pathOr(defaultValue, path, xs)).toBe(defaultValue);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("example 4", () => {
|
|
32
|
+
const defaultValue = "defaultValue";
|
|
33
|
+
const path = ["a", "b", "c"];
|
|
34
|
+
const xs = undefined;
|
|
35
|
+
|
|
36
|
+
expect(pathOr(defaultValue, path, xs)).toBe(defaultValue);
|
|
37
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { startsWith } from "../startsWith";
|
|
2
|
+
|
|
3
|
+
describe("startsWith", () => {
|
|
4
|
+
it("returns false when str is null", () => {
|
|
5
|
+
expect(startsWith("a", null)).toBe(false);
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it("returns false when str is undefined", () => {
|
|
9
|
+
expect(startsWith("a", undefined)).toBe(false);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("returns true when string starts with target", () => {
|
|
13
|
+
expect(startsWith("he", "hello")).toBe(true);
|
|
14
|
+
expect(startsWith("", "hello")).toBe(true); // empty target always matches
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("returns false when string does not start with target", () => {
|
|
18
|
+
expect(startsWith("yo", "hello")).toBe(false);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("works with single character target", () => {
|
|
22
|
+
expect(startsWith("h", "hello")).toBe(true);
|
|
23
|
+
expect(startsWith("x", "hello")).toBe(false);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("is case-sensitive", () => {
|
|
27
|
+
expect(startsWith("He", "hello")).toBe(false);
|
|
28
|
+
expect(startsWith("he", "hello")).toBe(true);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { take } from "../take";
|
|
2
|
+
|
|
3
|
+
describe("take", () => {
|
|
4
|
+
it("takes n elements from the beginning", () => {
|
|
5
|
+
expect(take(2, [1, 2, 3])).toEqual([1, 2]);
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it("returns the whole array if n is larger than length", () => {
|
|
9
|
+
expect(take(5, [1, 2, 3])).toEqual([1, 2, 3]);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("returns empty array if n is 0", () => {
|
|
13
|
+
expect(take(0, [1, 2, 3])).toEqual([]);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("returns empty array for empty input array", () => {
|
|
17
|
+
expect(take(2, [])).toEqual([]);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("returns empty array if n is negative", () => {
|
|
21
|
+
expect(take(-1, [1, 2, 3])).toEqual([]);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("works with strings in array", () => {
|
|
25
|
+
expect(take(2, ["a", "b", "c"])).toEqual(["a", "b"]);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("works with objects in array", () => {
|
|
29
|
+
const arr = [{ id: 1 }, { id: 2 }];
|
|
30
|
+
expect(take(1, arr)).toEqual([{ id: 1 }]);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("returns empty array if input is not an array", () => {
|
|
34
|
+
// @ts-expect-error testing non-array input
|
|
35
|
+
expect(take(2, null)).toEqual([]);
|
|
36
|
+
|
|
37
|
+
// @ts-expect-error testing non-array input
|
|
38
|
+
expect(take(2, undefined)).toEqual([]);
|
|
39
|
+
});
|
|
40
|
+
});
|
package/utils/find.ts
ADDED
package/utils/index.ts
CHANGED
|
@@ -2,6 +2,22 @@ export { chunk } from "./chunk";
|
|
|
2
2
|
|
|
3
3
|
export { times } from "./times";
|
|
4
4
|
|
|
5
|
+
export { startsWith } from "./startsWith";
|
|
6
|
+
|
|
7
|
+
export { find } from "./find";
|
|
8
|
+
|
|
9
|
+
export { pathOr } from "./pathOr";
|
|
10
|
+
|
|
11
|
+
export { path } from "./path";
|
|
12
|
+
|
|
13
|
+
export { omit } from "./omit";
|
|
14
|
+
|
|
15
|
+
export { endsWith } from "./endsWith";
|
|
16
|
+
|
|
17
|
+
export { take } from "./take";
|
|
18
|
+
|
|
19
|
+
export { mapAccum } from "./mapAccum";
|
|
20
|
+
|
|
5
21
|
export {
|
|
6
22
|
cloneDeep as clone,
|
|
7
23
|
flatten,
|
|
@@ -13,8 +29,14 @@ export {
|
|
|
13
29
|
has,
|
|
14
30
|
flatMap,
|
|
15
31
|
difference,
|
|
16
|
-
|
|
32
|
+
pick,
|
|
17
33
|
map,
|
|
18
34
|
trim,
|
|
19
35
|
toString,
|
|
36
|
+
last,
|
|
37
|
+
toLower,
|
|
38
|
+
isEqual as equals,
|
|
39
|
+
flowRight as compose,
|
|
40
|
+
partial,
|
|
41
|
+
reverse,
|
|
20
42
|
} from "lodash";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { curry } from "lodash";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A native reimplementation of Ramda's mapAccum.
|
|
5
|
+
*
|
|
6
|
+
* @template A, B, C
|
|
7
|
+
* @param {(acc: A, value: B) => [A, C]} fn - Function returning [newAcc, mappedValue]
|
|
8
|
+
* @param {A} acc - Initial accumulator
|
|
9
|
+
* @param {B[]} list - List to process
|
|
10
|
+
* @returns {[A, C[]]} - Tuple of [final accumulator, mapped array]
|
|
11
|
+
*/
|
|
12
|
+
export const mapAccum = curry((fn, acc, list) => {
|
|
13
|
+
const result = [];
|
|
14
|
+
let currentAcc = acc;
|
|
15
|
+
|
|
16
|
+
for (let i = 0; i < list.length; i++) {
|
|
17
|
+
const [nextAcc, mapped] = fn(currentAcc, list[i]);
|
|
18
|
+
currentAcc = nextAcc;
|
|
19
|
+
result.push(mapped);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return [currentAcc, result];
|
|
23
|
+
});
|
package/utils/omit.ts
ADDED
package/utils/path.ts
ADDED
package/utils/pathOr.ts
ADDED