@applicaster/zapp-react-native-utils 15.0.0-rc.14 → 15.0.0-rc.140

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.
Files changed (177) hide show
  1. package/README.md +0 -6
  2. package/actionsExecutor/ActionExecutorContext.tsx +86 -12
  3. package/actionsExecutor/feedDecorator.ts +6 -6
  4. package/adsUtils/__tests__/createVMAP.test.ts +419 -0
  5. package/adsUtils/index.ts +2 -2
  6. package/analyticsUtils/README.md +1 -1
  7. package/analyticsUtils/analyticsMapper.ts +10 -2
  8. package/appDataUtils/__tests__/urlScheme.test.ts +678 -0
  9. package/appUtils/HooksManager/__tests__/__snapshots__/hooksManager.test.js.snap +0 -188
  10. package/appUtils/HooksManager/__tests__/hooksManager.test.js +16 -2
  11. package/appUtils/HooksManager/index.ts +45 -10
  12. package/appUtils/RiverFocusManager/{index.js → index.ts} +25 -18
  13. package/appUtils/accessibilityManager/__tests__/utils.test.ts +360 -0
  14. package/appUtils/accessibilityManager/const.ts +4 -0
  15. package/appUtils/accessibilityManager/hooks.ts +20 -13
  16. package/appUtils/accessibilityManager/index.ts +28 -1
  17. package/appUtils/accessibilityManager/utils.ts +59 -8
  18. package/appUtils/contextKeysManager/__tests__/getKeys/failure.test.ts +7 -2
  19. package/appUtils/contextKeysManager/__tests__/getKeys/success.test.ts +48 -0
  20. package/appUtils/contextKeysManager/contextResolver.ts +51 -22
  21. package/appUtils/contextKeysManager/index.ts +65 -10
  22. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +3 -0
  23. package/appUtils/focusManager/index.ios.ts +43 -4
  24. package/appUtils/focusManager/treeDataStructure/Tree/__tests__/Tree.test.js +46 -0
  25. package/appUtils/focusManager/treeDataStructure/Tree/index.js +18 -18
  26. package/appUtils/focusManagerAux/utils/index.ios.ts +122 -0
  27. package/appUtils/focusManagerAux/utils/index.ts +13 -7
  28. package/appUtils/focusManagerAux/utils/utils.ios.ts +202 -3
  29. package/appUtils/keyCodes/keys/keys.web.ts +1 -4
  30. package/appUtils/localizationsHelper.ts +4 -0
  31. package/appUtils/orientationHelper.ts +2 -4
  32. package/appUtils/platform/platformUtils.ts +117 -18
  33. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +94 -4
  34. package/appUtils/playerManager/OverlayObserver/utils.ts +32 -20
  35. package/appUtils/playerManager/index.ts +9 -0
  36. package/appUtils/playerManager/player.ts +5 -1
  37. package/appUtils/playerManager/playerNative.ts +31 -17
  38. package/appUtils/playerManager/usePlayer.tsx +5 -3
  39. package/appUtils/playerManager/usePlayerState.tsx +14 -2
  40. package/arrayUtils/__tests__/allTruthy.test.ts +24 -0
  41. package/arrayUtils/__tests__/anyThruthy.test.ts +24 -0
  42. package/arrayUtils/index.ts +5 -0
  43. package/cellUtils/__tests__/cellUtils.test.ts +39 -0
  44. package/cellUtils/index.ts +43 -1
  45. package/cloudEventsUtils/__tests__/index.test.ts +529 -0
  46. package/cloudEventsUtils/index.ts +65 -1
  47. package/componentsUtils/index.ts +8 -0
  48. package/configurationUtils/__tests__/imageSrcFromMediaItem.test.ts +38 -0
  49. package/configurationUtils/__tests__/manifestKeyParser.test.ts +26 -26
  50. package/configurationUtils/index.ts +17 -11
  51. package/dateUtils/__tests__/dayjs.test.ts +327 -0
  52. package/dateUtils/index.ts +2 -0
  53. package/enumUtils/__tests__/getEnumKeyByEnumValue.test.ts +207 -0
  54. package/errorUtils/__tests__/GeneralError.test.ts +97 -0
  55. package/errorUtils/__tests__/HttpStatusCode.test.ts +344 -0
  56. package/errorUtils/__tests__/MissingPluginError.test.ts +113 -0
  57. package/errorUtils/__tests__/NetworkError.test.ts +202 -0
  58. package/errorUtils/__tests__/getParsedResponse.test.ts +188 -0
  59. package/errorUtils/__tests__/invariant.test.ts +112 -0
  60. package/focusManager/aux/index.ts +1 -1
  61. package/headersUtils/__tests__/headersUtils.test.js +11 -1
  62. package/headersUtils/index.ts +2 -1
  63. package/manifestUtils/_internals/__tests__/index.test.js +41 -0
  64. package/manifestUtils/_internals/index.js +33 -0
  65. package/manifestUtils/defaultManifestConfigurations/player.js +115 -11
  66. package/manifestUtils/fieldUtils/__tests__/fieldUtils.test.js +49 -0
  67. package/manifestUtils/fieldUtils/index.js +54 -0
  68. package/manifestUtils/index.js +2 -0
  69. package/manifestUtils/keys.js +249 -0
  70. package/manifestUtils/mobileAction/button/__tests__/mobileActionButton.test.js +168 -0
  71. package/manifestUtils/mobileAction/button/index.js +140 -0
  72. package/manifestUtils/mobileAction/container/__tests__/mobileActionButtonsContainer.test.js +102 -0
  73. package/manifestUtils/mobileAction/container/index.js +73 -0
  74. package/manifestUtils/mobileAction/groups/__tests__/buildMobileActionButtonGroups.test.js +127 -0
  75. package/manifestUtils/mobileAction/groups/defaults.js +76 -0
  76. package/manifestUtils/mobileAction/groups/index.js +80 -0
  77. package/manifestUtils/platformIsTV.js +13 -0
  78. package/manifestUtils/sharedConfiguration/screenPicker/utils.js +1 -0
  79. package/manifestUtils/tvAction/container/index.js +1 -1
  80. package/navigationUtils/index.ts +15 -5
  81. package/numberUtils/__tests__/toNumber.test.ts +27 -0
  82. package/numberUtils/__tests__/toPositiveNumber.test.ts +193 -0
  83. package/numberUtils/index.ts +23 -1
  84. package/package.json +4 -4
  85. package/playerUtils/usePlayerTTS.ts +8 -3
  86. package/pluginUtils/index.ts +4 -0
  87. package/reactHooks/advertising/index.ts +2 -2
  88. package/reactHooks/analytics/__tests__/useSendAnalyticsOnPress.test.ts +537 -0
  89. package/reactHooks/app/__tests__/useAppState.test.ts +1 -1
  90. package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +1 -1
  91. package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +1 -2
  92. package/reactHooks/cell-click/__tests__/index.test.js +1 -3
  93. package/reactHooks/cell-click/index.ts +2 -1
  94. package/reactHooks/configuration/__tests__/index.test.tsx +1 -1
  95. package/reactHooks/connection/__tests__/index.test.js +1 -1
  96. package/reactHooks/debugging/__tests__/index.test.js +4 -4
  97. package/reactHooks/dev/__tests__/useReRenderLog.test.ts +188 -0
  98. package/reactHooks/device/useIsTablet.tsx +14 -19
  99. package/reactHooks/device/useMemoizedIsTablet.ts +3 -3
  100. package/reactHooks/events/index.ts +20 -0
  101. package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +32 -23
  102. package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +19 -19
  103. package/reactHooks/feed/__tests__/useEntryScreenId.test.tsx +4 -1
  104. package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +42 -30
  105. package/reactHooks/feed/__tests__/{useInflatedUrl.test.ts → useInflatedUrl.test.tsx} +62 -7
  106. package/reactHooks/feed/index.ts +0 -2
  107. package/reactHooks/feed/useBatchLoading.ts +7 -1
  108. package/reactHooks/feed/useEntryScreenId.ts +2 -2
  109. package/reactHooks/feed/useInflatedUrl.ts +44 -18
  110. package/reactHooks/feed/usePipesCacheReset.ts +3 -1
  111. package/reactHooks/flatList/useLoadNextPageIfNeeded.ts +13 -16
  112. package/reactHooks/hookModal/hooks/useHookModalScreenData.ts +12 -8
  113. package/reactHooks/index.ts +2 -0
  114. package/reactHooks/layout/__tests__/index.test.tsx +1 -1
  115. package/reactHooks/layout/__tests__/useLayoutVersion.test.tsx +1 -1
  116. package/reactHooks/layout/index.ts +1 -1
  117. package/reactHooks/layout/useDimensions/__tests__/{useDimensions.test.ts → useDimensions.test.tsx} +105 -25
  118. package/reactHooks/layout/useDimensions/useDimensions.ts +2 -2
  119. package/reactHooks/navigation/__tests__/index.test.tsx +40 -9
  120. package/reactHooks/navigation/index.ts +27 -11
  121. package/reactHooks/navigation/useRoute.ts +11 -7
  122. package/reactHooks/player/TVSeekControlller/TVSeekController.ts +27 -10
  123. package/reactHooks/player/__tests__/useAutoSeek._test.tsx +1 -1
  124. package/reactHooks/player/__tests__/useTapSeek._test.ts +1 -1
  125. package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +1 -1
  126. package/reactHooks/resolvers/__tests__/useComponentResolver.test.tsx +1 -1
  127. package/reactHooks/resolvers/useCellResolver.ts +6 -2
  128. package/reactHooks/resolvers/useComponentResolver.ts +19 -3
  129. package/reactHooks/screen/__tests__/useCurrentScreenData.test.tsx +2 -2
  130. package/reactHooks/screen/__tests__/useScreenBackgroundColor.test.tsx +1 -1
  131. package/reactHooks/screen/__tests__/useScreenData.test.tsx +1 -1
  132. package/reactHooks/screen/__tests__/useTargetScreenData.test.tsx +12 -4
  133. package/reactHooks/screen/useTargetScreenData.ts +4 -2
  134. package/reactHooks/state/__tests__/useComponentScreenState.test.ts +246 -0
  135. package/reactHooks/state/index.ts +2 -0
  136. package/reactHooks/state/useComponentScreenState.ts +45 -0
  137. package/reactHooks/state/useRefWithInitialValue.ts +10 -0
  138. package/reactHooks/state/useRivers.ts +1 -1
  139. package/reactHooks/ui/__tests__/useFadeOutWhenBlurred.test.ts +580 -0
  140. package/reactHooks/usePluginConfiguration.ts +2 -2
  141. package/reactHooks/utils/__tests__/index.test.js +1 -1
  142. package/rectUtils/__tests__/index.test.ts +549 -0
  143. package/rectUtils/index.ts +2 -2
  144. package/refreshUtils/RefreshCoordinator/__tests__/refreshCoordinator.test.ts +206 -0
  145. package/refreshUtils/RefreshCoordinator/index.ts +245 -0
  146. package/refreshUtils/RefreshCoordinator/utils/__tests__/getDataRefreshConfig.test.ts +104 -0
  147. package/refreshUtils/RefreshCoordinator/utils/index.ts +29 -0
  148. package/screenPickerUtils/__tests__/index.test.ts +333 -0
  149. package/screenPickerUtils/index.ts +5 -0
  150. package/screenState/__tests__/index.test.ts +1 -1
  151. package/screenUtils/index.ts +3 -0
  152. package/searchUtils/const.ts +7 -0
  153. package/searchUtils/index.ts +3 -0
  154. package/services/storageServiceSync.web.ts +1 -1
  155. package/stringUtils/index.ts +1 -1
  156. package/testUtils/index.tsx +30 -21
  157. package/time/__tests__/BackgroundTimer.test.ts +156 -0
  158. package/time/__tests__/Timer.test.ts +236 -0
  159. package/typeGuards/__tests__/isString.test.ts +21 -0
  160. package/typeGuards/index.ts +4 -0
  161. package/utils/__tests__/clone.test.ts +158 -0
  162. package/utils/__tests__/mapAccum.test.ts +73 -0
  163. package/utils/__tests__/mergeRight.test.ts +48 -0
  164. package/utils/__tests__/path.test.ts +7 -0
  165. package/utils/__tests__/selectors.test.ts +124 -0
  166. package/utils/clone.ts +7 -0
  167. package/utils/index.ts +21 -1
  168. package/utils/mapAccum.ts +23 -0
  169. package/utils/mergeRight.ts +5 -0
  170. package/utils/path.ts +6 -3
  171. package/utils/pathOr.ts +5 -1
  172. package/utils/selectors.ts +46 -0
  173. package/zappFrameworkUtils/HookCallback/callbackNavigationAction.ts +49 -12
  174. package/zappFrameworkUtils/HookCallback/hookCallbackManifestExtensions.config.js +1 -1
  175. package/reactHooks/componentsMap/index.ts +0 -55
  176. package/reactHooks/feed/__tests__/useFeedRefresh.test.tsx +0 -75
  177. package/reactHooks/feed/useFeedRefresh.tsx +0 -65
