@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 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/json/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,eAAO,MAAM,SAAS,EAAE,QAAQ,EAQ/B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getJsonType.d.ts","sourceRoot":"","sources":["../../../src/json/getJsonType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,eAAO,MAAM,WAAW,WAElB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,OAAO,MAAM,EAAE,OAAO,CAAC,GACvB,OAAO,EAAE,KACZ,QA8BF,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export const getJsonType = (value) => {
|
|
2
|
+
if (value === null || value === undefined) {
|
|
3
|
+
return "any";
|
|
4
|
+
}
|
|
5
|
+
if (Array.isArray(value) === true) {
|
|
6
|
+
return "array";
|
|
7
|
+
}
|
|
8
|
+
if (value instanceof Date) {
|
|
9
|
+
return "date";
|
|
10
|
+
}
|
|
11
|
+
if (typeof value === "object") {
|
|
12
|
+
return "object";
|
|
13
|
+
}
|
|
14
|
+
if (value === true || value === false) {
|
|
15
|
+
return "boolean";
|
|
16
|
+
}
|
|
17
|
+
if (typeof value === "number") {
|
|
18
|
+
return "number";
|
|
19
|
+
}
|
|
20
|
+
if (typeof value === "string") {
|
|
21
|
+
return "string";
|
|
22
|
+
}
|
|
23
|
+
return "any";
|
|
24
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./castToJsonType.js";
|
|
2
|
+
export * from "./constants.js";
|
|
3
|
+
export * from "./getJsonType.js";
|
|
4
|
+
export * from "./isJson.js";
|
|
5
|
+
export * from "./isJsonSchemaEmpty.js";
|
|
6
|
+
export * from "./stringifyJson.js";
|
|
7
|
+
export * from "./types.js";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/json/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isJson.d.ts","sourceRoot":"","sources":["../../../src/json/isJson.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM,UAAW,MAAM,KAAG,OAQtC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isJsonSchemaEmpty.d.ts","sourceRoot":"","sources":["../../../src/json/isJsonSchemaEmpty.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAIzC,eAAO,MAAM,iBAAiB,eAAgB,MAAM,KAAG,OAOtD,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { getKeys } from "../collection.js";
|
|
2
|
+
export const isJsonSchemaEmpty = (jsonSchema) => {
|
|
3
|
+
return (jsonSchema.type === "object" &&
|
|
4
|
+
jsonSchema.additionalProperties !== true &&
|
|
5
|
+
(jsonSchema.properties === undefined ||
|
|
6
|
+
getKeys(jsonSchema.properties).length === 0));
|
|
7
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stringifyJson.d.ts","sourceRoot":"","sources":["../../../src/json/stringifyJson.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,UAAW,OAAO,KAAG,MAM9C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/json/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAChB,QAAQ,GACR,QAAQ,GACR,QAAQ,GACR,OAAO,GACP,MAAM,GACN,SAAS,GACT,KAAK,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Schema } from "jsonschema";
|
|
2
|
+
export type { Schema as JsonSchema } from "jsonschema";
|
|
3
|
+
export type JsonType = "string" | "number" | "object" | "array" | "date" | "boolean" | "any";
|
|
4
|
+
export declare const jsonTypes: JsonType[];
|
|
5
|
+
export declare const isJson: (value: string) => boolean;
|
|
6
|
+
export declare const getJsonType: (value?: string | number | boolean | Date | Record<string, unknown> | unknown[]) => JsonType;
|
|
7
|
+
export declare const castToJsonType: (value: unknown, type: JsonType, options?: {
|
|
8
|
+
timezone?: string;
|
|
9
|
+
}) => unknown;
|
|
10
|
+
export declare const stringifyJson: (value: unknown) => string;
|
|
11
|
+
export declare const isJsonSchemaEmpty: (jsonSchema: Schema) => boolean;
|
|
12
|
+
export declare const cleanJson: (jsonSchema: Schema, value: unknown) => unknown;
|
|
13
|
+
//# sourceMappingURL=json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,YAAY,CAAC;AAKzC,YAAY,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,YAAY,CAAC;AAEvD,MAAM,MAAM,QAAQ,GAChB,QAAQ,GACR,QAAQ,GACR,QAAQ,GACR,OAAO,GACP,MAAM,GACN,SAAS,GACT,KAAK,CAAC;AAEV,eAAO,MAAM,SAAS,EAAE,QAAQ,EAQ/B,CAAC;AAEF,eAAO,MAAM,MAAM,UAAW,MAAM,KAAG,OAQtC,CAAC;AAEF,eAAO,MAAM,WAAW,WAElB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,OAAO,MAAM,EAAE,OAAO,CAAC,GACvB,OAAO,EAAE,KACZ,QA8BF,CAAC;AAEF,eAAO,MAAM,cAAc,UAClB,OAAO,QACR,QAAQ,YACL;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,KAC7B,OA0CF,CAAC;AAEF,eAAO,MAAM,aAAa,UAAW,OAAO,KAAG,MAM9C,CAAC;AAEF,eAAO,MAAM,iBAAiB,eAAgB,MAAM,KAAG,OAOtD,CAAC;AAEF,eAAO,MAAM,SAAS,eAAgB,MAAM,SAAS,OAAO,KAAG,OAuB9D,CAAC"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { getEntries, getKeys } from "./collection.js";
|
|
2
|
+
import { getDate } from "./date/getDate.js";
|
|
3
|
+
export const jsonTypes = [
|
|
4
|
+
"string",
|
|
5
|
+
"number",
|
|
6
|
+
"object",
|
|
7
|
+
"array",
|
|
8
|
+
"date",
|
|
9
|
+
"boolean",
|
|
10
|
+
"any",
|
|
11
|
+
];
|
|
12
|
+
export const isJson = (value) => {
|
|
13
|
+
try {
|
|
14
|
+
JSON.parse(value);
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
export const getJsonType = (value) => {
|
|
22
|
+
if (value === null || value === undefined) {
|
|
23
|
+
return "any";
|
|
24
|
+
}
|
|
25
|
+
if (Array.isArray(value) === true) {
|
|
26
|
+
return "array";
|
|
27
|
+
}
|
|
28
|
+
if (value instanceof Date) {
|
|
29
|
+
return "date";
|
|
30
|
+
}
|
|
31
|
+
if (typeof value === "object") {
|
|
32
|
+
return "object";
|
|
33
|
+
}
|
|
34
|
+
if (value === true || value === false) {
|
|
35
|
+
return "boolean";
|
|
36
|
+
}
|
|
37
|
+
if (typeof value === "number") {
|
|
38
|
+
return "number";
|
|
39
|
+
}
|
|
40
|
+
if (typeof value === "string") {
|
|
41
|
+
return "string";
|
|
42
|
+
}
|
|
43
|
+
return "any";
|
|
44
|
+
};
|
|
45
|
+
export const castToJsonType = (value, type, options = {}) => {
|
|
46
|
+
const { timezone = "UTC" } = options;
|
|
47
|
+
try {
|
|
48
|
+
if (value === undefined) {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
if (value === null) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
if (type === "array") {
|
|
55
|
+
return Array.isArray(value) ? value : null;
|
|
56
|
+
}
|
|
57
|
+
if (type === "string") {
|
|
58
|
+
return String(value);
|
|
59
|
+
}
|
|
60
|
+
if (type === "boolean") {
|
|
61
|
+
return Boolean(value);
|
|
62
|
+
}
|
|
63
|
+
if (type === "number") {
|
|
64
|
+
const number = Number(value);
|
|
65
|
+
if (isNaN(number)) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
return number;
|
|
69
|
+
}
|
|
70
|
+
if (type === "date") {
|
|
71
|
+
return getDate(value, { timezone });
|
|
72
|
+
}
|
|
73
|
+
return value;
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
export const stringifyJson = (value) => {
|
|
80
|
+
if (typeof value === "string") {
|
|
81
|
+
return value;
|
|
82
|
+
}
|
|
83
|
+
return JSON.stringify(value);
|
|
84
|
+
};
|
|
85
|
+
export const isJsonSchemaEmpty = (jsonSchema) => {
|
|
86
|
+
return (jsonSchema.type === "object" &&
|
|
87
|
+
jsonSchema.additionalProperties !== true &&
|
|
88
|
+
(jsonSchema.properties === undefined ||
|
|
89
|
+
getKeys(jsonSchema.properties).length === 0));
|
|
90
|
+
};
|
|
91
|
+
export const cleanJson = (jsonSchema, value) => {
|
|
92
|
+
if (jsonSchema.type === "object" &&
|
|
93
|
+
jsonSchema.properties !== undefined &&
|
|
94
|
+
typeof value === "object" &&
|
|
95
|
+
value !== null) {
|
|
96
|
+
return getEntries(jsonSchema.properties).reduce((out, [key, subJsonSchema]) => {
|
|
97
|
+
if (key in value) {
|
|
98
|
+
return {
|
|
99
|
+
...out,
|
|
100
|
+
[key]: cleanJson(subJsonSchema, value[key]),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
return out;
|
|
104
|
+
}, {});
|
|
105
|
+
}
|
|
106
|
+
return value;
|
|
107
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Schema as JsonSchema } from "jsonschema";
|
|
2
|
+
export { JsonSchema };
|
|
3
|
+
export declare const getJsonSchemaFromPath: (schema: JsonSchema, path: string[]) => JsonSchema | undefined;
|
|
4
|
+
export declare const derivePartialJsonSchema: (schema: JsonSchema, paths: string[][]) => JsonSchema;
|
|
5
|
+
export declare const setJsonSchemaMetaFromPath: (schema: JsonSchema, path: string[], meta: {
|
|
6
|
+
title?: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
}) => JsonSchema;
|
|
9
|
+
export declare const cleanDataFromJsonSchema: (jsonSchema: JsonSchema, data: unknown | null) => unknown;
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/jsonSchema/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,YAAY,CAAC;AAIvD,OAAO,EAAE,UAAU,EAAE,CAAC;AAEtB,eAAO,MAAM,qBAAqB,WACxB,UAAU,QACZ,MAAM,EAAE,KACb,UAAU,GAAG,SAiCf,CAAC;AAEF,eAAO,MAAM,uBAAuB,WAC1B,UAAU,SACX,MAAM,EAAE,EAAE,KAChB,UAqHF,CAAC;AAEF,eAAO,MAAM,yBAAyB,WAC5B,UAAU,QACZ,MAAM,EAAE,QACR;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,KAC7C,UAwFF,CAAC;AAEF,eAAO,MAAM,uBAAuB,eACtB,UAAU,QAChB,OAAO,GAAG,IAAI,KACnB,OAuBF,CAAC"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { getEntries, getKeys } from "../collection.js";
|
|
2
|
+
export const getJsonSchemaFromPath = (schema, path) => {
|
|
3
|
+
const [head, ...nested] = path;
|
|
4
|
+
if (head === undefined) {
|
|
5
|
+
return schema;
|
|
6
|
+
}
|
|
7
|
+
if (schema.type === "array" && schema.items !== undefined) {
|
|
8
|
+
if (Array.isArray(schema.items) === true) {
|
|
9
|
+
const index = Number(head);
|
|
10
|
+
const item = schema.items[index];
|
|
11
|
+
if (item === undefined) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
return getJsonSchemaFromPath(item, nested);
|
|
15
|
+
}
|
|
16
|
+
return getJsonSchemaFromPath(schema.items, nested);
|
|
17
|
+
}
|
|
18
|
+
if (schema.type === "object" && schema.properties !== undefined) {
|
|
19
|
+
const property = schema.properties[head];
|
|
20
|
+
if (property === undefined) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
return getJsonSchemaFromPath(property, nested);
|
|
24
|
+
}
|
|
25
|
+
return undefined;
|
|
26
|
+
};
|
|
27
|
+
export const derivePartialJsonSchema = (schema, paths) => {
|
|
28
|
+
if (paths.length === 0) {
|
|
29
|
+
return { type: "object", properties: {}, additionalProperties: false };
|
|
30
|
+
}
|
|
31
|
+
const groupedPaths = paths.reduce((acc, [head, ...nested]) => {
|
|
32
|
+
if (head === undefined) {
|
|
33
|
+
return acc;
|
|
34
|
+
}
|
|
35
|
+
const currentPaths = acc[head];
|
|
36
|
+
if (currentPaths === undefined) {
|
|
37
|
+
return { ...acc, [head]: [nested] };
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
...acc,
|
|
41
|
+
[head]: [...currentPaths, nested],
|
|
42
|
+
};
|
|
43
|
+
}, {});
|
|
44
|
+
if (schema.type === "object" && schema.properties !== undefined) {
|
|
45
|
+
const newProperties = getEntries(groupedPaths).reduce((acc, [head, nestedPaths]) => {
|
|
46
|
+
if (schema.properties === undefined) {
|
|
47
|
+
return acc;
|
|
48
|
+
}
|
|
49
|
+
const subSchema = schema.properties[head];
|
|
50
|
+
if (subSchema === undefined) {
|
|
51
|
+
return acc;
|
|
52
|
+
}
|
|
53
|
+
const hasEmptyPath = nestedPaths.some((path) => path.length === 0);
|
|
54
|
+
if (hasEmptyPath === true) {
|
|
55
|
+
return { ...acc, [head]: subSchema };
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
...acc,
|
|
59
|
+
[head]: derivePartialJsonSchema(subSchema, nestedPaths),
|
|
60
|
+
};
|
|
61
|
+
}, {});
|
|
62
|
+
return { type: "object", properties: newProperties };
|
|
63
|
+
}
|
|
64
|
+
if (schema.type === "array" && schema.items !== undefined) {
|
|
65
|
+
const items = Array.isArray(schema.items) === true ? schema.items : [schema.items];
|
|
66
|
+
const defaultItem = items.at(-1);
|
|
67
|
+
if (defaultItem === undefined) {
|
|
68
|
+
return {
|
|
69
|
+
type: "array",
|
|
70
|
+
items: [],
|
|
71
|
+
additionalItems: false,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const indices = getKeys(groupedPaths).map(Number);
|
|
75
|
+
const itemsLength = Math.max(...indices.map((index) => index + 1), items.length);
|
|
76
|
+
return {
|
|
77
|
+
type: "array",
|
|
78
|
+
items: Array.from({ length: itemsLength }, (_, i) => {
|
|
79
|
+
if (indices.includes(i) === false) {
|
|
80
|
+
return {
|
|
81
|
+
type: "object",
|
|
82
|
+
properties: {},
|
|
83
|
+
additionalProperties: false,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const item = items[i] !== undefined ? items[i] : defaultItem;
|
|
87
|
+
if (item === undefined) {
|
|
88
|
+
return {
|
|
89
|
+
type: "object",
|
|
90
|
+
properties: {},
|
|
91
|
+
additionalProperties: false,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
const nestedPaths = groupedPaths[i];
|
|
95
|
+
if (nestedPaths === undefined) {
|
|
96
|
+
return {
|
|
97
|
+
type: "object",
|
|
98
|
+
properties: {},
|
|
99
|
+
additionalProperties: false,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
const hasEmptyPath = nestedPaths.some((path) => path.length === 0);
|
|
103
|
+
if (hasEmptyPath === true) {
|
|
104
|
+
return { ...item };
|
|
105
|
+
}
|
|
106
|
+
return derivePartialJsonSchema(item, nestedPaths);
|
|
107
|
+
}),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
return schema;
|
|
111
|
+
};
|
|
112
|
+
export const setJsonSchemaMetaFromPath = (schema, path, meta) => {
|
|
113
|
+
const [head, ...nested] = path;
|
|
114
|
+
if (head === undefined) {
|
|
115
|
+
return {
|
|
116
|
+
...schema,
|
|
117
|
+
title: meta.title,
|
|
118
|
+
description: meta.description,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
if (schema.type === "array" && schema.items !== undefined) {
|
|
122
|
+
const index = Number(head);
|
|
123
|
+
if (Array.isArray(schema.items) === true) {
|
|
124
|
+
const { items } = schema;
|
|
125
|
+
const defaultItem = items.at(-1);
|
|
126
|
+
if (defaultItem === undefined) {
|
|
127
|
+
return schema;
|
|
128
|
+
}
|
|
129
|
+
const itemsLength = Math.max(index + 1, items.length);
|
|
130
|
+
return {
|
|
131
|
+
...schema,
|
|
132
|
+
items: Array.from({ length: itemsLength }, (_, i) => {
|
|
133
|
+
const item = items[i] !== undefined ? items[i] : defaultItem;
|
|
134
|
+
if (item === undefined) {
|
|
135
|
+
return {
|
|
136
|
+
type: "object",
|
|
137
|
+
properties: {},
|
|
138
|
+
additionalProperties: false,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
if (i === index) {
|
|
142
|
+
return setJsonSchemaMetaFromPath(item, nested, meta);
|
|
143
|
+
}
|
|
144
|
+
return { ...item };
|
|
145
|
+
}),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
const { items: item } = schema;
|
|
149
|
+
if (index === 0) {
|
|
150
|
+
const updatedItems = setJsonSchemaMetaFromPath(item, nested, meta);
|
|
151
|
+
return {
|
|
152
|
+
...schema,
|
|
153
|
+
items: updatedItems,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
...schema,
|
|
158
|
+
items: Array.from({ length: index + 1 }, (_, i) => {
|
|
159
|
+
if (i === index) {
|
|
160
|
+
return setJsonSchemaMetaFromPath(item, nested, meta);
|
|
161
|
+
}
|
|
162
|
+
return { ...item };
|
|
163
|
+
}),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
if (schema.type === "object" && schema.properties !== undefined) {
|
|
167
|
+
const property = schema.properties[head];
|
|
168
|
+
if (property === undefined) {
|
|
169
|
+
return schema;
|
|
170
|
+
}
|
|
171
|
+
const updatedProperty = setJsonSchemaMetaFromPath(property, nested, meta);
|
|
172
|
+
return {
|
|
173
|
+
...schema,
|
|
174
|
+
properties: {
|
|
175
|
+
...schema.properties,
|
|
176
|
+
[head]: updatedProperty,
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
return schema;
|
|
181
|
+
};
|
|
182
|
+
export const cleanDataFromJsonSchema = (jsonSchema, data) => {
|
|
183
|
+
if (jsonSchema.type === "object" &&
|
|
184
|
+
jsonSchema.properties !== undefined &&
|
|
185
|
+
typeof data === "object" &&
|
|
186
|
+
data !== null) {
|
|
187
|
+
return getEntries(jsonSchema.properties).reduce((out, [key, subJsonSchema]) => {
|
|
188
|
+
if (key in data) {
|
|
189
|
+
return {
|
|
190
|
+
...out,
|
|
191
|
+
[key]: cleanDataFromJsonSchema(subJsonSchema, data[key]),
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
return out;
|
|
195
|
+
}, {});
|
|
196
|
+
}
|
|
197
|
+
return data;
|
|
198
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Schema as JsonSchema } from "jsonschema";
|
|
2
|
+
export { JsonSchema };
|
|
3
|
+
export declare const getJsonSchemaFromPath: (schema: JsonSchema, path: string[]) => JsonSchema | undefined;
|
|
4
|
+
export declare const derivePartialJsonSchema: (schema: JsonSchema, paths: string[][]) => JsonSchema;
|
|
5
|
+
//# sourceMappingURL=jsonSchema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonSchema.d.ts","sourceRoot":"","sources":["../../src/jsonSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,YAAY,CAAC;AAIvD,OAAO,EAAE,UAAU,EAAE,CAAC;AAEtB,eAAO,MAAM,qBAAqB,WACxB,UAAU,QACZ,MAAM,EAAE,KACb,UAAU,GAAG,SA4Bf,CAAC;AAEF,eAAO,MAAM,uBAAuB,WAC1B,UAAU,SACX,MAAM,EAAE,EAAE,KAChB,UAuEF,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { getEntries, getValues } from "./collection.js";
|
|
2
|
+
export const getJsonSchemaFromPath = (schema, path) => {
|
|
3
|
+
const [head, ...nested] = path;
|
|
4
|
+
if (head === undefined) {
|
|
5
|
+
return schema;
|
|
6
|
+
}
|
|
7
|
+
if (schema.type === "array" && schema.items !== undefined) {
|
|
8
|
+
const items = Array.isArray(schema.items) ? schema.items[0] : schema.items;
|
|
9
|
+
if (items === undefined) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
return getJsonSchemaFromPath(items, nested);
|
|
13
|
+
}
|
|
14
|
+
if (schema.type === "object" && schema.properties !== undefined) {
|
|
15
|
+
const property = schema.properties[head];
|
|
16
|
+
if (property === undefined) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
return getJsonSchemaFromPath(property, nested);
|
|
20
|
+
}
|
|
21
|
+
return undefined;
|
|
22
|
+
};
|
|
23
|
+
export const derivePartialJsonSchema = (schema, paths) => {
|
|
24
|
+
if (paths.length === 0) {
|
|
25
|
+
return { type: "object", properties: {} };
|
|
26
|
+
}
|
|
27
|
+
const groupedPaths = paths.reduce((acc, [head, ...nested]) => {
|
|
28
|
+
if (head === undefined) {
|
|
29
|
+
return acc;
|
|
30
|
+
}
|
|
31
|
+
const currentPaths = acc[head];
|
|
32
|
+
if (currentPaths === undefined) {
|
|
33
|
+
return { ...acc, [head]: [nested] };
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
...acc,
|
|
37
|
+
[head]: [...currentPaths, nested],
|
|
38
|
+
};
|
|
39
|
+
}, {});
|
|
40
|
+
if (schema.type === "object" && schema.properties !== undefined) {
|
|
41
|
+
const newProperties = getEntries(groupedPaths).reduce((acc, [head, nestedPaths]) => {
|
|
42
|
+
const subSchema = schema.properties?.[head];
|
|
43
|
+
if (subSchema === undefined) {
|
|
44
|
+
return acc;
|
|
45
|
+
}
|
|
46
|
+
const hasEmptyPath = nestedPaths.some((path) => path.length === 0);
|
|
47
|
+
if (hasEmptyPath === true) {
|
|
48
|
+
return { ...acc, [head]: subSchema };
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
...acc,
|
|
52
|
+
[head]: derivePartialJsonSchema(subSchema, nestedPaths),
|
|
53
|
+
};
|
|
54
|
+
}, {});
|
|
55
|
+
return { type: "object", properties: newProperties };
|
|
56
|
+
}
|
|
57
|
+
if (schema.type === "array" && schema.items !== undefined) {
|
|
58
|
+
const items = Array.isArray(schema.items) ? schema.items[0] : schema.items;
|
|
59
|
+
if (items === undefined) {
|
|
60
|
+
return schema;
|
|
61
|
+
}
|
|
62
|
+
const allNestedPaths = getValues(groupedPaths).flat();
|
|
63
|
+
const hasEmptyPath = allNestedPaths.some((path) => path.length === 0);
|
|
64
|
+
if (hasEmptyPath === true) {
|
|
65
|
+
return schema;
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
type: "array",
|
|
69
|
+
items: derivePartialJsonSchema(items, allNestedPaths),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return schema;
|
|
73
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatCredits.d.ts","sourceRoot":"","sources":["../../../src/number/formatCredits.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,YAAa,MAAM,KAAG,MAM/C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatPrice.d.ts","sourceRoot":"","sources":["../../../src/number/formatPrice.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,UAAW,MAAM,KAAG,MAO3C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getNumberWithMaxDecimals.d.ts","sourceRoot":"","sources":["../../../src/number/getNumberWithMaxDecimals.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wBAAwB,WAC3B,MAAM,eACD,MAAM,KAClB,MAEF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/number/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,+BAA+B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"poll.d.ts","sourceRoot":"","sources":["../../src/poll.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,cAAc,OACrB,MAAM,QAAQ,OAAO,CAAC;gBAKZ,MAAM;cACR,MAAM;MAEjB,QAAQ,OAAO,CA6BjB,CAAC"}
|