@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,88 @@
|
|
|
1
|
+
const ANNUAL_CREDITS_COSTS = [
|
|
2
|
+
{
|
|
3
|
+
rate: 0.25,
|
|
4
|
+
amount: 1_200,
|
|
5
|
+
fixedPrice: 0,
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
rate: 0.088,
|
|
9
|
+
amount: 30_000,
|
|
10
|
+
fixedPrice: 0.088 * 30_000,
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
rate: 0.0792,
|
|
14
|
+
amount: 66_000,
|
|
15
|
+
fixedPrice: 0.0792 * 66_000,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
rate: 0.0704,
|
|
19
|
+
amount: 120_000,
|
|
20
|
+
fixedPrice: 0.0704 * 120_000,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
rate: 0.0616,
|
|
24
|
+
amount: 204_000,
|
|
25
|
+
fixedPrice: 0.0616 * 204_000,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
rate: 0.0572,
|
|
29
|
+
amount: 276_000,
|
|
30
|
+
fixedPrice: 0.0572 * 276_000,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
rate: 0.0546,
|
|
34
|
+
amount: 480_000,
|
|
35
|
+
fixedPrice: 0.0546 * 480_000,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
rate: 0.0528,
|
|
39
|
+
amount: 600_000,
|
|
40
|
+
fixedPrice: 0.0528 * 600_000,
|
|
41
|
+
},
|
|
42
|
+
];
|
|
43
|
+
const MONTHLY_CREDITS_COSTS = [
|
|
44
|
+
{
|
|
45
|
+
rate: 0.25,
|
|
46
|
+
amount: 100,
|
|
47
|
+
fixedPrice: 0,
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
rate: 0.1,
|
|
51
|
+
amount: 2_500,
|
|
52
|
+
fixedPrice: 0.1 * 2_500,
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
rate: 0.09,
|
|
56
|
+
amount: 5_500,
|
|
57
|
+
fixedPrice: 0.09 * 5_500,
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
rate: 0.08,
|
|
61
|
+
amount: 10_000,
|
|
62
|
+
fixedPrice: 0.08 * 10_000,
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
rate: 0.07,
|
|
66
|
+
amount: 17_000,
|
|
67
|
+
fixedPrice: 0.07 * 17_000,
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
rate: 0.065,
|
|
71
|
+
amount: 23_000,
|
|
72
|
+
fixedPrice: 0.065 * 23_000,
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
rate: 0.062,
|
|
76
|
+
amount: 40_000,
|
|
77
|
+
fixedPrice: 0.062 * 40_000,
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
rate: 0.06,
|
|
81
|
+
amount: 50_000,
|
|
82
|
+
fixedPrice: 0.06 * 50_000,
|
|
83
|
+
},
|
|
84
|
+
];
|
|
85
|
+
export const CREDITS_COSTS = {
|
|
86
|
+
monthly: MONTHLY_CREDITS_COSTS,
|
|
87
|
+
annual: ANNUAL_CREDITS_COSTS,
|
|
88
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export type HumanizedCron = "Every 30 minutes" | "Every hour" | "Every 3 hours" | "Every 6 hours" | "Every 12 hours" | "Every day" | "Every 3 days" | "Every week" | "Every 2 weeks" | "Every 3 weeks";
|
|
2
|
+
export declare const humanizedCrons: Record<HumanizedCron, string>;
|
|
3
|
+
//# sourceMappingURL=cron.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cron.d.ts","sourceRoot":"","sources":["../../src/cron.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GACrB,kBAAkB,GAClB,YAAY,GACZ,eAAe,GACf,eAAe,GACf,gBAAgB,GAChB,WAAW,GACX,cAAc,GACd,YAAY,GACZ,eAAe,GACf,eAAe,CAAC;AAOpB,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,aAAa,EAAE,MAAM,CAWxD,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const every3daysCron = `@every ${3 * 24}h`;
|
|
2
|
+
const everyWeekCron = `@every ${7 * 24}h`;
|
|
3
|
+
const every2WeeksCron = `@every ${2 * 7 * 24}h`;
|
|
4
|
+
const every3WeeksCron = `@every ${3 * 7 * 24}h`;
|
|
5
|
+
export const humanizedCrons = {
|
|
6
|
+
"Every 30 minutes": "@every 30m",
|
|
7
|
+
"Every hour": "@every 1h",
|
|
8
|
+
"Every 3 hours": "@every 3h",
|
|
9
|
+
"Every 6 hours": "@every 6h",
|
|
10
|
+
"Every 12 hours": "@every 12h",
|
|
11
|
+
"Every day": "@every 24h",
|
|
12
|
+
"Every 3 days": every3daysCron,
|
|
13
|
+
"Every week": everyWeekCron,
|
|
14
|
+
"Every 2 weeks": every2WeeksCron,
|
|
15
|
+
"Every 3 weeks": every3WeeksCron,
|
|
16
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getContextTimezone.d.ts","sourceRoot":"","sources":["../../../src/date/getContextTimezone.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,QAAO,MAErC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDate.d.ts","sourceRoot":"","sources":["../../../src/date/getDate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAKtC,KAAK,OAAO,GAAG;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF,eAAO,MAAM,OAAO,eACN,IAAI,GAAG,MAAM,GAAG,MAAM,YACzB,OAAO,KACf,MAgCF,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { TZDate } from "@date-fns/tz";
|
|
2
|
+
import { addHours } from "date-fns";
|
|
3
|
+
import { getTimezoneHoursOffset } from "./getTimezoneHoursOffset.js";
|
|
4
|
+
export const getDate = (dateValue, options = {}) => {
|
|
5
|
+
const { timezone = "UTC", overrideTimezone = false } = options;
|
|
6
|
+
const getValueDate = () => {
|
|
7
|
+
if (dateValue === undefined) {
|
|
8
|
+
return new Date();
|
|
9
|
+
}
|
|
10
|
+
if (typeof dateValue === "string" || typeof dateValue === "number") {
|
|
11
|
+
return new Date(dateValue);
|
|
12
|
+
}
|
|
13
|
+
return dateValue;
|
|
14
|
+
};
|
|
15
|
+
const date = getValueDate();
|
|
16
|
+
const timezoneDate = new TZDate(date, timezone);
|
|
17
|
+
if (overrideTimezone === false) {
|
|
18
|
+
return timezoneDate;
|
|
19
|
+
}
|
|
20
|
+
const originalTimezoneMinutesOffset = -date.getTimezoneOffset();
|
|
21
|
+
const originalTimezoneHoursOffset = originalTimezoneMinutesOffset / 60;
|
|
22
|
+
const newTimezoneHoursOffset = getTimezoneHoursOffset(date, timezone);
|
|
23
|
+
const timezoneOffsetDifference = originalTimezoneHoursOffset - newTimezoneHoursOffset;
|
|
24
|
+
return new TZDate(addHours(timezoneDate, timezoneOffsetDifference), timezone);
|
|
25
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDateString.d.ts","sourceRoot":"","sources":["../../../src/date/getDateString.ts"],"names":[],"mappings":"AAKA,KAAK,OAAO,GAAG;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC,CAAC;AAEF,eAAO,MAAM,aAAa,cACb,IAAI,GAAG,MAAM,GAAG,MAAM,YACxB,OAAO,KACf,MAeF,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { format as getFormattedDate } from "date-fns";
|
|
2
|
+
import { getDate } from "./getDate.js";
|
|
3
|
+
import { getTimezoneOffsetString } from "./getTimezoneOffsetString.js";
|
|
4
|
+
export const getDateString = (dateValue, options = {}) => {
|
|
5
|
+
const { format, timezone = "UTC", hasTimezoneIndicator = false } = options;
|
|
6
|
+
const date = getDate(dateValue, { timezone });
|
|
7
|
+
const dateString = format === undefined ? date.toISOString() : getFormattedDate(date, format);
|
|
8
|
+
if (hasTimezoneIndicator === false) {
|
|
9
|
+
return dateString;
|
|
10
|
+
}
|
|
11
|
+
const timezoneOffsetString = getTimezoneOffsetString(date, timezone);
|
|
12
|
+
return `${dateString} (${timezoneOffsetString})`;
|
|
13
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDatesDifferenceString.d.ts","sourceRoot":"","sources":["../../../src/date/getDatesDifferenceString.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,wBAAwB,mBACnB,IAAI,GAAG,MAAM,GAAG,MAAM,gBACxB,IAAI,GAAG,MAAM,GAAG,MAAM,KACnC,MAoBF,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { formatDuration } from "date-fns";
|
|
2
|
+
import { intervalToDuration } from "date-fns";
|
|
3
|
+
import { getDate } from "./getDate.js";
|
|
4
|
+
export const getDatesDifferenceString = (startDateValue, endDateValue) => {
|
|
5
|
+
const startDate = typeof startDateValue === "string" || typeof startDateValue === "number"
|
|
6
|
+
? getDate(startDateValue)
|
|
7
|
+
: startDateValue;
|
|
8
|
+
const endDate = typeof endDateValue === "string" || typeof endDateValue === "number"
|
|
9
|
+
? getDate(endDateValue)
|
|
10
|
+
: endDateValue;
|
|
11
|
+
const duration = intervalToDuration({ start: startDate, end: endDate });
|
|
12
|
+
const formattedDuration = formatDuration(duration);
|
|
13
|
+
if (formattedDuration === "") {
|
|
14
|
+
return "0 seconds";
|
|
15
|
+
}
|
|
16
|
+
return formattedDuration;
|
|
17
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTimeFromNowString.d.ts","sourceRoot":"","sources":["../../../src/date/getTimeFromNowString.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,oBAAoB,cACpB,IAAI,GAAG,MAAM,GAAG,MAAM,KAChC,MAOF,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { formatDistanceToNow } from "date-fns";
|
|
2
|
+
import { getDate } from "./getDate.js";
|
|
3
|
+
export const getTimeFromNowString = (dateValue) => {
|
|
4
|
+
const date = typeof dateValue === "string" || typeof dateValue === "number"
|
|
5
|
+
? getDate(dateValue)
|
|
6
|
+
: dateValue;
|
|
7
|
+
return formatDistanceToNow(date, { addSuffix: true });
|
|
8
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTimezoneHoursOffset.d.ts","sourceRoot":"","sources":["../../../src/date/getTimezoneHoursOffset.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,sBAAsB,cACtB,IAAI,GAAG,MAAM,GAAG,MAAM,YACvB,MAAM,KACf,MAQF,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { getDate } from "./getDate.js";
|
|
2
|
+
export const getTimezoneHoursOffset = (dateValue, timezone) => {
|
|
3
|
+
const date = getDate(dateValue, { timezone });
|
|
4
|
+
const timezoneMinutesOffset = date.getTimezoneOffset();
|
|
5
|
+
const timezoneHoursOffset = timezoneMinutesOffset / 60;
|
|
6
|
+
return -timezoneHoursOffset;
|
|
7
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTimezoneOffsetString.d.ts","sourceRoot":"","sources":["../../../src/date/getTimezoneOffsetString.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,uBAAuB,cACvB,IAAI,GAAG,MAAM,GAAG,MAAM,YACvB,MAAM,KACf,MAQF,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { getTimezoneHoursOffset } from "./getTimezoneHoursOffset.js";
|
|
2
|
+
export const getTimezoneOffsetString = (dateValue, timezone) => {
|
|
3
|
+
const timezoneHoursOffset = getTimezoneHoursOffset(dateValue, timezone);
|
|
4
|
+
if (timezoneHoursOffset === 0) {
|
|
5
|
+
return "UTC";
|
|
6
|
+
}
|
|
7
|
+
return `UTC${timezoneHoursOffset > 0 ? "+" : ""}${timezoneHoursOffset}`;
|
|
8
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./getContextTimezone.js";
|
|
2
|
+
export * from "./getDate.js";
|
|
3
|
+
export * from "./getDatesDifferenceString.js";
|
|
4
|
+
export * from "./getDateString.js";
|
|
5
|
+
export * from "./getTimeFromNowString.js";
|
|
6
|
+
export * from "./getTimezoneHoursOffset.js";
|
|
7
|
+
export * from "./getTimezoneOffsetString.js";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/date/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,cAAc,CAAC;AAC7B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from "./getContextTimezone.js";
|
|
2
|
+
export * from "./getDate.js";
|
|
3
|
+
export * from "./getDatesDifferenceString.js";
|
|
4
|
+
export * from "./getDateString.js";
|
|
5
|
+
export * from "./getTimeFromNowString.js";
|
|
6
|
+
export * from "./getTimezoneHoursOffset.js";
|
|
7
|
+
export * from "./getTimezoneOffsetString.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalizes a Date object to an ISO 8601 date string (`YYYY-MM-DD`),
|
|
3
|
+
* compensating for the local timezone offset to ensure consistency in UTC.
|
|
4
|
+
*
|
|
5
|
+
* @param {Date} date - The date object to normalize.
|
|
6
|
+
* @returns {string} The normalized ISO date string (`YYYY-MM-DD`).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const date = new Date("2024-02-17T23:59:59");
|
|
10
|
+
* console.log(getUTCDateString(date)); // "2024-02-17" (adjusted for timezone)
|
|
11
|
+
*/
|
|
12
|
+
export declare function getUTCDateString(date: Date): string | undefined;
|
|
13
|
+
//# sourceMappingURL=date.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../src/date.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,SAAS,CAE/D"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalizes a Date object to an ISO 8601 date string (`YYYY-MM-DD`),
|
|
3
|
+
* compensating for the local timezone offset to ensure consistency in UTC.
|
|
4
|
+
*
|
|
5
|
+
* @param {Date} date - The date object to normalize.
|
|
6
|
+
* @returns {string} The normalized ISO date string (`YYYY-MM-DD`).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const date = new Date("2024-02-17T23:59:59");
|
|
10
|
+
* console.log(getUTCDateString(date)); // "2024-02-17" (adjusted for timezone)
|
|
11
|
+
*/
|
|
12
|
+
export function getUTCDateString(date) {
|
|
13
|
+
return date.toISOString().split("T")[0];
|
|
14
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const delay: (milliseconds: number) => Promise<void>;
|
|
2
|
+
export type HeartbeatOptions = {
|
|
3
|
+
heartbeatInterval?: number;
|
|
4
|
+
sendInitialHeartbeat?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export declare const delayWithHeartbeat: (milliseconds: number, heartbeat: () => void, options?: HeartbeatOptions) => Promise<void>;
|
|
7
|
+
//# sourceMappingURL=delay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delay.d.ts","sourceRoot":"","sources":["../../src/delay.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK,iBAAwB,MAAM,KAAG,QAAQ,IAAI,CAI9D,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC,CAAC;AAEF,eAAO,MAAM,kBAAkB,iBACf,MAAM,aACT,MAAM,IAAI,YACZ,gBAAgB,KACxB,QAAQ,IAAI,CAqBd,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const delay = async (milliseconds) => {
|
|
2
|
+
await new Promise((resolve) => setTimeout(() => resolve(), milliseconds));
|
|
3
|
+
};
|
|
4
|
+
export const delayWithHeartbeat = async (milliseconds, heartbeat, options = {}) => {
|
|
5
|
+
const { heartbeatInterval = 30000, sendInitialHeartbeat = true } = options;
|
|
6
|
+
const startTime = Date.now();
|
|
7
|
+
if (sendInitialHeartbeat === true) {
|
|
8
|
+
heartbeat();
|
|
9
|
+
}
|
|
10
|
+
while (Date.now() - startTime < milliseconds) {
|
|
11
|
+
const remainingTime = milliseconds - (Date.now() - startTime);
|
|
12
|
+
const waitTime = Math.min(heartbeatInterval, remainingTime);
|
|
13
|
+
if (waitTime <= 0) {
|
|
14
|
+
break;
|
|
15
|
+
}
|
|
16
|
+
await new Promise((resolve) => setTimeout(resolve, waitTime));
|
|
17
|
+
heartbeat();
|
|
18
|
+
}
|
|
19
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
type Reference = {
|
|
2
|
+
index: number;
|
|
3
|
+
full: string;
|
|
4
|
+
parent: string;
|
|
5
|
+
slug: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const EXPRESSION_REFERENCE_PARENT_KEYS: string[];
|
|
8
|
+
export declare function getExpressionNodesReferences(expressionValue: string): Reference[];
|
|
9
|
+
type DoubleBracketGroup = {
|
|
10
|
+
before: string;
|
|
11
|
+
group: string;
|
|
12
|
+
after: string;
|
|
13
|
+
};
|
|
14
|
+
export declare function getDoubleBracketGroupsInString(value: string): DoubleBracketGroup[] | undefined;
|
|
15
|
+
export declare function getDoubleBracketGroupNodesReferences(doubleBracketGroup: string): Reference[];
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=getExpressionNodesReferences.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getExpressionNodesReferences.d.ts","sourceRoot":"","sources":["../../../src/expression/getExpressionNodesReferences.ts"],"names":[],"mappings":"AAAA,KAAK,SAAS,GAAG;IACf,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,eAAO,MAAM,gCAAgC,UAK5C,CAAC;AAEF,wBAAgB,4BAA4B,CAC1C,eAAe,EAAE,MAAM,GACtB,SAAS,EAAE,CA8Bb;AAED,KAAK,kBAAkB,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,wBAAgB,8BAA8B,CAC5C,KAAK,EAAE,MAAM,GACZ,kBAAkB,EAAE,GAAG,SAAS,CAyBlC;AAED,wBAAgB,oCAAoC,CAClD,kBAAkB,EAAE,MAAM,GACzB,SAAS,EAAE,CAkCb"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export const EXPRESSION_REFERENCE_PARENT_KEYS = [
|
|
2
|
+
"nodes",
|
|
3
|
+
"parentNodes",
|
|
4
|
+
"tools",
|
|
5
|
+
"resources",
|
|
6
|
+
];
|
|
7
|
+
export function getExpressionNodesReferences(expressionValue) {
|
|
8
|
+
const doubleBracketGroups = getDoubleBracketGroupsInString(expressionValue);
|
|
9
|
+
if (doubleBracketGroups === undefined) {
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
const references = [];
|
|
13
|
+
let currentExpressionValueIndex = 0;
|
|
14
|
+
doubleBracketGroups.forEach((group) => {
|
|
15
|
+
currentExpressionValueIndex =
|
|
16
|
+
currentExpressionValueIndex + group.before.length;
|
|
17
|
+
const doubleBracketGroupNodesReferences = getDoubleBracketGroupNodesReferences(group.group);
|
|
18
|
+
doubleBracketGroupNodesReferences.forEach((reference) => {
|
|
19
|
+
references.push({
|
|
20
|
+
...reference,
|
|
21
|
+
index: currentExpressionValueIndex + reference.index,
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
currentExpressionValueIndex =
|
|
25
|
+
currentExpressionValueIndex + group.group.length;
|
|
26
|
+
});
|
|
27
|
+
return references;
|
|
28
|
+
}
|
|
29
|
+
export function getDoubleBracketGroupsInString(value) {
|
|
30
|
+
const openDoubleBracketsIndex = value.indexOf("{{");
|
|
31
|
+
const closeDoubleBracketsIndex = value.indexOf("}}");
|
|
32
|
+
if (openDoubleBracketsIndex === -1 ||
|
|
33
|
+
closeDoubleBracketsIndex === -1 ||
|
|
34
|
+
openDoubleBracketsIndex > closeDoubleBracketsIndex) {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
const group = {
|
|
38
|
+
before: value.slice(0, openDoubleBracketsIndex),
|
|
39
|
+
group: value.slice(openDoubleBracketsIndex, closeDoubleBracketsIndex + 2),
|
|
40
|
+
after: value.slice(closeDoubleBracketsIndex + 2),
|
|
41
|
+
};
|
|
42
|
+
const afterGroups = getDoubleBracketGroupsInString(group.after);
|
|
43
|
+
if (afterGroups === undefined) {
|
|
44
|
+
return [group];
|
|
45
|
+
}
|
|
46
|
+
return [group, ...afterGroups];
|
|
47
|
+
}
|
|
48
|
+
export function getDoubleBracketGroupNodesReferences(doubleBracketGroup) {
|
|
49
|
+
const matches = Array.from(doubleBracketGroup.matchAll(/(nodes|parentNodes|tools|resources)((\?)?\.([a-zA-Z0-9_$]+)|(\?\.)?\[("|')([a-zA-Z0-9_$]+)("|')\])((\?)?\.([a-zA-Z0-9_$ ]*[a-zA-Z0-9_$])|(\?\.)?\[("|')([a-zA-Z0-9_$ ]*[a-zA-Z0-9_$])("|')\])*/g));
|
|
50
|
+
const references = [];
|
|
51
|
+
for (const match of matches) {
|
|
52
|
+
if (match === null || match.index === undefined) {
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
const isDotPropertyAccess = match[4] !== undefined;
|
|
56
|
+
const index = match.index;
|
|
57
|
+
const full = match[0];
|
|
58
|
+
const parent = match[1];
|
|
59
|
+
const slug = isDotPropertyAccess === true ? match[4] : match[7];
|
|
60
|
+
if (parent !== undefined && slug !== undefined) {
|
|
61
|
+
const reference = {
|
|
62
|
+
index,
|
|
63
|
+
full,
|
|
64
|
+
parent,
|
|
65
|
+
slug,
|
|
66
|
+
};
|
|
67
|
+
references.push(reference);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return references;
|
|
71
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { NodePath } from "@babel/traverse";
|
|
2
|
+
import _traverse from "@babel/traverse";
|
|
3
|
+
export declare const traverse: {
|
|
4
|
+
<S>(parent: _traverse.Node, opts: _traverse.TraverseOptions<S>, scope: _traverse.Scope | undefined, state: S, parentPath?: NodePath<_traverse.Node> | undefined): void;
|
|
5
|
+
(parent: _traverse.Node, opts?: _traverse.TraverseOptions<_traverse.Node> | undefined, scope?: _traverse.Scope | undefined, state?: any, parentPath?: NodePath<_traverse.Node> | undefined): void;
|
|
6
|
+
visitors: typeof _traverse.visitors;
|
|
7
|
+
verify: typeof _traverse.visitors.verify;
|
|
8
|
+
explode: typeof _traverse.visitors.explode;
|
|
9
|
+
cheap: (node: _traverse.Node, enter: (node: _traverse.Node) => void) => void;
|
|
10
|
+
node: (node: _traverse.Node, opts: _traverse.TraverseOptions<_traverse.Node>, scope?: _traverse.Scope | undefined, state?: any, path?: NodePath<_traverse.Node> | undefined, skipKeys?: Record<string, boolean> | undefined) => void;
|
|
11
|
+
clearNode: (node: _traverse.Node, opts?: _traverse.RemovePropertiesOptions | undefined) => void;
|
|
12
|
+
removeProperties: (tree: _traverse.Node, opts?: _traverse.RemovePropertiesOptions | undefined) => _traverse.Node;
|
|
13
|
+
hasType: (tree: _traverse.Node, type: "File" | "MemberExpression" | "OptionalMemberExpression" | "AnyTypeAnnotation" | "ArgumentPlaceholder" | "ArrayExpression" | "ArrayPattern" | "ArrayTypeAnnotation" | "ArrowFunctionExpression" | "AssignmentExpression" | "AssignmentPattern" | "AwaitExpression" | "BigIntLiteral" | "BinaryExpression" | "BindExpression" | "BlockStatement" | "BooleanLiteral" | "BooleanLiteralTypeAnnotation" | "BooleanTypeAnnotation" | "BreakStatement" | "CallExpression" | "CatchClause" | "ClassAccessorProperty" | "ClassBody" | "ClassDeclaration" | "ClassExpression" | "ClassImplements" | "ClassMethod" | "ClassPrivateMethod" | "ClassPrivateProperty" | "ClassProperty" | "ConditionalExpression" | "ContinueStatement" | "DebuggerStatement" | "DecimalLiteral" | "DeclareClass" | "DeclareExportAllDeclaration" | "DeclareExportDeclaration" | "DeclareFunction" | "DeclareInterface" | "DeclareModule" | "DeclareModuleExports" | "DeclareOpaqueType" | "DeclareTypeAlias" | "DeclareVariable" | "DeclaredPredicate" | "Decorator" | "Directive" | "DirectiveLiteral" | "DoExpression" | "DoWhileStatement" | "EmptyStatement" | "EmptyTypeAnnotation" | "EnumBooleanBody" | "EnumBooleanMember" | "EnumDeclaration" | "EnumDefaultedMember" | "EnumNumberBody" | "EnumNumberMember" | "EnumStringBody" | "EnumStringMember" | "EnumSymbolBody" | "ExistsTypeAnnotation" | "ExportAllDeclaration" | "ExportDefaultDeclaration" | "ExportDefaultSpecifier" | "ExportNamedDeclaration" | "ExportNamespaceSpecifier" | "ExportSpecifier" | "ExpressionStatement" | "ForInStatement" | "ForOfStatement" | "ForStatement" | "FunctionDeclaration" | "FunctionExpression" | "FunctionTypeAnnotation" | "FunctionTypeParam" | "GenericTypeAnnotation" | "Identifier" | "IfStatement" | "Import" | "ImportAttribute" | "ImportDeclaration" | "ImportDefaultSpecifier" | "ImportExpression" | "ImportNamespaceSpecifier" | "ImportSpecifier" | "IndexedAccessType" | "InferredPredicate" | "InterfaceDeclaration" | "InterfaceExtends" | "InterfaceTypeAnnotation" | "InterpreterDirective" | "IntersectionTypeAnnotation" | "JSXAttribute" | "JSXClosingElement" | "JSXClosingFragment" | "JSXElement" | "JSXEmptyExpression" | "JSXExpressionContainer" | "JSXFragment" | "JSXIdentifier" | "JSXMemberExpression" | "JSXNamespacedName" | "JSXOpeningElement" | "JSXOpeningFragment" | "JSXSpreadAttribute" | "JSXSpreadChild" | "JSXText" | "LabeledStatement" | "LogicalExpression" | "MetaProperty" | "MixedTypeAnnotation" | "ModuleExpression" | "NewExpression" | "Noop" | "NullLiteral" | "NullLiteralTypeAnnotation" | "NullableTypeAnnotation" | "NumberLiteral" | "NumberLiteralTypeAnnotation" | "NumberTypeAnnotation" | "NumericLiteral" | "ObjectExpression" | "ObjectMethod" | "ObjectPattern" | "ObjectProperty" | "ObjectTypeAnnotation" | "ObjectTypeCallProperty" | "ObjectTypeIndexer" | "ObjectTypeInternalSlot" | "ObjectTypeProperty" | "ObjectTypeSpreadProperty" | "OpaqueType" | "OptionalCallExpression" | "OptionalIndexedAccessType" | "ParenthesizedExpression" | "PipelineBareFunction" | "PipelinePrimaryTopicReference" | "PipelineTopicExpression" | "Placeholder" | "PrivateName" | "Program" | "QualifiedTypeIdentifier" | "RecordExpression" | "RegExpLiteral" | "RegexLiteral" | "RestElement" | "RestProperty" | "ReturnStatement" | "SequenceExpression" | "SpreadElement" | "SpreadProperty" | "StaticBlock" | "StringLiteral" | "StringLiteralTypeAnnotation" | "StringTypeAnnotation" | "Super" | "SwitchCase" | "SwitchStatement" | "SymbolTypeAnnotation" | "TSAnyKeyword" | "TSArrayType" | "TSAsExpression" | "TSBigIntKeyword" | "TSBooleanKeyword" | "TSCallSignatureDeclaration" | "TSConditionalType" | "TSConstructSignatureDeclaration" | "TSConstructorType" | "TSDeclareFunction" | "TSDeclareMethod" | "TSEnumBody" | "TSEnumDeclaration" | "TSEnumMember" | "TSExportAssignment" | "TSExpressionWithTypeArguments" | "TSExternalModuleReference" | "TSFunctionType" | "TSImportEqualsDeclaration" | "TSImportType" | "TSIndexSignature" | "TSIndexedAccessType" | "TSInferType" | "TSInstantiationExpression" | "TSInterfaceBody" | "TSInterfaceDeclaration" | "TSIntersectionType" | "TSIntrinsicKeyword" | "TSLiteralType" | "TSMappedType" | "TSMethodSignature" | "TSModuleBlock" | "TSModuleDeclaration" | "TSNamedTupleMember" | "TSNamespaceExportDeclaration" | "TSNeverKeyword" | "TSNonNullExpression" | "TSNullKeyword" | "TSNumberKeyword" | "TSObjectKeyword" | "TSOptionalType" | "TSParameterProperty" | "TSParenthesizedType" | "TSPropertySignature" | "TSQualifiedName" | "TSRestType" | "TSSatisfiesExpression" | "TSStringKeyword" | "TSSymbolKeyword" | "TSTemplateLiteralType" | "TSThisType" | "TSTupleType" | "TSTypeAliasDeclaration" | "TSTypeAnnotation" | "TSTypeAssertion" | "TSTypeLiteral" | "TSTypeOperator" | "TSTypeParameter" | "TSTypeParameterDeclaration" | "TSTypeParameterInstantiation" | "TSTypePredicate" | "TSTypeQuery" | "TSTypeReference" | "TSUndefinedKeyword" | "TSUnionType" | "TSUnknownKeyword" | "TSVoidKeyword" | "TaggedTemplateExpression" | "TemplateElement" | "TemplateLiteral" | "ThisExpression" | "ThisTypeAnnotation" | "ThrowStatement" | "TopicReference" | "TryStatement" | "TupleExpression" | "TupleTypeAnnotation" | "TypeAlias" | "TypeAnnotation" | "TypeCastExpression" | "TypeParameter" | "TypeParameterDeclaration" | "TypeParameterInstantiation" | "TypeofTypeAnnotation" | "UnaryExpression" | "UnionTypeAnnotation" | "UpdateExpression" | "V8IntrinsicIdentifier" | "VariableDeclaration" | "VariableDeclarator" | "Variance" | "VoidPattern" | "VoidTypeAnnotation" | "WhileStatement" | "WithStatement" | "YieldExpression", denylistTypes?: string[] | undefined) => boolean;
|
|
14
|
+
cache: typeof _traverse.cache;
|
|
15
|
+
};
|
|
16
|
+
export declare const getObjectAccessKeysBeforeCursor: (code: string, cursorPositionIndex: number) => string[];
|
|
17
|
+
//# sourceMappingURL=getObjectAccessKeysBeforeCursor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getObjectAccessKeysBeforeCursor.d.ts","sourceRoot":"","sources":["../../../src/expression/getObjectAccessKeysBeforeCursor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,SAAS,MAAM,iBAAiB,CAAC;AAIxC,eAAO,MAAM,QAAQ;;;;;;;;;;;;CAC4C,CAAC;AAIlE,eAAO,MAAM,+BAA+B,SACpC,MAAM,uBACS,MAAM,KAC1B,MAAM,EAmGR,CAAC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import * as parser from "@babel/parser";
|
|
2
|
+
import _traverse from "@babel/traverse";
|
|
3
|
+
// This casting allows to use the function everywhere (Next.js app, Backend, Vite libraries)
|
|
4
|
+
export const traverse = typeof _traverse === "function" ? _traverse : _traverse.default;
|
|
5
|
+
const DUMMY_PROPERTY = "__CARGO_DUMMY_PROPERTY__";
|
|
6
|
+
export const getObjectAccessKeysBeforeCursor = (code, cursorPositionIndex) => {
|
|
7
|
+
// We need to try catch because the parser.parse can throw an error if the code is not valid
|
|
8
|
+
try {
|
|
9
|
+
// Get the part of the code we want to parse
|
|
10
|
+
const objectAccess = getObjectAccessCodeBeforeCursor(code, cursorPositionIndex);
|
|
11
|
+
if (objectAccess === undefined) {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
// Since we also want to support code with a trailing dot which is not valid syntax
|
|
15
|
+
// we add a dummy property while parsing the AST which we then ignore
|
|
16
|
+
const needsDummyProperty = objectAccess.code.slice(-1) === ".";
|
|
17
|
+
const codeWithDummyProperty = needsDummyProperty === true
|
|
18
|
+
? `${objectAccess.code}${DUMMY_PROPERTY}`
|
|
19
|
+
: objectAccess.code;
|
|
20
|
+
const ast = parser.parse(codeWithDummyProperty, {
|
|
21
|
+
sourceType: "module",
|
|
22
|
+
errorRecovery: true,
|
|
23
|
+
});
|
|
24
|
+
let keys = [];
|
|
25
|
+
const handleMemberExpression = (path) => {
|
|
26
|
+
const { end } = path.node;
|
|
27
|
+
if (end === undefined || end === null) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const readjustedEnd = needsDummyProperty === true ? end - DUMMY_PROPERTY.length : end;
|
|
31
|
+
// We are only interested in full member expression right before the cursor position
|
|
32
|
+
if (objectAccess.cursorPositionIndex !== readjustedEnd) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
keys = [];
|
|
36
|
+
let current = path.node;
|
|
37
|
+
// Traverse the chain of MemberExpressions to extract keys
|
|
38
|
+
while (current) {
|
|
39
|
+
if (current.property) {
|
|
40
|
+
if (current.property.type === "Identifier") {
|
|
41
|
+
keys.unshift(current.property.name); // e.g., `someField`
|
|
42
|
+
}
|
|
43
|
+
else if (current.property.type === "StringLiteral") {
|
|
44
|
+
keys.unshift(current.property.value); // e.g., `"some field"`
|
|
45
|
+
}
|
|
46
|
+
else if (current.property.type === "NumericLiteral") {
|
|
47
|
+
keys.unshift(String(current.property.value)); // e.g., `0`
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (current.object &&
|
|
51
|
+
(current.object.type === "MemberExpression" ||
|
|
52
|
+
current.object.type === "OptionalMemberExpression")) {
|
|
53
|
+
current = current.object; // Continue traversing the chain
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (current.object && current.object.type === "Identifier") {
|
|
57
|
+
keys.unshift(current.object.name); // e.g., `nodes`
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
// Traverse the AST to find the MemberExpression at the cursor position
|
|
64
|
+
traverse(ast, {
|
|
65
|
+
MemberExpression(path) {
|
|
66
|
+
handleMemberExpression(path);
|
|
67
|
+
},
|
|
68
|
+
OptionalMemberExpression(path) {
|
|
69
|
+
handleMemberExpression(path);
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
if (needsDummyProperty === true) {
|
|
73
|
+
return keys.filter((key) => {
|
|
74
|
+
// Filter out the dummy property if it was added
|
|
75
|
+
return key !== DUMMY_PROPERTY;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return keys;
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return [];
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const OBJECT_ACCESS_REGEX = /(([a-zA-Z0-9_$]+)|(\?\.)?\[("|')?([a-zA-Z0-9_$]+)("|')?\])((\?)?\.([a-zA-Z0-9_$ ]*[a-zA-Z0-9_$])|(\?\.)?\[("|')?([a-zA-Z0-9_$ ]*[a-zA-Z0-9_$])("|')?\])*(\??\.?)?$/;
|
|
85
|
+
const getObjectAccessCodeBeforeCursor = (code, cursorPositionIndex) => {
|
|
86
|
+
const match = code.slice(0, cursorPositionIndex).match(OBJECT_ACCESS_REGEX);
|
|
87
|
+
if (match === null) {
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
const objectAccessCode = match[0];
|
|
91
|
+
const objectAccessCodeOriginalIndex = code.lastIndexOf(objectAccessCode);
|
|
92
|
+
const objectAccessCursorPositionIndex = cursorPositionIndex - objectAccessCodeOriginalIndex;
|
|
93
|
+
return {
|
|
94
|
+
code: objectAccessCode,
|
|
95
|
+
cursorPositionIndex: objectAccessCursorPositionIndex,
|
|
96
|
+
};
|
|
97
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/expression/index.ts"],"names":[],"mappings":"AAAA,cAAc,mCAAmC,CAAC;AAClD,cAAc,sCAAsC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonSchema.d.ts","sourceRoot":"","sources":["../../../src/expression/jsonSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,eAAO,MAAM,oBAAoB,EAAE,UAqDlC,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,UAAU,CAAC,aAAa,CA8B3D,CAAC"}
|