@@ -0,0 +1,236 @@
1
+ import { Timer } from "../Timer";
2
+ import BackgroundTimer from "../BackgroundTimer";
3
+
4
+ // Mock BackgroundTimer
5
+ jest.mock("../BackgroundTimer", () => ({
6
+ __esModule: true,
7
+ default: {
8
+ setTimeout: jest.fn((callback, delay) => {
9
+ return setTimeout(callback, delay);
10
+ }),
11
+ clearTimeout: jest.fn((id) => {
12
+ clearTimeout(id as NodeJS.Timeout);
13
+ }),
14
+ },
15
+ }));
16
+
17
+ describe("Timer", () => {
18
+ let mockCallback: jest.Mock;
19
+
20
+ beforeEach(() => {
21
+ jest.clearAllMocks();
22
+ jest.useFakeTimers();
23
+ mockCallback = jest.fn();
24
+ });
25
+
26
+ afterEach(() => {
27
+ jest.useRealTimers();
28
+ });
29
+
30
+ describe("constructor", () => {
31
+ it("should create timer with callback and remaining time", () => {
32
+ const timer = new Timer(mockCallback, 1000);
33
+
34
+ expect(timer).toBeInstanceOf(Timer);
35
+ });
36
+
37
+ it("should create timer with callback only (optional remaining param)", () => {
38
+ const timer = new Timer(mockCallback);
39
+
40
+ expect(timer).toBeInstanceOf(Timer);
41
+ });
42
+
43
+ it("should not start automatically", () => {
44
+ // eslint-disable-next-line no-new
45
+ new Timer(mockCallback, 1000);
46
+
47
+ expect(BackgroundTimer.setTimeout).not.toHaveBeenCalled();
48
+ });
49
+ });
50
+
51
+ describe("start", () => {
52
+ it("should call setTimeout with callback and remaining time", () => {
53
+ const timer = new Timer(mockCallback, 1000);
54
+
55
+ timer.start();
56
+
57
+ expect(BackgroundTimer.setTimeout).toHaveBeenCalledWith(
58
+ mockCallback,
59
+ 1000
60
+ );
61
+ });
62
+
63
+ it("should reset remaining time to 0 after starting", () => {
64
+ const timer = new Timer(mockCallback, 5000);
65
+
66
+ timer.start();
67
+ timer.clear();
68
+ timer.start();
69
+
70
+ expect(BackgroundTimer.setTimeout).toHaveBeenCalledTimes(2);
71
+ });
72
+ });
73
+
74
+ describe("pause", () => {
75
+ it("should clear timeout and calculate remaining time correctly", () => {
76
+ const startTime = 1000;
77
+ const pauseTime = 1500;
78
+
79
+ jest
80
+ .spyOn(Date, "now")
81
+ .mockReturnValueOnce(startTime) // start
82
+ .mockReturnValueOnce(pauseTime); // pause
83
+
84
+ const timer = new Timer(mockCallback, 2000);
85
+
86
+ timer.start();
87
+ timer.pause();
88
+
89
+ expect(BackgroundTimer.clearTimeout).toHaveBeenCalled();
90
+ });
91
+
92
+ it("should be safe to call pause multiple times", () => {
93
+ const timer = new Timer(mockCallback, 1000);
94
+
95
+ timer.start();
96
+ timer.pause();
97
+ timer.pause();
98
+
99
+ expect(BackgroundTimer.clearTimeout).toHaveBeenCalledTimes(2);
100
+ });
101
+ });
102
+
103
+ describe("resume", () => {
104
+ it("should restart timer with remaining time after pause", () => {
105
+ const startTime = 1000;
106
+ const pauseTime = 1500;
107
+
108
+ jest
109
+ .spyOn(Date, "now")
110
+ .mockReturnValueOnce(startTime)
111
+ .mockReturnValueOnce(pauseTime);
112
+
113
+ const timer = new Timer(mockCallback, 2000);
114
+
115
+ timer.start();
116
+ timer.pause();
117
+ timer.resume();
118
+
119
+ expect(BackgroundTimer.setTimeout).toHaveBeenCalledTimes(2);
120
+ });
121
+
122
+ it("should be callable without prior pause", () => {
123
+ const timer = new Timer(mockCallback, 1000);
124
+
125
+ timer.resume();
126
+
127
+ expect(BackgroundTimer.setTimeout).toHaveBeenCalled();
128
+ });
129
+ });
130
+
131
+ describe("clear", () => {
132
+ it("should clear timeout and be safe to call without starting timer", () => {
133
+ const timer = new Timer(mockCallback, 1000);
134
+
135
+ expect(() => {
136
+ timer.clear();
137
+ }).not.toThrow();
138
+
139
+ expect(BackgroundTimer.clearTimeout).toHaveBeenCalled();
140
+ });
141
+
142
+ it("should be callable multiple times", () => {
143
+ const timer = new Timer(mockCallback, 1000);
144
+
145
+ timer.start();
146
+ timer.clear();
147
+ timer.clear();
148
+
149
+ expect(BackgroundTimer.clearTimeout).toHaveBeenCalledTimes(2);
150
+ });
151
+ });
152
+
153
+ describe("timer lifecycle", () => {
154
+ it("should support complete lifecycle: start -> pause -> resume -> clear", () => {
155
+ const timer = new Timer(mockCallback, 1000);
156
+
157
+ timer.start();
158
+ expect(BackgroundTimer.setTimeout).toHaveBeenCalledTimes(1);
159
+
160
+ timer.pause();
161
+ expect(BackgroundTimer.clearTimeout).toHaveBeenCalledTimes(1);
162
+
163
+ timer.resume();
164
+ expect(BackgroundTimer.setTimeout).toHaveBeenCalledTimes(2);
165
+
166
+ timer.clear();
167
+ expect(BackgroundTimer.clearTimeout).toHaveBeenCalledTimes(2);
168
+ });
169
+ });
170
+
171
+ describe("edge cases", () => {
172
+ it("should handle zero delay", () => {
173
+ const timer = new Timer(mockCallback, 0);
174
+
175
+ timer.start();
176
+
177
+ expect(BackgroundTimer.setTimeout).toHaveBeenCalledWith(mockCallback, 0);
178
+ });
179
+
180
+ it("should handle very long delays", () => {
181
+ const longDelay = Number.MAX_SAFE_INTEGER;
182
+ const timer = new Timer(mockCallback, longDelay);
183
+
184
+ timer.start();
185
+
186
+ expect(BackgroundTimer.setTimeout).toHaveBeenCalledWith(
187
+ mockCallback,
188
+ longDelay
189
+ );
190
+ });
191
+
192
+ it("should handle negative delays gracefully", () => {
193
+ const timer = new Timer(mockCallback, -1000);
194
+
195
+ expect(() => {
196
+ timer.start();
197
+ }).not.toThrow();
198
+ });
199
+
200
+ it("should maintain callback reference through lifecycle", () => {
201
+ const specificCallback = jest.fn();
202
+ const timer = new Timer(specificCallback, 1000);
203
+
204
+ timer.start();
205
+
206
+ expect(BackgroundTimer.setTimeout).toHaveBeenCalledWith(
207
+ specificCallback,
208
+ 1000
209
+ );
210
+ });
211
+ });
212
+
213
+ describe("callback execution safety", () => {
214
+ it("should not execute callback immediately on start", () => {
215
+ const timer = new Timer(mockCallback, 1000);
216
+
217
+ timer.start();
218
+
219
+ expect(mockCallback).not.toHaveBeenCalled();
220
+ });
221
+
222
+ it("should not execute callback when paused or cleared", () => {
223
+ const timer1 = new Timer(mockCallback, 100);
224
+ const timer2 = new Timer(mockCallback, 100);
225
+
226
+ timer1.start();
227
+ timer1.pause();
228
+ timer2.start();
229
+ timer2.clear();
230
+
231
+ jest.advanceTimersByTime(200);
232
+
233
+ expect(mockCallback).not.toHaveBeenCalled();
234
+ });
235
+ });
236
+ });
@@ -0,0 +1,21 @@
1
+ import { isString } from "../index";
2
+
3
+ describe("isString", () => {
4
+ it("should return true for string primitives", () => {
5
+ expect(isString("hello")).toBe(true);
6
+ expect(isString("")).toBe(true);
7
+ });
8
+
9
+ it("should return true for String object instances", () => {
10
+ // eslint-disable-next-line no-new-wrappers
11
+ expect(isString(new String("test"))).toBe(true);
12
+ });
13
+
14
+ it("should return false for non-string values", () => {
15
+ expect(isString(123)).toBe(false);
16
+ expect(isString(null)).toBe(false);
17
+ expect(isString(undefined)).toBe(false);
18
+ expect(isString({})).toBe(false);
19
+ expect(isString([])).toBe(false);
20
+ });
21
+ });
@@ -1,3 +1,7 @@
1
1
  export const isString = (value: unknown) => {
2
+ if (typeof value === "object" && value instanceof String) {
3
+ return true;
4
+ }
5
+
2
6
  return typeof value === "string";
3
7
  };
