@nosto/nosto-react 2.1.0 → 2.2.1
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/README.md +13 -0
- package/dist/index.d.ts +148 -24
- package/dist/index.es.js +255 -824
- package/dist/index.umd.js +1 -25
- package/package.json +3 -3
- package/src/components/Nosto404.tsx +17 -3
- package/src/components/NostoCategory.tsx +19 -3
- package/src/components/NostoCheckout.tsx +17 -3
- package/src/components/NostoHome.tsx +17 -3
- package/src/components/NostoOrder.tsx +19 -6
- package/src/components/NostoOther.tsx +17 -3
- package/src/components/NostoPlacement.tsx +6 -2
- package/src/components/NostoProduct.tsx +21 -8
- package/src/components/NostoProvider.tsx +8 -2
- package/src/components/NostoSearch.tsx +19 -3
- package/src/components/NostoSession.tsx +26 -7
- package/src/components/index.ts +10 -10
- package/src/hooks/useDeepCompareEffect.ts +6 -6
- package/src/hooks/useNostoApi.ts +3 -6
- package/src/hooks/useRenderCampaigns.tsx +4 -2
- package/src/utils/snakeize.ts +5 -1
- package/src/utils/types.ts +29 -0
package/src/utils/snakeize.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import { ToSnakeCase } from "./types"
|
|
2
|
+
|
|
3
|
+
// signature override
|
|
4
|
+
export function snakeize<T>(obj: T): ToSnakeCase<T>
|
|
5
|
+
export function snakeize<T>(obj: T): unknown {
|
|
2
6
|
if (!obj || typeof obj !== "object") {
|
|
3
7
|
return obj
|
|
4
8
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
type SnakeToCamelCase<S extends string> = S extends `${infer T}_${infer U}`
|
|
2
|
+
? `${T}${Capitalize<SnakeToCamelCase<U>>}`
|
|
3
|
+
: S
|
|
4
|
+
|
|
5
|
+
// Recursive type to apply the conversion to all keys in an object type
|
|
6
|
+
export type ToCamelCase<T> = T extends (infer U)[]
|
|
7
|
+
? ToCamelCase<U>[]
|
|
8
|
+
: T extends Date ? T
|
|
9
|
+
: T extends object
|
|
10
|
+
? {
|
|
11
|
+
[K in keyof T as SnakeToCamelCase<K & string>]: ToCamelCase<T[K]>
|
|
12
|
+
}
|
|
13
|
+
: T
|
|
14
|
+
|
|
15
|
+
type CamelToSnakeCase<S extends string> = S extends `${infer T}${infer U}`
|
|
16
|
+
? U extends Uncapitalize<U>
|
|
17
|
+
? `${Lowercase<T>}${CamelToSnakeCase<U>}`
|
|
18
|
+
: `${Lowercase<T>}_${CamelToSnakeCase<Uncapitalize<U>>}`
|
|
19
|
+
: S
|
|
20
|
+
|
|
21
|
+
// Recursive type to apply the conversion to all keys in an object type
|
|
22
|
+
export type ToSnakeCase<T> = T extends (infer U)[]
|
|
23
|
+
? ToSnakeCase<U>[]
|
|
24
|
+
: T extends Date ? T
|
|
25
|
+
: T extends object
|
|
26
|
+
? {
|
|
27
|
+
[K in keyof T as CamelToSnakeCase<K & string>]: ToSnakeCase<T[K]>
|
|
28
|
+
}
|
|
29
|
+
: T
|