@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.
Files changed (251) hide show
  1. package/build/array.js +52 -0
  2. package/build/collection.js +155 -0
  3. package/build/components.js +56 -0
  4. package/build/cron.js +19 -0
  5. package/build/delay.js +52 -0
  6. package/build/hooks/index.js +35 -0
  7. package/build/hooks/useClickOutside.js +46 -0
  8. package/build/hooks/useCountAnimation.js +34 -0
  9. package/build/hooks/useDeviceType.js +54 -0
  10. package/build/hooks/useEventListener.js +27 -0
  11. package/build/hooks/useHeight.js +26 -0
  12. package/build/hooks/usePictureInPicture.js +126 -0
  13. package/build/hooks/useResizeObserver.js +35 -0
  14. package/build/hooks/useScrollPosition.js +22 -0
  15. package/build/hooks/useStepper.js +138 -0
  16. package/build/hooks/useStorageState.js +110 -0
  17. package/build/hooks/useVideoPlayer/VideoManager.js +78 -0
  18. package/build/hooks/useVideoPlayer/index.js +5 -0
  19. package/build/hooks/useVideoPlayer/useVideoPlayer.js +100 -0
  20. package/build/hooks/useWillUnmountEffect.js +13 -0
  21. package/build/index.js +28 -0
  22. package/build/json.js +81 -0
  23. package/build/random.js +7 -0
  24. package/build/src/array.d.ts +16 -0
  25. package/build/src/array.d.ts.map +1 -0
  26. package/build/src/array.js +81 -0
  27. package/build/src/base64.d.ts +3 -0
  28. package/build/src/base64.d.ts.map +1 -0
  29. package/build/src/base64.js +6 -0
  30. package/build/src/bytes.d.ts +7 -0
  31. package/build/src/bytes.d.ts.map +1 -0
  32. package/build/src/bytes.js +71 -0
  33. package/build/src/collection/deepMergeObjects.d.ts +2 -0
  34. package/build/src/collection/deepMergeObjects.d.ts.map +1 -0
  35. package/build/src/collection/deepMergeObjects.js +30 -0
  36. package/build/src/collection/index.d.ts +2 -0
  37. package/build/src/collection/index.d.ts.map +1 -0
  38. package/build/src/collection/index.js +1 -0
  39. package/build/src/collection.d.ts +22 -0
  40. package/build/src/collection.d.ts.map +1 -0
  41. package/build/src/collection.js +210 -0
  42. package/build/src/colors.d.ts +2 -0
  43. package/build/src/colors.d.ts.map +1 -0
  44. package/build/src/colors.js +14 -0
  45. package/build/src/components.d.ts +4 -0
  46. package/build/src/components.js +45 -0
  47. package/build/src/credits.d.ts +7 -0
  48. package/build/src/credits.d.ts.map +1 -0
  49. package/build/src/credits.js +88 -0
  50. package/build/src/cron.d.ts +3 -0
  51. package/build/src/cron.d.ts.map +1 -0
  52. package/build/src/cron.js +16 -0
  53. package/build/src/date/getContextTimezone.d.ts +2 -0
  54. package/build/src/date/getContextTimezone.d.ts.map +1 -0
  55. package/build/src/date/getContextTimezone.js +3 -0
  56. package/build/src/date/getDate.d.ts +8 -0
  57. package/build/src/date/getDate.d.ts.map +1 -0
  58. package/build/src/date/getDate.js +25 -0
  59. package/build/src/date/getDateString.d.ts +8 -0
  60. package/build/src/date/getDateString.d.ts.map +1 -0
  61. package/build/src/date/getDateString.js +13 -0
  62. package/build/src/date/getDatesDifferenceString.d.ts +2 -0
  63. package/build/src/date/getDatesDifferenceString.d.ts.map +1 -0
  64. package/build/src/date/getDatesDifferenceString.js +17 -0
  65. package/build/src/date/getTimeFromNowString.d.ts +2 -0
  66. package/build/src/date/getTimeFromNowString.d.ts.map +1 -0
  67. package/build/src/date/getTimeFromNowString.js +8 -0
  68. package/build/src/date/getTimezoneHoursOffset.d.ts +2 -0
  69. package/build/src/date/getTimezoneHoursOffset.d.ts.map +1 -0
  70. package/build/src/date/getTimezoneHoursOffset.js +7 -0
  71. package/build/src/date/getTimezoneOffsetString.d.ts +2 -0
  72. package/build/src/date/getTimezoneOffsetString.d.ts.map +1 -0
  73. package/build/src/date/getTimezoneOffsetString.js +8 -0
  74. package/build/src/date/index.d.ts +8 -0
  75. package/build/src/date/index.d.ts.map +1 -0
  76. package/build/src/date/index.js +7 -0
  77. package/build/src/date.d.ts +13 -0
  78. package/build/src/date.d.ts.map +1 -0
  79. package/build/src/date.js +14 -0
  80. package/build/src/delay.d.ts +7 -0
  81. package/build/src/delay.d.ts.map +1 -0
  82. package/build/src/delay.js +19 -0
  83. package/build/src/expression/getExpressionNodesReferences.d.ts +17 -0
  84. package/build/src/expression/getExpressionNodesReferences.d.ts.map +1 -0
  85. package/build/src/expression/getExpressionNodesReferences.js +71 -0
  86. package/build/src/expression/getObjectAccessKeysBeforeCursor.d.ts +17 -0
  87. package/build/src/expression/getObjectAccessKeysBeforeCursor.d.ts.map +1 -0
  88. package/build/src/expression/getObjectAccessKeysBeforeCursor.js +97 -0
  89. package/build/src/expression/index.d.ts +3 -0
  90. package/build/src/expression/index.d.ts.map +1 -0
  91. package/build/src/expression/index.js +2 -0
  92. package/build/src/expression/jsonSchema.d.ts +4 -0
  93. package/build/src/expression/jsonSchema.d.ts.map +1 -0
  94. package/build/src/expression/jsonSchema.js +85 -0
  95. package/build/src/expression/matchIsExpression.d.ts +2 -0
  96. package/build/src/expression/matchIsExpression.d.ts.map +1 -0
  97. package/build/src/expression/matchIsExpression.js +10 -0
  98. package/build/src/expression/matchIsExpressionObject.d.ts +2 -0
  99. package/build/src/expression/matchIsExpressionObject.d.ts.map +1 -0
  100. package/build/src/expression/matchIsExpressionObject.js +10 -0
  101. package/build/src/expression/matchIsExpressionString.d.ts +2 -0
  102. package/build/src/expression/matchIsExpressionString.d.ts.map +1 -0
  103. package/build/src/expression/matchIsExpressionString.js +4 -0
  104. package/build/src/gclid.d.ts +4 -0
  105. package/build/src/gclid.d.ts.map +1 -0
  106. package/build/src/gclid.js +30 -0
  107. package/build/src/hooks/index.d.ts +12 -0
  108. package/build/src/hooks/index.js +12 -0
  109. package/build/src/hooks/useClickOutside.d.ts +4 -0
  110. package/build/src/hooks/useClickOutside.js +42 -0
  111. package/build/src/hooks/useCountAnimation.d.ts +1 -0
  112. package/build/src/hooks/useCountAnimation.js +30 -0
  113. package/build/src/hooks/useDeviceType.d.ts +2 -0
  114. package/build/src/hooks/useDeviceType.js +50 -0
  115. package/build/src/hooks/useEventListener.d.ts +6 -0
  116. package/build/src/hooks/useEventListener.js +23 -0
  117. package/build/src/hooks/useHeight.d.ts +2 -0
  118. package/build/src/hooks/useHeight.js +20 -0
  119. package/build/src/hooks/usePictureInPicture.d.ts +9 -0
  120. package/build/src/hooks/usePictureInPicture.js +60 -0
  121. package/build/src/hooks/useResizeObserver.d.ts +4 -0
  122. package/build/src/hooks/useResizeObserver.js +31 -0
  123. package/build/src/hooks/useScrollPosition.d.ts +5 -0
  124. package/build/src/hooks/useScrollPosition.js +18 -0
  125. package/build/src/hooks/useStepper.d.ts +26 -0
  126. package/build/src/hooks/useStepper.js +136 -0
  127. package/build/src/hooks/useStorageState.d.ts +12 -0
  128. package/build/src/hooks/useStorageState.js +53 -0
  129. package/build/src/hooks/useVideoPlayer/VideoManager.d.ts +18 -0
  130. package/build/src/hooks/useVideoPlayer/VideoManager.js +72 -0
  131. package/build/src/hooks/useVideoPlayer/index.d.ts +1 -0
  132. package/build/src/hooks/useVideoPlayer/index.js +1 -0
  133. package/build/src/hooks/useVideoPlayer/useVideoPlayer.d.ts +15 -0
  134. package/build/src/hooks/useVideoPlayer/useVideoPlayer.js +96 -0
  135. package/build/src/hooks/useWillUnmountEffect.d.ts +1 -0
  136. package/build/src/hooks/useWillUnmountEffect.js +8 -0
  137. package/build/src/index.d.ts +27 -0
  138. package/build/src/index.d.ts.map +1 -0
  139. package/build/src/index.js +26 -0
  140. package/build/src/integration.d.ts +14 -0
  141. package/build/src/integration.d.ts.map +1 -0
  142. package/build/src/integration.js +72 -0
  143. package/build/src/json/castToJsonType.d.ts +5 -0
  144. package/build/src/json/castToJsonType.d.ts.map +1 -0
  145. package/build/src/json/castToJsonType.js +58 -0
  146. package/build/src/json/cleanJson.d.ts +3 -0
  147. package/build/src/json/cleanJson.d.ts.map +1 -0
  148. package/build/src/json/cleanJson.js +18 -0
  149. package/build/src/json/constants.d.ts +3 -0
  150. package/build/src/json/constants.d.ts.map +1 -0
  151. package/build/src/json/constants.js +9 -0
  152. package/build/src/json/getJsonType.d.ts +3 -0
  153. package/build/src/json/getJsonType.d.ts.map +1 -0
  154. package/build/src/json/getJsonType.js +24 -0
  155. package/build/src/json/index.d.ts +8 -0
  156. package/build/src/json/index.d.ts.map +1 -0
  157. package/build/src/json/index.js +7 -0
  158. package/build/src/json/isJson.d.ts +2 -0
  159. package/build/src/json/isJson.d.ts.map +1 -0
  160. package/build/src/json/isJson.js +9 -0
  161. package/build/src/json/isJsonSchemaEmpty.d.ts +3 -0
  162. package/build/src/json/isJsonSchemaEmpty.d.ts.map +1 -0
  163. package/build/src/json/isJsonSchemaEmpty.js +7 -0
  164. package/build/src/json/stringifyJson.d.ts +2 -0
  165. package/build/src/json/stringifyJson.d.ts.map +1 -0
  166. package/build/src/json/stringifyJson.js +6 -0
  167. package/build/src/json/types.d.ts +2 -0
  168. package/build/src/json/types.d.ts.map +1 -0
  169. package/build/src/json/types.js +1 -0
  170. package/build/src/json.d.ts +13 -0
  171. package/build/src/json.d.ts.map +1 -0
  172. package/build/src/json.js +107 -0
  173. package/build/src/jsonSchema/index.d.ts +10 -0
  174. package/build/src/jsonSchema/index.d.ts.map +1 -0
  175. package/build/src/jsonSchema/index.js +198 -0
  176. package/build/src/jsonSchema.d.ts +5 -0
  177. package/build/src/jsonSchema.d.ts.map +1 -0
  178. package/build/src/jsonSchema.js +73 -0
  179. package/build/src/number/formatCredits.d.ts +2 -0
  180. package/build/src/number/formatCredits.d.ts.map +1 -0
  181. package/build/src/number/formatCredits.js +7 -0
  182. package/build/src/number/formatPrice.d.ts +2 -0
  183. package/build/src/number/formatPrice.d.ts.map +1 -0
  184. package/build/src/number/formatPrice.js +8 -0
  185. package/build/src/number/getNumberWithMaxDecimals.d.ts +2 -0
  186. package/build/src/number/getNumberWithMaxDecimals.d.ts.map +1 -0
  187. package/build/src/number/getNumberWithMaxDecimals.js +3 -0
  188. package/build/src/number/index.d.ts +4 -0
  189. package/build/src/number/index.d.ts.map +1 -0
  190. package/build/src/number/index.js +3 -0
  191. package/build/src/poll.d.ts +5 -0
  192. package/build/src/poll.d.ts.map +1 -0
  193. package/build/src/poll.js +30 -0
  194. package/build/src/random.d.ts +2 -0
  195. package/build/src/random.d.ts.map +1 -0
  196. package/build/src/random.js +3 -0
  197. package/build/src/schema.d.ts +24 -0
  198. package/build/src/schema.d.ts.map +1 -0
  199. package/build/src/schema.js +315 -0
  200. package/build/src/searchInTree.d.ts +46 -0
  201. package/build/src/searchInTree.d.ts.map +1 -0
  202. package/build/src/searchInTree.js +67 -0
  203. package/build/src/storage.d.ts +13 -0
  204. package/build/src/storage.d.ts.map +1 -0
  205. package/build/src/storage.js +169 -0
  206. package/build/src/string/capitalizeFirstLetter.d.ts +2 -0
  207. package/build/src/string/capitalizeFirstLetter.d.ts.map +1 -0
  208. package/build/src/string/capitalizeFirstLetter.js +3 -0
  209. package/build/src/string/findAllIndexOf.d.ts +2 -0
  210. package/build/src/string/findAllIndexOf.d.ts.map +1 -0
  211. package/build/src/string/findAllIndexOf.js +13 -0
  212. package/build/src/string/getHash.d.ts +2 -0
  213. package/build/src/string/getHash.d.ts.map +1 -0
  214. package/build/src/string/getHash.js +9 -0
  215. package/build/src/string/index.d.ts +5 -0
  216. package/build/src/string/index.d.ts.map +1 -0
  217. package/build/src/string/index.js +4 -0
  218. package/build/src/string/sentenceCase.d.ts +2 -0
  219. package/build/src/string/sentenceCase.d.ts.map +1 -0
  220. package/build/src/string/sentenceCase.js +38 -0
  221. package/build/src/string.d.ts +2 -0
  222. package/build/src/string.d.ts.map +1 -0
  223. package/build/src/string.js +3 -0
  224. package/build/src/type.d.ts +10 -0
  225. package/build/src/type.js +1 -0
  226. package/build/src/types.d.ts +22 -0
  227. package/build/src/types.d.ts.map +1 -0
  228. package/build/src/types.js +1 -0
  229. package/build/src/user.d.ts +3 -0
  230. package/build/src/user.d.ts.map +1 -0
  231. package/build/src/user.js +7 -0
  232. package/build/src/validation/index.d.ts +2 -0
  233. package/build/src/validation/index.d.ts.map +1 -0
  234. package/build/src/validation/index.js +1 -0
  235. package/build/src/validation/matchIsObjectLike.d.ts +2 -0
  236. package/build/src/validation/matchIsObjectLike.d.ts.map +1 -0
  237. package/build/src/validation/matchIsObjectLike.js +4 -0
  238. package/build/src/vm.d.ts +1 -0
  239. package/build/src/vm.js +32 -0
  240. package/build/src/zod/index.d.ts +14 -0
  241. package/build/src/zod/index.d.ts.map +1 -0
  242. package/build/src/zod/index.js +210 -0
  243. package/build/src/zod.d.ts +8 -0
  244. package/build/src/zod.d.ts.map +1 -0
  245. package/build/src/zod.js +89 -0
  246. package/build/storage.js +285 -0
  247. package/build/string.js +17 -0
  248. package/build/tsconfig.tsbuildinfo +1 -0
  249. package/build/type.js +2 -0
  250. package/build/user.js +12 -0
  251. package/package.json +50 -0