@@ -0,0 +1,158 @@
1
+ import { clone } from "../clone";
2
+
3
+ describe("clone", () => {
4
+ const originalStructuredClone = global.structuredClone;
5
+
6
+ afterEach(() => {
7
+ // Restore the original structuredClone after each test
8
+ global.structuredClone = originalStructuredClone;
9
+ });
10
+
11
+ describe("when structuredClone is available", () => {
12
+ beforeEach(() => {
13
+ // Mock structuredClone if it's not available
14
+ if (typeof global.structuredClone === "undefined") {
15
+ global.structuredClone = jest.fn((value) =>
16
+ JSON.parse(JSON.stringify(value))
17
+ );
18
+ }
19
+ });
20
+
21
+ test("clones primitive values", () => {
22
+ expect(clone(42)).toBe(42);
23
+ expect(clone("test")).toBe("test");
24
+ expect(clone(true)).toBe(true);
25
+ expect(clone(null)).toBe(null);
26
+ });
27
+
28
+ test("clones simple objects", () => {
29
+ const original = { a: 1, b: 2 };
30
+ const cloned = clone(original);
31
+
32
+ expect(cloned).toEqual(original);
33
+ expect(cloned).not.toBe(original);
34
+ });
35
+
36
+ test("clones nested objects", () => {
37
+ const original = { a: { b: { c: 1 } } };
38
+ const cloned = clone(original);
39
+
40
+ expect(cloned).toEqual(original);
41
+ expect(cloned).not.toBe(original);
42
+ expect(cloned.a).not.toBe(original.a);
43
+ expect(cloned.a.b).not.toBe(original.a.b);
44
+ });
45
+
46
+ test("clones arrays", () => {
47
+ const original = [1, 2, 3];
48
+ const cloned = clone(original);
49
+
50
+ expect(cloned).toEqual(original);
51
+ expect(cloned).not.toBe(original);
52
+ });
53
+
54
+ test("clones arrays with nested objects", () => {
55
+ const original = [{ a: 1 }, { b: 2 }];
56
+ const cloned = clone(original);
57
+
58
+ expect(cloned).toEqual(original);
59
+ expect(cloned).not.toBe(original);
60
+ expect(cloned[0]).not.toBe(original[0]);
61
+ expect(cloned[1]).not.toBe(original[1]);
62
+ });
63
+
64
+ test("does not mutate the original value", () => {
65
+ const original = { a: 1, b: { c: 2 } };
66
+ const cloned = clone(original);
67
+
68
+ cloned.a = 99;
69
+ cloned.b.c = 99;
70
+
71
+ expect(original.a).toBe(1);
72
+ expect(original.b.c).toBe(2);
73
+ });
74
+ });
75
+
76
+ describe("when structuredClone is not available (fallback to cloneDeep)", () => {
77
+ beforeEach(() => {
78
+ // Delete structuredClone to force fallback to cloneDeep
79
+ delete (global as any).structuredClone;
80
+ });
81
+
82
+ test("clones primitive values using cloneDeep", () => {
83
+ expect(clone(42)).toBe(42);
84
+ expect(clone("test")).toBe("test");
85
+ expect(clone(true)).toBe(true);
86
+ expect(clone(null)).toBe(null);
87
+ });
88
+
89
+ test("clones simple objects using cloneDeep", () => {
90
+ const original = { a: 1, b: 2 };
91
+ const cloned = clone(original);
92
+
93
+ expect(cloned).toEqual(original);
94
+ expect(cloned).not.toBe(original);
95
+ });
96
+
97
+ test("clones nested objects using cloneDeep", () => {
98
+ const original = { a: { b: { c: 1 } } };
99
+ const cloned = clone(original);
100
+
101
+ expect(cloned).toEqual(original);
102
+ expect(cloned).not.toBe(original);
103
+ expect(cloned.a).not.toBe(original.a);
104
+ expect(cloned.a.b).not.toBe(original.a.b);
105
+ });
106
+
107
+ test("clones arrays using cloneDeep", () => {
108
+ const original = [1, 2, 3];
109
+ const cloned = clone(original);
110
+
111
+ expect(cloned).toEqual(original);
112
+ expect(cloned).not.toBe(original);
113
+ });
114
+
115
+ test("clones arrays with nested objects using cloneDeep", () => {
116
+ const original = [{ a: 1 }, { b: 2 }];
117
+ const cloned = clone(original);
118
+
119
+ expect(cloned).toEqual(original);
120
+ expect(cloned).not.toBe(original);
121
+ expect(cloned[0]).not.toBe(original[0]);
122
+ expect(cloned[1]).not.toBe(original[1]);
123
+ });
124
+
125
+ test("does not mutate the original value when using cloneDeep", () => {
126
+ const original = { a: 1, b: { c: 2 } };
127
+ const cloned = clone(original);
128
+
129
+ cloned.a = 99;
130
+ cloned.b.c = 99;
131
+
132
+ expect(original.a).toBe(1);
133
+ expect(original.b.c).toBe(2);
134
+ });
135
+
136
+ test("handles complex objects with multiple levels", () => {
137
+ const original = {
138
+ name: "test",
139
+ data: {
140
+ items: [
141
+ { id: 1, value: "a" },
142
+ { id: 2, value: "b" },
143
+ ],
144
+ meta: { count: 2 },
145
+ },
146
+ };
147
+
148
+ const cloned = clone(original);
149
+
150
+ expect(cloned).toEqual(original);
151
+ expect(cloned).not.toBe(original);
152
+ expect(cloned.data).not.toBe(original.data);
153
+ expect(cloned.data.items).not.toBe(original.data.items);
154
+ expect(cloned.data.items[0]).not.toBe(original.data.items[0]);
155
+ expect(cloned.data.meta).not.toBe(original.data.meta);
156
+ });
157
+ });
158
+ });
@@ -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,48 @@
1
+ import { mergeRight } from "../mergeRight";
2
+
3
+ describe("mergeRight", () => {
4
+ test("merges two objects with no overlapping keys", () => {
5
+ const a = { x: 1, y: 2 };
6
+ const b = { z: 3 };
7
+
8
+ const result = mergeRight(a, b);
9
+
10
+ expect(result).toEqual({ x: 1, y: 2, z: 3 });
11
+ });
12
+
13
+ test("overwrites keys from the second object", () => {
14
+ const a = { x: 1, y: 2 };
15
+ const b = { y: 10, z: 3 };
16
+
17
+ const result = mergeRight(a, b);
18
+
19
+ expect(result).toEqual({ x: 1, y: 10, z: 3 });
20
+ });
21
+
22
+ test("does not mutate the original objects", () => {
23
+ const a = { x: 1 };
24
+ const b = { y: 2 };
25
+
26
+ const result = mergeRight(a, b);
27
+
28
+ expect(result).not.toBe(a);
29
+ expect(result).not.toBe(b);
30
+ expect(a).toEqual({ x: 1 });
31
+ expect(b).toEqual({ y: 2 });
32
+ });
33
+
34
+ test("works with empty objects", () => {
35
+ expect(mergeRight({}, { a: 1 })).toEqual({ a: 1 });
36
+ expect(mergeRight({ a: 1 }, {})).toEqual({ a: 1 });
37
+ expect(mergeRight({}, {})).toEqual({});
38
+ });
39
+
40
+ test("works with nested objects (shallow merge only)", () => {
41
+ const a = { x: { nested: 1 }, y: 2 };
42
+ const b = { x: { nested: 10 }, z: 3 };
43
+
44
+ const result = mergeRight(a, b);
45
+
46
+ expect(result).toEqual({ x: { nested: 10 }, y: 2, z: 3 });
47
+ });
48
+ });
@@ -31,3 +31,10 @@ test("example 4", () => {
31
31
 
32
32
  expect(path(route, xs)).toBeUndefined();
33
33
  });
