@cargo-ai/utils 1.0.4
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/build/array.js +52 -0
- package/build/collection.js +155 -0
- package/build/components.js +56 -0
- package/build/cron.js +19 -0
- package/build/delay.js +52 -0
- package/build/hooks/index.js +35 -0
- package/build/hooks/useClickOutside.js +46 -0
- package/build/hooks/useCountAnimation.js +34 -0
- package/build/hooks/useDeviceType.js +54 -0
- package/build/hooks/useEventListener.js +27 -0
- package/build/hooks/useHeight.js +26 -0
- package/build/hooks/usePictureInPicture.js +126 -0
- package/build/hooks/useResizeObserver.js +35 -0
- package/build/hooks/useScrollPosition.js +22 -0
- package/build/hooks/useStepper.js +138 -0
- package/build/hooks/useStorageState.js +110 -0
- package/build/hooks/useVideoPlayer/VideoManager.js +78 -0
- package/build/hooks/useVideoPlayer/index.js +5 -0
- package/build/hooks/useVideoPlayer/useVideoPlayer.js +100 -0
- package/build/hooks/useWillUnmountEffect.js +13 -0
- package/build/index.js +28 -0
- package/build/json.js +81 -0
- package/build/random.js +7 -0
- package/build/src/array.d.ts +16 -0
- package/build/src/array.d.ts.map +1 -0
- package/build/src/array.js +81 -0
- package/build/src/base64.d.ts +3 -0
- package/build/src/base64.d.ts.map +1 -0
- package/build/src/base64.js +6 -0
- package/build/src/bytes.d.ts +7 -0
- package/build/src/bytes.d.ts.map +1 -0
- package/build/src/bytes.js +71 -0
- package/build/src/collection/deepMergeObjects.d.ts +2 -0
- package/build/src/collection/deepMergeObjects.d.ts.map +1 -0
- package/build/src/collection/deepMergeObjects.js +30 -0
- package/build/src/collection/index.d.ts +2 -0
- package/build/src/collection/index.d.ts.map +1 -0
- package/build/src/collection/index.js +1 -0
- package/build/src/collection.d.ts +22 -0
- package/build/src/collection.d.ts.map +1 -0
- package/build/src/collection.js +210 -0
- package/build/src/colors.d.ts +2 -0
- package/build/src/colors.d.ts.map +1 -0
- package/build/src/colors.js +14 -0
- package/build/src/components.d.ts +4 -0
- package/build/src/components.js +45 -0
- package/build/src/credits.d.ts +7 -0
- package/build/src/credits.d.ts.map +1 -0
- package/build/src/credits.js +88 -0
- package/build/src/cron.d.ts +3 -0
- package/build/src/cron.d.ts.map +1 -0
- package/build/src/cron.js +16 -0
- package/build/src/date/getContextTimezone.d.ts +2 -0
- package/build/src/date/getContextTimezone.d.ts.map +1 -0
- package/build/src/date/getContextTimezone.js +3 -0
- package/build/src/date/getDate.d.ts +8 -0
- package/build/src/date/getDate.d.ts.map +1 -0
- package/build/src/date/getDate.js +25 -0
- package/build/src/date/getDateString.d.ts +8 -0
- package/build/src/date/getDateString.d.ts.map +1 -0
- package/build/src/date/getDateString.js +13 -0
- package/build/src/date/getDatesDifferenceString.d.ts +2 -0
- package/build/src/date/getDatesDifferenceString.d.ts.map +1 -0
- package/build/src/date/getDatesDifferenceString.js +17 -0
- package/build/src/date/getTimeFromNowString.d.ts +2 -0
- package/build/src/date/getTimeFromNowString.d.ts.map +1 -0
- package/build/src/date/getTimeFromNowString.js +8 -0
- package/build/src/date/getTimezoneHoursOffset.d.ts +2 -0
- package/build/src/date/getTimezoneHoursOffset.d.ts.map +1 -0
- package/build/src/date/getTimezoneHoursOffset.js +7 -0
- package/build/src/date/getTimezoneOffsetString.d.ts +2 -0
- package/build/src/date/getTimezoneOffsetString.d.ts.map +1 -0
- package/build/src/date/getTimezoneOffsetString.js +8 -0
- package/build/src/date/index.d.ts +8 -0
- package/build/src/date/index.d.ts.map +1 -0
- package/build/src/date/index.js +7 -0
- package/build/src/date.d.ts +13 -0
- package/build/src/date.d.ts.map +1 -0
- package/build/src/date.js +14 -0
- package/build/src/delay.d.ts +7 -0
- package/build/src/delay.d.ts.map +1 -0
- package/build/src/delay.js +19 -0
- package/build/src/expression/getExpressionNodesReferences.d.ts +17 -0
- package/build/src/expression/getExpressionNodesReferences.d.ts.map +1 -0
- package/build/src/expression/getExpressionNodesReferences.js +71 -0
- package/build/src/expression/getObjectAccessKeysBeforeCursor.d.ts +17 -0
- package/build/src/expression/getObjectAccessKeysBeforeCursor.d.ts.map +1 -0
- package/build/src/expression/getObjectAccessKeysBeforeCursor.js +97 -0
- package/build/src/expression/index.d.ts +3 -0
- package/build/src/expression/index.d.ts.map +1 -0
- package/build/src/expression/index.js +2 -0
- package/build/src/expression/jsonSchema.d.ts +4 -0
- package/build/src/expression/jsonSchema.d.ts.map +1 -0
- package/build/src/expression/jsonSchema.js +85 -0
- package/build/src/expression/matchIsExpression.d.ts +2 -0
- package/build/src/expression/matchIsExpression.d.ts.map +1 -0
- package/build/src/expression/matchIsExpression.js +10 -0
- package/build/src/expression/matchIsExpressionObject.d.ts +2 -0
- package/build/src/expression/matchIsExpressionObject.d.ts.map +1 -0
- package/build/src/expression/matchIsExpressionObject.js +10 -0
- package/build/src/expression/matchIsExpressionString.d.ts +2 -0
- package/build/src/expression/matchIsExpressionString.d.ts.map +1 -0
- package/build/src/expression/matchIsExpressionString.js +4 -0
- package/build/src/gclid.d.ts +4 -0
- package/build/src/gclid.d.ts.map +1 -0
- package/build/src/gclid.js +30 -0
- package/build/src/hooks/index.d.ts +12 -0
- package/build/src/hooks/index.js +12 -0
- package/build/src/hooks/useClickOutside.d.ts +4 -0
- package/build/src/hooks/useClickOutside.js +42 -0
- package/build/src/hooks/useCountAnimation.d.ts +1 -0
- package/build/src/hooks/useCountAnimation.js +30 -0
- package/build/src/hooks/useDeviceType.d.ts +2 -0
- package/build/src/hooks/useDeviceType.js +50 -0
- package/build/src/hooks/useEventListener.d.ts +6 -0
- package/build/src/hooks/useEventListener.js +23 -0
- package/build/src/hooks/useHeight.d.ts +2 -0
- package/build/src/hooks/useHeight.js +20 -0
- package/build/src/hooks/usePictureInPicture.d.ts +9 -0
- package/build/src/hooks/usePictureInPicture.js +60 -0
- package/build/src/hooks/useResizeObserver.d.ts +4 -0
- package/build/src/hooks/useResizeObserver.js +31 -0
- package/build/src/hooks/useScrollPosition.d.ts +5 -0
- package/build/src/hooks/useScrollPosition.js +18 -0
- package/build/src/hooks/useStepper.d.ts +26 -0
- package/build/src/hooks/useStepper.js +136 -0
- package/build/src/hooks/useStorageState.d.ts +12 -0
- package/build/src/hooks/useStorageState.js +53 -0
- package/build/src/hooks/useVideoPlayer/VideoManager.d.ts +18 -0
- package/build/src/hooks/useVideoPlayer/VideoManager.js +72 -0
- package/build/src/hooks/useVideoPlayer/index.d.ts +1 -0
- package/build/src/hooks/useVideoPlayer/index.js +1 -0
- package/build/src/hooks/useVideoPlayer/useVideoPlayer.d.ts +15 -0
- package/build/src/hooks/useVideoPlayer/useVideoPlayer.js +96 -0
- package/build/src/hooks/useWillUnmountEffect.d.ts +1 -0
- package/build/src/hooks/useWillUnmountEffect.js +8 -0
- package/build/src/index.d.ts +27 -0
- package/build/src/index.d.ts.map +1 -0
- package/build/src/index.js +26 -0
- package/build/src/integration.d.ts +14 -0
- package/build/src/integration.d.ts.map +1 -0
- package/build/src/integration.js +72 -0
- package/build/src/json/castToJsonType.d.ts +5 -0
- package/build/src/json/castToJsonType.d.ts.map +1 -0
- package/build/src/json/castToJsonType.js +58 -0
- package/build/src/json/cleanJson.d.ts +3 -0
- package/build/src/json/cleanJson.d.ts.map +1 -0
- package/build/src/json/cleanJson.js +18 -0
- package/build/src/json/constants.d.ts +3 -0
- package/build/src/json/constants.d.ts.map +1 -0
- package/build/src/json/constants.js +9 -0
- package/build/src/json/getJsonType.d.ts +3 -0
- package/build/src/json/getJsonType.d.ts.map +1 -0
- package/build/src/json/getJsonType.js +24 -0
- package/build/src/json/index.d.ts +8 -0
- package/build/src/json/index.d.ts.map +1 -0
- package/build/src/json/index.js +7 -0
- package/build/src/json/isJson.d.ts +2 -0
- package/build/src/json/isJson.d.ts.map +1 -0
- package/build/src/json/isJson.js +9 -0
- package/build/src/json/isJsonSchemaEmpty.d.ts +3 -0
- package/build/src/json/isJsonSchemaEmpty.d.ts.map +1 -0
- package/build/src/json/isJsonSchemaEmpty.js +7 -0
- package/build/src/json/stringifyJson.d.ts +2 -0
- package/build/src/json/stringifyJson.d.ts.map +1 -0
- package/build/src/json/stringifyJson.js +6 -0
- package/build/src/json/types.d.ts +2 -0
- package/build/src/json/types.d.ts.map +1 -0
- package/build/src/json/types.js +1 -0
- package/build/src/json.d.ts +13 -0
- package/build/src/json.d.ts.map +1 -0
- package/build/src/json.js +107 -0
- package/build/src/jsonSchema/index.d.ts +10 -0
- package/build/src/jsonSchema/index.d.ts.map +1 -0
- package/build/src/jsonSchema/index.js +198 -0
- package/build/src/jsonSchema.d.ts +5 -0
- package/build/src/jsonSchema.d.ts.map +1 -0
- package/build/src/jsonSchema.js +73 -0
- package/build/src/number/formatCredits.d.ts +2 -0
- package/build/src/number/formatCredits.d.ts.map +1 -0
- package/build/src/number/formatCredits.js +7 -0
- package/build/src/number/formatPrice.d.ts +2 -0
- package/build/src/number/formatPrice.d.ts.map +1 -0
- package/build/src/number/formatPrice.js +8 -0
- package/build/src/number/getNumberWithMaxDecimals.d.ts +2 -0
- package/build/src/number/getNumberWithMaxDecimals.d.ts.map +1 -0
- package/build/src/number/getNumberWithMaxDecimals.js +3 -0
- package/build/src/number/index.d.ts +4 -0
- package/build/src/number/index.d.ts.map +1 -0
- package/build/src/number/index.js +3 -0
- package/build/src/poll.d.ts +5 -0
- package/build/src/poll.d.ts.map +1 -0
- package/build/src/poll.js +30 -0
- package/build/src/random.d.ts +2 -0
- package/build/src/random.d.ts.map +1 -0
- package/build/src/random.js +3 -0
- package/build/src/schema.d.ts +24 -0
- package/build/src/schema.d.ts.map +1 -0
- package/build/src/schema.js +315 -0
- package/build/src/searchInTree.d.ts +46 -0
- package/build/src/searchInTree.d.ts.map +1 -0
- package/build/src/searchInTree.js +67 -0
- package/build/src/storage.d.ts +13 -0
- package/build/src/storage.d.ts.map +1 -0
- package/build/src/storage.js +169 -0
- package/build/src/string/capitalizeFirstLetter.d.ts +2 -0
- package/build/src/string/capitalizeFirstLetter.d.ts.map +1 -0
- package/build/src/string/capitalizeFirstLetter.js +3 -0
- package/build/src/string/findAllIndexOf.d.ts +2 -0
- package/build/src/string/findAllIndexOf.d.ts.map +1 -0
- package/build/src/string/findAllIndexOf.js +13 -0
- package/build/src/string/getHash.d.ts +2 -0
- package/build/src/string/getHash.d.ts.map +1 -0
- package/build/src/string/getHash.js +9 -0
- package/build/src/string/index.d.ts +5 -0
- package/build/src/string/index.d.ts.map +1 -0
- package/build/src/string/index.js +4 -0
- package/build/src/string/sentenceCase.d.ts +2 -0
- package/build/src/string/sentenceCase.d.ts.map +1 -0
- package/build/src/string/sentenceCase.js +38 -0
- package/build/src/string.d.ts +2 -0
- package/build/src/string.d.ts.map +1 -0
- package/build/src/string.js +3 -0
- package/build/src/type.d.ts +10 -0
- package/build/src/type.js +1 -0
- package/build/src/types.d.ts +22 -0
- package/build/src/types.d.ts.map +1 -0
- package/build/src/types.js +1 -0
- package/build/src/user.d.ts +3 -0
- package/build/src/user.d.ts.map +1 -0
- package/build/src/user.js +7 -0
- package/build/src/validation/index.d.ts +2 -0
- package/build/src/validation/index.d.ts.map +1 -0
- package/build/src/validation/index.js +1 -0
- package/build/src/validation/matchIsObjectLike.d.ts +2 -0
- package/build/src/validation/matchIsObjectLike.d.ts.map +1 -0
- package/build/src/validation/matchIsObjectLike.js +4 -0
- package/build/src/vm.d.ts +1 -0
- package/build/src/vm.js +32 -0
- package/build/src/zod/index.d.ts +14 -0
- package/build/src/zod/index.d.ts.map +1 -0
- package/build/src/zod/index.js +210 -0
- package/build/src/zod.d.ts +8 -0
- package/build/src/zod.d.ts.map +1 -0
- package/build/src/zod.js +89 -0
- package/build/storage.js +285 -0
- package/build/string.js +17 -0
- package/build/tsconfig.tsbuildinfo +1 -0
- package/build/type.js +2 -0
- package/build/user.js +12 -0
- package/package.json +50 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export function useStepper(props) {
|
|
3
|
+
const { steps, initialStep, onStep } = props;
|
|
4
|
+
React.useEffect(() => {
|
|
5
|
+
checkUniqueKeys(steps);
|
|
6
|
+
}, [steps]);
|
|
7
|
+
const initialIndex = React.useMemo(() => {
|
|
8
|
+
const stepIndex = steps.findIndex((step) => {
|
|
9
|
+
return step.key === initialStep;
|
|
10
|
+
});
|
|
11
|
+
if (stepIndex === -1) {
|
|
12
|
+
return 0;
|
|
13
|
+
}
|
|
14
|
+
return stepIndex;
|
|
15
|
+
}, [initialStep, steps]);
|
|
16
|
+
const [stepIndex, setStepIndex] = React.useState(initialIndex);
|
|
17
|
+
const step = React.useMemo(() => {
|
|
18
|
+
return steps[stepIndex];
|
|
19
|
+
}, [stepIndex, steps]);
|
|
20
|
+
const isFirstStep = React.useMemo(() => {
|
|
21
|
+
return stepIndex === 0;
|
|
22
|
+
}, [stepIndex]);
|
|
23
|
+
const isLastStep = React.useMemo(() => {
|
|
24
|
+
return stepIndex === steps.length - 1;
|
|
25
|
+
}, [stepIndex, steps.length]);
|
|
26
|
+
const goToNextStep = React.useCallback(() => {
|
|
27
|
+
setStepIndex((currentStepIndex) => {
|
|
28
|
+
const nextIndex = Math.min(currentStepIndex + 1, steps.length - 1);
|
|
29
|
+
const nextStep = steps[nextIndex];
|
|
30
|
+
if (nextStep !== undefined && onStep !== undefined) {
|
|
31
|
+
onStep(nextStep, nextIndex);
|
|
32
|
+
}
|
|
33
|
+
return nextIndex;
|
|
34
|
+
});
|
|
35
|
+
}, [steps, onStep]);
|
|
36
|
+
const goToPreviousStep = React.useCallback(() => {
|
|
37
|
+
setStepIndex((currentStepIndex) => {
|
|
38
|
+
const previousIndex = Math.max(currentStepIndex - 1, 0);
|
|
39
|
+
const previousStep = steps[previousIndex];
|
|
40
|
+
if (previousStep !== undefined && onStep !== undefined) {
|
|
41
|
+
onStep(previousStep, previousIndex);
|
|
42
|
+
}
|
|
43
|
+
return previousIndex;
|
|
44
|
+
});
|
|
45
|
+
}, [steps, onStep]);
|
|
46
|
+
const goToStep = React.useCallback((key) => {
|
|
47
|
+
const index = steps.findIndex((curentStep) => {
|
|
48
|
+
return curentStep.key === key;
|
|
49
|
+
});
|
|
50
|
+
if (index === -1) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
setStepIndex(index);
|
|
54
|
+
const indexStep = steps[index];
|
|
55
|
+
if (indexStep !== undefined && onStep !== undefined) {
|
|
56
|
+
onStep(indexStep, index);
|
|
57
|
+
}
|
|
58
|
+
}, [steps, onStep]);
|
|
59
|
+
const reset = React.useCallback(() => {
|
|
60
|
+
setStepIndex(initialIndex);
|
|
61
|
+
const initialIndexStep = steps[initialIndex];
|
|
62
|
+
if (initialIndexStep !== undefined && onStep !== undefined) {
|
|
63
|
+
onStep(initialIndexStep, initialIndex);
|
|
64
|
+
}
|
|
65
|
+
}, [initialIndex, steps, onStep]);
|
|
66
|
+
const ComponentWithInjectedProps = React.useMemo(() => {
|
|
67
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, react/display-name
|
|
68
|
+
return (props) => {
|
|
69
|
+
if (step === undefined) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
return React.createElement(step.Component, {
|
|
73
|
+
...props,
|
|
74
|
+
step,
|
|
75
|
+
stepIndex,
|
|
76
|
+
isFirstStep,
|
|
77
|
+
isLastStep,
|
|
78
|
+
goToNextStep,
|
|
79
|
+
goToPreviousStep,
|
|
80
|
+
goToStep,
|
|
81
|
+
reset,
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
}, [
|
|
85
|
+
step,
|
|
86
|
+
goToStep,
|
|
87
|
+
isFirstStep,
|
|
88
|
+
isLastStep,
|
|
89
|
+
goToNextStep,
|
|
90
|
+
goToPreviousStep,
|
|
91
|
+
reset,
|
|
92
|
+
stepIndex,
|
|
93
|
+
]);
|
|
94
|
+
const currentStep = React.useMemo(() => {
|
|
95
|
+
if (step === undefined) {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
...step,
|
|
100
|
+
Component: ComponentWithInjectedProps,
|
|
101
|
+
};
|
|
102
|
+
}, [ComponentWithInjectedProps, step]);
|
|
103
|
+
const values = React.useMemo(() => {
|
|
104
|
+
return {
|
|
105
|
+
step: currentStep,
|
|
106
|
+
stepIndex,
|
|
107
|
+
isFirstStep,
|
|
108
|
+
isLastStep,
|
|
109
|
+
goToNextStep,
|
|
110
|
+
goToPreviousStep,
|
|
111
|
+
goToStep,
|
|
112
|
+
reset,
|
|
113
|
+
};
|
|
114
|
+
}, [
|
|
115
|
+
currentStep,
|
|
116
|
+
stepIndex,
|
|
117
|
+
isFirstStep,
|
|
118
|
+
isLastStep,
|
|
119
|
+
goToNextStep,
|
|
120
|
+
goToPreviousStep,
|
|
121
|
+
goToStep,
|
|
122
|
+
reset,
|
|
123
|
+
]);
|
|
124
|
+
return values;
|
|
125
|
+
}
|
|
126
|
+
function checkUniqueKeys(steps) {
|
|
127
|
+
const keys = steps.map((step) => {
|
|
128
|
+
return step.key;
|
|
129
|
+
});
|
|
130
|
+
const duplicates = keys.filter((key, index) => {
|
|
131
|
+
return keys.indexOf(key) !== index;
|
|
132
|
+
});
|
|
133
|
+
if (duplicates.length > 0) {
|
|
134
|
+
throw new Error(`Duplicate step keys found: ${duplicates.join(", ")}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Storage } from "../storage.js";
|
|
2
|
+
interface Options<T> {
|
|
3
|
+
key: string | undefined;
|
|
4
|
+
defaultValue: T;
|
|
5
|
+
storage?: Storage;
|
|
6
|
+
getValueOverrideAfterRestore?: (storedValue: T | undefined) => Promise<T> | T;
|
|
7
|
+
matchIsValueToBeStored?: (value: T) => boolean;
|
|
8
|
+
}
|
|
9
|
+
type SetStateSignature<T> = (value: T | ((currentValue: T) => T)) => void;
|
|
10
|
+
type ReturnType<T> = [T, SetStateSignature<T>, boolean];
|
|
11
|
+
export declare function useStorageState<T>(options: Options<T>): ReturnType<T>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { getItemFromStorage, setItemInStorage, } from "../storage.js";
|
|
3
|
+
export function useStorageState(options) {
|
|
4
|
+
const { key, defaultValue, storage = "localStorage", getValueOverrideAfterRestore, matchIsValueToBeStored, } = options;
|
|
5
|
+
const [storedValue, setStoreValue] = React.useState(defaultValue);
|
|
6
|
+
const [hasRestoredValue, setHasRestoredValue] = React.useState(false);
|
|
7
|
+
const isRestoringValueRef = React.useRef(false);
|
|
8
|
+
const lastKeyRestoredRef = React.useRef(undefined);
|
|
9
|
+
const callbacksAfterRestoreRef = React.useRef([]);
|
|
10
|
+
React.useEffect(() => {
|
|
11
|
+
if (key === undefined || key === lastKeyRestoredRef.current) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
setHasRestoredValue(false);
|
|
15
|
+
isRestoringValueRef.current = true;
|
|
16
|
+
lastKeyRestoredRef.current = key;
|
|
17
|
+
const updateRestoredStorageValue = async () => {
|
|
18
|
+
const storageValue = await getItemFromStorage(key, { storage });
|
|
19
|
+
const restoredValue = getValueOverrideAfterRestore !== undefined
|
|
20
|
+
? await getValueOverrideAfterRestore(storageValue)
|
|
21
|
+
: storageValue;
|
|
22
|
+
if (restoredValue !== undefined) {
|
|
23
|
+
let restoredValueAfterCallbacks = restoredValue;
|
|
24
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
25
|
+
for (const callback of callbacksAfterRestoreRef.current) {
|
|
26
|
+
restoredValueAfterCallbacks = callback(restoredValueAfterCallbacks);
|
|
27
|
+
}
|
|
28
|
+
setStoreValue(restoredValueAfterCallbacks);
|
|
29
|
+
}
|
|
30
|
+
setHasRestoredValue(true);
|
|
31
|
+
isRestoringValueRef.current = false;
|
|
32
|
+
callbacksAfterRestoreRef.current = [];
|
|
33
|
+
};
|
|
34
|
+
updateRestoredStorageValue();
|
|
35
|
+
}, [defaultValue, getValueOverrideAfterRestore, key, storage]);
|
|
36
|
+
const setValue = React.useCallback((value) => {
|
|
37
|
+
if (isRestoringValueRef.current === true) {
|
|
38
|
+
callbacksAfterRestoreRef.current.push(value instanceof Function ? value : () => value);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const valueToStore = value instanceof Function ? value(storedValue) : value;
|
|
42
|
+
setStoreValue(valueToStore);
|
|
43
|
+
if (key !== undefined &&
|
|
44
|
+
(matchIsValueToBeStored === undefined ||
|
|
45
|
+
matchIsValueToBeStored(valueToStore))) {
|
|
46
|
+
setItemInStorage(key, valueToStore, { storage });
|
|
47
|
+
}
|
|
48
|
+
}, [key, storedValue, matchIsValueToBeStored, storage]);
|
|
49
|
+
const returnValue = React.useMemo(() => {
|
|
50
|
+
return [storedValue, setValue, hasRestoredValue];
|
|
51
|
+
}, [storedValue, setValue, hasRestoredValue]);
|
|
52
|
+
return returnValue;
|
|
53
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare class VideoManager {
|
|
2
|
+
private static instance;
|
|
3
|
+
private videoElement;
|
|
4
|
+
private isPlaying;
|
|
5
|
+
private hasStarted;
|
|
6
|
+
private currentTime;
|
|
7
|
+
private constructor();
|
|
8
|
+
static getInstance(): VideoManager;
|
|
9
|
+
setVideoElement(video: HTMLVideoElement): void;
|
|
10
|
+
getVideoElement(): HTMLVideoElement | null;
|
|
11
|
+
play(): void;
|
|
12
|
+
pause(): void;
|
|
13
|
+
saveVideoState(): void;
|
|
14
|
+
restoreVideoState(): void;
|
|
15
|
+
releaseVideo(): void;
|
|
16
|
+
isSameVideo(video: HTMLVideoElement): boolean;
|
|
17
|
+
getHasStarted(): boolean;
|
|
18
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// Singleton to ensure unique video element
|
|
2
|
+
export class VideoManager {
|
|
3
|
+
static instance = null;
|
|
4
|
+
videoElement = null;
|
|
5
|
+
isPlaying = false;
|
|
6
|
+
hasStarted = false;
|
|
7
|
+
currentTime = 0;
|
|
8
|
+
constructor() { }
|
|
9
|
+
static getInstance() {
|
|
10
|
+
if (VideoManager.instance === null) {
|
|
11
|
+
VideoManager.instance = new VideoManager();
|
|
12
|
+
}
|
|
13
|
+
return VideoManager.instance;
|
|
14
|
+
}
|
|
15
|
+
setVideoElement(video) {
|
|
16
|
+
if (this.videoElement !== null && this.videoElement !== video) {
|
|
17
|
+
this.saveVideoState();
|
|
18
|
+
this.releaseVideo();
|
|
19
|
+
}
|
|
20
|
+
this.videoElement = video;
|
|
21
|
+
this.restoreVideoState();
|
|
22
|
+
}
|
|
23
|
+
getVideoElement() {
|
|
24
|
+
return this.videoElement;
|
|
25
|
+
}
|
|
26
|
+
play() {
|
|
27
|
+
if (this.videoElement === null) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
this.videoElement.play();
|
|
31
|
+
this.isPlaying = true;
|
|
32
|
+
this.hasStarted = true;
|
|
33
|
+
}
|
|
34
|
+
pause() {
|
|
35
|
+
if (this.videoElement === null) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
this.videoElement.pause();
|
|
39
|
+
this.isPlaying = false;
|
|
40
|
+
}
|
|
41
|
+
saveVideoState() {
|
|
42
|
+
if (this.videoElement === null) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
this.currentTime = this.videoElement.currentTime;
|
|
46
|
+
this.isPlaying = this.videoElement.paused === false;
|
|
47
|
+
this.hasStarted = this.isPlaying || this.currentTime > 0;
|
|
48
|
+
}
|
|
49
|
+
restoreVideoState() {
|
|
50
|
+
if (this.videoElement === null) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
this.videoElement.currentTime = this.currentTime;
|
|
54
|
+
if (this.isPlaying === true && this.videoElement.paused === true) {
|
|
55
|
+
this.videoElement.play();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
releaseVideo() {
|
|
59
|
+
if (this.videoElement === null) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
this.pause();
|
|
63
|
+
this.videoElement = null;
|
|
64
|
+
this.hasStarted = false;
|
|
65
|
+
}
|
|
66
|
+
isSameVideo(video) {
|
|
67
|
+
return this.videoElement === video;
|
|
68
|
+
}
|
|
69
|
+
getHasStarted() {
|
|
70
|
+
return this.hasStarted;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useVideoPlayer } from "./useVideoPlayer.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useVideoPlayer } from "./useVideoPlayer.js";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { VideoManager } from "./VideoManager.js";
|
|
3
|
+
type UsevideoPlayerValues = readonly [
|
|
4
|
+
React.MutableRefObject<HTMLVideoElement | null>,
|
|
5
|
+
{
|
|
6
|
+
readonly isPlaying: boolean;
|
|
7
|
+
readonly hasStarted: boolean;
|
|
8
|
+
readonly onPlayback: () => void;
|
|
9
|
+
readonly onVideoEnd: () => void;
|
|
10
|
+
readonly videoDuration: number | null;
|
|
11
|
+
readonly videoManager: VideoManager;
|
|
12
|
+
}
|
|
13
|
+
];
|
|
14
|
+
export declare function useVideoPlayer(): UsevideoPlayerValues;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { VideoManager } from "./VideoManager.js";
|
|
3
|
+
export function useVideoPlayer() {
|
|
4
|
+
const videoRef = React.useRef(null);
|
|
5
|
+
const videoManagerRef = React.useRef(VideoManager.getInstance());
|
|
6
|
+
const [isPlaying, setIsPlaying] = React.useState(false);
|
|
7
|
+
const [hasStarted, setHasStarted] = React.useState(videoManagerRef.current.getHasStarted());
|
|
8
|
+
const [videoDuration, setVideoDuration] = React.useState(null);
|
|
9
|
+
const onPlayback = React.useCallback(() => {
|
|
10
|
+
const videoElement = videoRef.current;
|
|
11
|
+
if (videoElement === null) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const videoManager = videoManagerRef.current;
|
|
15
|
+
videoManager.setVideoElement(videoElement);
|
|
16
|
+
if (videoElement.paused === true || videoElement.ended === true) {
|
|
17
|
+
videoManager.play();
|
|
18
|
+
setIsPlaying(true);
|
|
19
|
+
setHasStarted(true);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
videoManager.pause();
|
|
23
|
+
setIsPlaying(false);
|
|
24
|
+
}
|
|
25
|
+
}, []);
|
|
26
|
+
const onVideoEnd = React.useCallback(() => {
|
|
27
|
+
const videoElement = videoRef.current;
|
|
28
|
+
if (videoElement === null) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const videoManager = videoManagerRef.current;
|
|
32
|
+
videoManager.releaseVideo();
|
|
33
|
+
videoManager.saveVideoState();
|
|
34
|
+
videoManager.pause();
|
|
35
|
+
setIsPlaying(false);
|
|
36
|
+
setHasStarted(false);
|
|
37
|
+
}, []);
|
|
38
|
+
React.useEffect(() => {
|
|
39
|
+
const videoElement = videoRef.current;
|
|
40
|
+
if (videoElement === null) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
const videoManager = videoManagerRef.current;
|
|
44
|
+
if (videoManager.isSameVideo(videoElement) === true) {
|
|
45
|
+
videoManager.restoreVideoState();
|
|
46
|
+
setHasStarted(videoManager.getHasStarted());
|
|
47
|
+
setIsPlaying(videoElement.paused === false);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
videoElement.currentTime = 0;
|
|
51
|
+
setHasStarted(false);
|
|
52
|
+
setIsPlaying(false);
|
|
53
|
+
}
|
|
54
|
+
const handlePlay = () => {
|
|
55
|
+
setIsPlaying(true);
|
|
56
|
+
setHasStarted(true);
|
|
57
|
+
};
|
|
58
|
+
const handlePause = () => {
|
|
59
|
+
setIsPlaying(false);
|
|
60
|
+
};
|
|
61
|
+
const handleEnded = () => {
|
|
62
|
+
setIsPlaying(false);
|
|
63
|
+
setHasStarted(false);
|
|
64
|
+
};
|
|
65
|
+
const handleLoadedMetadata = () => {
|
|
66
|
+
setVideoDuration(videoElement.duration);
|
|
67
|
+
};
|
|
68
|
+
videoElement.addEventListener("play", handlePlay);
|
|
69
|
+
videoElement.addEventListener("pause", handlePause);
|
|
70
|
+
videoElement.addEventListener("ended", handleEnded);
|
|
71
|
+
videoElement.addEventListener("loadedmetadata", handleLoadedMetadata);
|
|
72
|
+
return () => {
|
|
73
|
+
videoElement.removeEventListener("play", handlePlay);
|
|
74
|
+
videoElement.removeEventListener("pause", handlePause);
|
|
75
|
+
videoElement.removeEventListener("ended", handleEnded);
|
|
76
|
+
videoElement.removeEventListener("loadedmetadata", handleLoadedMetadata);
|
|
77
|
+
const videoManager = VideoManager.getInstance();
|
|
78
|
+
if (videoManager.isSameVideo(videoElement) === true) {
|
|
79
|
+
videoManager.saveVideoState();
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}, []);
|
|
83
|
+
return React.useMemo(() => {
|
|
84
|
+
return [
|
|
85
|
+
videoRef,
|
|
86
|
+
{
|
|
87
|
+
isPlaying,
|
|
88
|
+
hasStarted,
|
|
89
|
+
onPlayback,
|
|
90
|
+
onVideoEnd,
|
|
91
|
+
videoDuration,
|
|
92
|
+
videoManager: videoManagerRef.current,
|
|
93
|
+
},
|
|
94
|
+
];
|
|
95
|
+
}, [hasStarted, isPlaying, onPlayback, onVideoEnd, videoDuration]);
|
|
96
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useWillUnmountEffect: (cleanupCallback?: () => void) => void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export const useWillUnmountEffect = (cleanupCallback = () => { }) => {
|
|
3
|
+
const callbackRef = React.useRef(cleanupCallback);
|
|
4
|
+
callbackRef.current = cleanupCallback; // always up to date
|
|
5
|
+
React.useEffect(() => {
|
|
6
|
+
return () => callbackRef.current();
|
|
7
|
+
}, []);
|
|
8
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export * from "./array.js";
|
|
2
|
+
export * from "./base64.js";
|
|
3
|
+
export * from "./bytes.js";
|
|
4
|
+
export * from "./collection.js";
|
|
5
|
+
export * from "./collection/index.js";
|
|
6
|
+
export * from "./colors.js";
|
|
7
|
+
export * from "./credits.js";
|
|
8
|
+
export * from "./cron.js";
|
|
9
|
+
export * from "./date/index.js";
|
|
10
|
+
export * from "./delay.js";
|
|
11
|
+
export * from "./expression/index.js";
|
|
12
|
+
export * from "./gclid.js";
|
|
13
|
+
export * from "./json/index.js";
|
|
14
|
+
export * from "./jsonSchema/index.js";
|
|
15
|
+
export * from "./number/index.js";
|
|
16
|
+
export * from "./poll.js";
|
|
17
|
+
export * from "./random.js";
|
|
18
|
+
export * from "./schema.js";
|
|
19
|
+
export * from "./searchInTree.js";
|
|
20
|
+
export * from "./storage.js";
|
|
21
|
+
export * from "./string.js";
|
|
22
|
+
export * from "./string/index.js";
|
|
23
|
+
export * from "./types.js";
|
|
24
|
+
export * from "./user.js";
|
|
25
|
+
export * from "./validation/index.js";
|
|
26
|
+
export * from "./zod/index.js";
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,uBAAuB,CAAC;AACtC,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,uBAAuB,CAAC;AACtC,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export * from "./array.js";
|
|
2
|
+
export * from "./base64.js";
|
|
3
|
+
export * from "./bytes.js";
|
|
4
|
+
export * from "./collection.js";
|
|
5
|
+
export * from "./collection/index.js";
|
|
6
|
+
export * from "./colors.js";
|
|
7
|
+
export * from "./credits.js";
|
|
8
|
+
export * from "./cron.js";
|
|
9
|
+
export * from "./date/index.js";
|
|
10
|
+
export * from "./delay.js";
|
|
11
|
+
export * from "./expression/index.js";
|
|
12
|
+
export * from "./gclid.js";
|
|
13
|
+
export * from "./json/index.js";
|
|
14
|
+
export * from "./jsonSchema/index.js";
|
|
15
|
+
export * from "./number/index.js";
|
|
16
|
+
export * from "./poll.js";
|
|
17
|
+
export * from "./random.js";
|
|
18
|
+
export * from "./schema.js";
|
|
19
|
+
export * from "./searchInTree.js";
|
|
20
|
+
export * from "./storage.js";
|
|
21
|
+
export * from "./string.js";
|
|
22
|
+
export * from "./string/index.js";
|
|
23
|
+
export * from "./types.js";
|
|
24
|
+
export * from "./user.js";
|
|
25
|
+
export * from "./validation/index.js";
|
|
26
|
+
export * from "./zod/index.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { JsonSchema } from "json.js";
|
|
2
|
+
type IntegrationAction = {
|
|
3
|
+
name: string;
|
|
4
|
+
config: {
|
|
5
|
+
jsonSchema: JsonSchema;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export declare const INTEGRATION_ACTION_PROPERTIES: {
|
|
9
|
+
objectType: string;
|
|
10
|
+
operation: string;
|
|
11
|
+
};
|
|
12
|
+
export declare const getIntegrationActionName: (integrationActionSlug: string, integrationAction: IntegrationAction, config: Record<string, unknown>) => string;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=integration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integration.d.ts","sourceRoot":"","sources":["../../src/integration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAG1C,KAAK,iBAAiB,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE;QACN,UAAU,EAAE,UAAU,CAAC;KACxB,CAAC;CACH,CAAC;AAEF,eAAO,MAAM,6BAA6B;;;CAGzC,CAAC;AAEF,eAAO,MAAM,wBAAwB,0BACZ,MAAM,qBACV,iBAAiB,UAC5B,OAAO,MAAM,EAAE,OAAO,CAAC,KAC9B,MAcF,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import pluralize from "pluralize";
|
|
2
|
+
export const INTEGRATION_ACTION_PROPERTIES = {
|
|
3
|
+
objectType: "objectType",
|
|
4
|
+
operation: "action",
|
|
5
|
+
};
|
|
6
|
+
export const getIntegrationActionName = (integrationActionSlug, integrationAction, config) => {
|
|
7
|
+
const operationName = getIntegrationActionOperationName(integrationActionSlug, integrationAction, config[INTEGRATION_ACTION_PROPERTIES.operation]);
|
|
8
|
+
const objectTypeName = getIntegrationActionObjectTypeName(integrationActionSlug, integrationAction, config[INTEGRATION_ACTION_PROPERTIES.objectType]);
|
|
9
|
+
return `${operationName}${objectTypeName !== undefined ? ` ${objectTypeName}` : ""}`;
|
|
10
|
+
};
|
|
11
|
+
const getIntegrationActionOperationName = (integrationActionSlug, integrationAction, operation) => {
|
|
12
|
+
if (operation === undefined) {
|
|
13
|
+
return integrationAction.name;
|
|
14
|
+
}
|
|
15
|
+
if (integrationAction.config.jsonSchema.properties === undefined) {
|
|
16
|
+
return integrationAction.name;
|
|
17
|
+
}
|
|
18
|
+
const operationJsonSchema = integrationAction.config.jsonSchema.properties[INTEGRATION_ACTION_PROPERTIES.operation];
|
|
19
|
+
if (operationJsonSchema === undefined ||
|
|
20
|
+
operationJsonSchema.oneOf === undefined) {
|
|
21
|
+
return integrationAction.name;
|
|
22
|
+
}
|
|
23
|
+
const operationEnumJsonSchema = operationJsonSchema.oneOf.find((jsonSchema) => {
|
|
24
|
+
return jsonSchema.const === operation;
|
|
25
|
+
});
|
|
26
|
+
if (operationEnumJsonSchema === undefined) {
|
|
27
|
+
return integrationAction.name;
|
|
28
|
+
}
|
|
29
|
+
if (integrationActionSlug === "associate") {
|
|
30
|
+
if (operation === "add") {
|
|
31
|
+
return "Add to";
|
|
32
|
+
}
|
|
33
|
+
if (operation === "remove") {
|
|
34
|
+
return "Remove from";
|
|
35
|
+
}
|
|
36
|
+
if (operation === "delete") {
|
|
37
|
+
return "Remove from";
|
|
38
|
+
}
|
|
39
|
+
if (operation === "create") {
|
|
40
|
+
return "Create association";
|
|
41
|
+
}
|
|
42
|
+
if (operation === "delete") {
|
|
43
|
+
return "Delete association";
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return operationEnumJsonSchema.title !== undefined
|
|
47
|
+
? operationEnumJsonSchema.title
|
|
48
|
+
: integrationAction.name;
|
|
49
|
+
};
|
|
50
|
+
const getIntegrationActionObjectTypeName = (integrationActionSlug, integrationAction, objectType) => {
|
|
51
|
+
if (integrationAction.config.jsonSchema.properties === undefined) {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
const operationJsonSchema = integrationAction.config.jsonSchema.properties[INTEGRATION_ACTION_PROPERTIES.objectType];
|
|
55
|
+
if (operationJsonSchema === undefined ||
|
|
56
|
+
operationJsonSchema.oneOf === undefined) {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
let jsonSchemaEnum = objectType !== undefined
|
|
60
|
+
? operationJsonSchema.oneOf.find((jsonSchema) => jsonSchema.const === objectType)
|
|
61
|
+
: undefined;
|
|
62
|
+
if (jsonSchemaEnum === undefined) {
|
|
63
|
+
jsonSchemaEnum = operationJsonSchema.oneOf.find((jsonSchema) => jsonSchema.type === "string");
|
|
64
|
+
}
|
|
65
|
+
if (jsonSchemaEnum === undefined || jsonSchemaEnum.title === undefined) {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
if (integrationActionSlug === "search" || integrationActionSlug === "count") {
|
|
69
|
+
return pluralize.plural(jsonSchemaEnum.title).toLowerCase();
|
|
70
|
+
}
|
|
71
|
+
return pluralize.singular(jsonSchemaEnum.title).toLowerCase();
|
|
72
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"castToJsonType.d.ts","sourceRoot":"","sources":["../../../src/json/castToJsonType.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,eAAO,MAAM,cAAc,UAClB,OAAO,QACR,QAAQ,YACL;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,KAC7B,OAoEF,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { getDate } from "../date/getDate.js";
|
|
2
|
+
export const castToJsonType = (value, type, options = {}) => {
|
|
3
|
+
const { timezone = "UTC" } = options;
|
|
4
|
+
try {
|
|
5
|
+
if (value === undefined) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
if (value === null) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
if (type === "object") {
|
|
12
|
+
if (typeof value === "object") {
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
return JSON.parse(value);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (type === "array") {
|
|
23
|
+
if (Array.isArray(value)) {
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
const parsedValue = JSON.parse(value);
|
|
28
|
+
if (Array.isArray(parsedValue) === false) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
return parsedValue;
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (type === "string") {
|
|
38
|
+
return String(value);
|
|
39
|
+
}
|
|
40
|
+
if (type === "boolean") {
|
|
41
|
+
return Boolean(value);
|
|
42
|
+
}
|
|
43
|
+
if (type === "number") {
|
|
44
|
+
const number = Number(value);
|
|
45
|
+
if (isNaN(number)) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
return number;
|
|
49
|
+
}
|
|
50
|
+
if (type === "date") {
|
|
51
|
+
return getDate(value, { timezone });
|
|
52
|
+
}
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cleanJson.d.ts","sourceRoot":"","sources":["../../../src/json/cleanJson.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,YAAY,CAAC;AAIzC,eAAO,MAAM,SAAS,eAAgB,MAAM,SAAS,OAAO,KAAG,OAuB9D,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { getEntries } from "../collection.js";
|
|
2
|
+
export const cleanJson = (jsonSchema, value) => {
|
|
3
|
+
if (jsonSchema.type === "object" &&
|
|
4
|
+
jsonSchema.properties !== undefined &&
|
|
5
|
+
typeof value === "object" &&
|
|
6
|
+
value !== null) {
|
|
7
|
+
return getEntries(jsonSchema.properties).reduce((out, [key, subJsonSchema]) => {
|
|
8
|
+
if (key in value) {
|
|
9
|
+
return {
|
|
10
|
+
...out,
|
|
11
|
+
[key]: cleanJson(subJsonSchema, value[key]),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
return out;
|
|
15
|
+
}, {});
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
18
|
+
};
|