@@ -0,0 +1,3 @@
1
+ import type { JsonType } from "./types.js";
2
+ export declare const jsonTypes: JsonType[];
3
+ //# sourceMappingURL=constants.d.ts.map
@@ -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,9 @@
1
+ export const jsonTypes = [
2
+ "string",
3
+ "number",
4
+ "object",
5
+ "array",
6
+ "date",
7
+ "boolean",
8
+ "any",
9
+ ];
@@ -0,0 +1,3 @@
1
+ import type { JsonType } from "./types.js";
2
+ export declare const getJsonType: (value?: string | number | boolean | Date | Record<string, unknown> | unknown[]) => JsonType;
3
+ //# sourceMappingURL=getJsonType.d.ts.map
@@ -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,7 @@
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";
@@ -0,0 +1,2 @@
1
+ export declare const isJson: (value: string) => boolean;
2
+ //# sourceMappingURL=isJson.d.ts.map
@@ -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,9 @@
1
+ export const isJson = (value) => {
2
+ try {
3
+ JSON.parse(value);
4
+ return true;
5
+ }
6
+ catch {
7
+ return false;
8
+ }
9
+ };
@@ -0,0 +1,3 @@
1
+ import type { Schema } from "jsonschema";
2
+ export declare const isJsonSchemaEmpty: (jsonSchema: Schema) => boolean;
3
+ //# sourceMappingURL=isJsonSchemaEmpty.d.ts.map
@@ -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,2 @@
1
+ export declare const stringifyJson: (value: unknown) => string;
2
+ //# sourceMappingURL=stringifyJson.d.ts.map
@@ -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,6 @@
1
+ export const stringifyJson = (value) => {
2
+ if (typeof value === "string") {
3
+ return value;
4
+ }
5
+ return JSON.stringify(value);
6
+ };
@@ -0,0 +1,2 @@
1
+ export type JsonType = "string" | "number" | "object" | "array" | "date" | "boolean" | "any";
2
+ //# sourceMappingURL=types.d.ts.map
@@ -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,2 @@
1
+ export declare const formatCredits: (credits: number) => string;
2
+ //# sourceMappingURL=formatCredits.d.ts.map
@@ -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,7 @@
1
+ export const formatCredits = (credits) => {
2
+ return new Intl.NumberFormat("en-EN", {
3
+ style: "decimal",
4
+ minimumFractionDigits: 0,
5
+ maximumFractionDigits: 2,
6
+ }).format(credits);
7
+ };
@@ -0,0 +1,2 @@
1
+ export declare const formatPrice: (price: number) => string;
2
+ //# sourceMappingURL=formatPrice.d.ts.map
@@ -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,8 @@
1
+ export const formatPrice = (price) => {
2
+ return new Intl.NumberFormat("en-EN", {
3
+ style: "currency",
4
+ currency: "USD",
5
+ minimumFractionDigits: 0,
6
+ maximumFractionDigits: 3,
7
+ }).format(price);
8
+ };
@@ -0,0 +1,2 @@
1
+ export declare const getNumberWithMaxDecimals: (number: number, maxDecimals: number) => number;
2
+ //# sourceMappingURL=getNumberWithMaxDecimals.d.ts.map
@@ -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,3 @@
1
+ export const getNumberWithMaxDecimals = (number, maxDecimals) => {
2
+ return parseFloat(number.toFixed(maxDecimals));
3
+ };
@@ -0,0 +1,4 @@
1
+ export * from "./formatCredits.js";
2
+ export * from "./formatPrice.js";
3
+ export * from "./getNumberWithMaxDecimals.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -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,3 @@
1
+ export * from "./formatCredits.js";
2
+ export * from "./formatPrice.js";
3
+ export * from "./getNumberWithMaxDecimals.js";
@@ -0,0 +1,5 @@
1
+ export declare const pollOnInterval: (fn: () => Promise<boolean>, { intervalMs, maxPolls, }: {
2
+ intervalMs: number;
3
+ maxPolls: number;
4
+ }) => Promise<boolean>;
5
+ //# sourceMappingURL=poll.d.ts.map
@@ -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"}