34
+
35
+ test("example 5", () => {
36
+ const route = ["a", "b", 0];
37
+ const xs = { a: { b: [1, 2, 3] } };
38
+
39
+ expect(path(route, xs)).toBe(1);
40
+ });
@@ -0,0 +1,124 @@
1
+ import {
2
+ createPluginsByPathSelector,
3
+ createPluginsByModuleSelector,
4
+ combinePluginSelectors,
5
+ } from "../selectors";
6
+
7
+ describe("Plugin Selectors", () => {
8
+ const mockPlugins = [
9
+ {
10
+ identifier: "plugin1",
11
+ module: {
12
+ urlScheme: { host: "test" },
13
+ player: { type: "default" },
14
+ },
15
+ customField: true,
16
+ },
17
+ {
18
+ identifier: "plugin2",
19
+ module: {
20
+ urlScheme: { host: "other" },
21
+ },
22
+ },
23
+ {
24
+ identifier: "plugin3",
25
+ module: {
26
+ player: { type: "custom" },
27
+ },
28
+ },
29
+ ];
30
+
31
+ const mockState = {
32
+ plugins: mockPlugins,
33
+ };
34
+
35
+ describe("createPluginsByPathSelector", () => {
36
+ it("filters plugins by string path", () => {
37
+ const selector = createPluginsByPathSelector("customField");
38
+ const result = selector(mockState);
39
+
40
+ expect(result).toHaveLength(1);
41
+ expect(result[0].identifier).toBe("plugin1");
42
+ });
43
+
44
+ it("filters plugins by array path", () => {
45
+ const selector = createPluginsByPathSelector(["module", "urlScheme"]);
46
+ const result = selector(mockState);
47
+
48
+ expect(result).toHaveLength(2);
49
+ expect(result.map((p) => p.identifier)).toEqual(["plugin1", "plugin2"]);
50
+ });
51
+
52
+ it("handles missing plugins array", () => {
53
+ const selector = createPluginsByPathSelector("customField");
54
+ const result = selector({});
55
+
56
+ expect(result).toEqual([]);
57
+ });
58
+
59
+ it("handles non-existent path", () => {
60
+ const selector = createPluginsByPathSelector("nonexistent");
61
+ const result = selector(mockState);
62
+
63
+ expect(result).toEqual([]);
64
+ });
65
+ });
66
+
67
+ describe("createPluginsByModuleSelector", () => {
68
+ it("filters plugins by module path", () => {
69
+ const selector = createPluginsByModuleSelector("player");
70
+ const result = selector(mockState);
71
+
72
+ expect(result).toHaveLength(2);
73
+ expect(result.map((p) => p.identifier)).toEqual(["plugin1", "plugin3"]);
74
+ });
75
+
76
+ it("handles non-existent module", () => {
77
+ const selector = createPluginsByModuleSelector("nonexistent");
78
+ const result = selector(mockState);
79
+
80
+ expect(result).toEqual([]);
81
+ });
82
+ });
83
+
84
+ describe("combinePluginSelectors", () => {
85
+ it("combines multiple selectors with AND logic", () => {
86
+ const urlSchemeSelector = createPluginsByModuleSelector("urlScheme");
87
+ const playerSelector = createPluginsByModuleSelector("player");
88
+
89
+ const combinedSelector = combinePluginSelectors(
90
+ urlSchemeSelector,
91
+ playerSelector
92
+ );
93
+
94
+ const result = combinedSelector(mockState);
95
+
96
+ expect(result).toHaveLength(1);
97
+ expect(result[0].identifier).toBe("plugin1");
98
+ });
99
+
100
+ it("returns empty array when no plugins match all conditions", () => {
101
+ const urlSchemeSelector = createPluginsByModuleSelector("urlScheme");
102
+ const customSelector = createPluginsByPathSelector("nonexistent");
103
+
104
+ const combinedSelector = combinePluginSelectors(
105
+ urlSchemeSelector,
106
+ customSelector
107
+ );
108
+
109
+ const result = combinedSelector(mockState);
110
+
111
+ expect(result).toEqual([]);
112
+ });
113
+
114
+ it("handles empty state", () => {
115
+ const selector = combinePluginSelectors(
116
+ createPluginsByModuleSelector("urlScheme")
117
+ );
118
+
119
+ const result = selector({});
120
+
121
+ expect(result).toEqual([]);
122
+ });
123
+ });
124
+ });
package/utils/clone.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { cloneDeep } from "lodash";
2
+
3
+ export const clone = (value) => {
4
+ return typeof structuredClone !== "undefined"
5
+ ? structuredClone(value) // no support for hermes, fallback to cloneDeep
6
+ : cloneDeep(value);
7
+ };