@cognite/underscore 1.0.1 → 1.48535.0

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 (95) hide show
  1. package/README.md +2 -0
  2. package/dist/arrays.d.ts +31 -31
  3. package/dist/arrays.js +53 -18
  4. package/dist/arrays.js.map +1 -0
  5. package/dist/assert.d.ts +6 -6
  6. package/dist/assert.js +12 -5
  7. package/dist/assert.js.map +1 -0
  8. package/dist/brand.d.ts +41 -38
  9. package/dist/brand.js +39 -0
  10. package/dist/brand.js.map +1 -0
  11. package/dist/chunk-and-process-in-parallel.d.ts +112 -106
  12. package/dist/chunk-and-process-in-parallel.js +138 -29
  13. package/dist/chunk-and-process-in-parallel.js.map +1 -0
  14. package/dist/chunk-array.d.ts +25 -25
  15. package/dist/chunk-array.js +34 -6
  16. package/dist/chunk-array.js.map +1 -0
  17. package/dist/class.d.ts +8 -8
  18. package/dist/class.js +11 -5
  19. package/dist/class.js.map +1 -0
  20. package/dist/exhaustive-guard.d.ts +15 -15
  21. package/dist/exhaustive-guard.js +19 -5
  22. package/dist/exhaustive-guard.js.map +1 -0
  23. package/dist/exponential-backoff-with-jitter.d.ts +13 -13
  24. package/dist/exponential-backoff-with-jitter.js +23 -7
  25. package/dist/exponential-backoff-with-jitter.js.map +1 -0
  26. package/dist/generate-unique-name.d.ts +17 -17
  27. package/dist/generate-unique-name.js +46 -10
  28. package/dist/generate-unique-name.js.map +1 -0
  29. package/dist/get-numbers-between.d.ts +15 -15
  30. package/dist/get-numbers-between.js +21 -5
  31. package/dist/get-numbers-between.js.map +1 -0
  32. package/dist/humanize-value.d.ts +3 -3
  33. package/dist/humanize-value.js +33 -15
  34. package/dist/humanize-value.js.map +1 -0
  35. package/dist/index.d.ts +23 -23
  36. package/dist/index.js +23 -23
  37. package/dist/index.js.map +1 -0
  38. package/dist/is-function.d.ts +5 -5
  39. package/dist/is-function.js +9 -5
  40. package/dist/is-function.js.map +1 -0
  41. package/dist/is-primitive.d.ts +7 -7
  42. package/dist/is-primitive.js +16 -6
  43. package/dist/is-primitive.js.map +1 -0
  44. package/dist/is-valid-url.d.ts +11 -14
  45. package/dist/is-valid-url.js +39 -16
  46. package/dist/is-valid-url.js.map +1 -0
  47. package/dist/iterators.d.ts +7 -7
  48. package/dist/iterators.js +16 -6
  49. package/dist/iterators.js.map +1 -0
  50. package/dist/math.d.ts +10 -10
  51. package/dist/math.js +16 -7
  52. package/dist/math.js.map +1 -0
  53. package/dist/random.d.ts +24 -24
  54. package/dist/random.js +52 -18
  55. package/dist/random.js.map +1 -0
  56. package/dist/react/use-debounce.d.ts +21 -21
  57. package/dist/react/use-debounce.js +39 -14
  58. package/dist/react/use-debounce.js.map +1 -0
  59. package/dist/react/use-derived-promise.d.ts +28 -29
  60. package/dist/react/use-derived-promise.js +70 -33
  61. package/dist/react/use-derived-promise.js.map +1 -0
  62. package/dist/react/use-stable-sync-external-store.d.ts +25 -25
  63. package/dist/react/use-stable-sync-external-store.js +52 -11
  64. package/dist/react/use-stable-sync-external-store.js.map +1 -0
  65. package/dist/react.d.ts +3 -3
  66. package/dist/react.js +5 -4
  67. package/dist/react.js.map +1 -0
  68. package/dist/repeat.d.ts +5 -5
  69. package/dist/repeat.js +11 -5
  70. package/dist/repeat.js.map +1 -0
  71. package/dist/retry-async.d.ts +87 -87
  72. package/dist/retry-async.js +88 -17
  73. package/dist/retry-async.js.map +1 -0
  74. package/dist/sleep.d.ts +5 -5
  75. package/dist/sleep.js +9 -5
  76. package/dist/sleep.js.map +1 -0
  77. package/dist/string.d.ts +35 -35
  78. package/dist/string.js +48 -9
  79. package/dist/string.js.map +1 -0
  80. package/dist/structMap/index.d.ts +3 -3
  81. package/dist/structMap/index.js +4 -0
  82. package/dist/structMap/index.js.map +1 -0
  83. package/dist/structMap/stableStringify.d.ts +21 -21
  84. package/dist/structMap/stableStringify.js +69 -22
  85. package/dist/structMap/stableStringify.js.map +1 -0
  86. package/dist/structMap/structMap.d.ts +111 -108
  87. package/dist/structMap/structMap.js +131 -28
  88. package/dist/structMap/structMap.js.map +1 -0
  89. package/dist/structMap/testUtils.d.ts +8 -8
  90. package/dist/structMap/testUtils.js +26 -0
  91. package/dist/structMap/testUtils.js.map +1 -0
  92. package/dist/structMap/types.d.ts +4 -4
  93. package/dist/structMap/types.js +5 -0
  94. package/dist/structMap/types.js.map +1 -0
  95. package/package.json +7 -4
@@ -1,92 +1,92 @@
1
1
  /**
2
- * Retries an operation a configurable number of times.
3
- *
4
- * The flow is as follows:
5
- * 1. Call the `operation` function.
6
- * 2. If it resolves, return the resolved value.
7
- * 3. If it throws an error, check if we should retry (based on `maxAttempts` and `shouldRetry`).
8
- * 4. If we should retry, calculate the delay using `delayInMsCalculator`, call `onAttemptFail`, wait for that duration, and then repeat from step 1.
9
- * 5. If we shouldn't retry (either because we've exhausted attempts or `shouldRetry` returned false), re-throw the error.
10
- *
11
- * By default, we use exponential backoff with jitter for delays between attempts.
12
- *
13
- * @param operation The function to execute and retry.
14
- * @param config Configuration for the retry mechanism.
15
- * @returns A Promise that resolves with the result of the successful operation.
16
- * @throws Will throw if, and only if, all retry attempts failed. Only the last exception from `operation` will be re-thrown.
17
- *
18
- * @example
19
- * ```ts
20
- * // Basic usage: retry a function that may fail
21
- * await retryAsync(() => {
22
- * if (Math.random() < 0.7) throw new Error('Transient error');
23
- * return 'success';
24
- * });
25
- * ```
26
- *
27
- * * @example
28
- * ```ts
29
- * try {
30
- * return retryAsync(() => fetchAllUsers());
31
- * } catch (err) {
32
- * console.error('Failed to fetch users after several attempts:', err);
33
- * notifyUser('Failed to fetch users. Please try again later.');
34
- * }
35
- * ```
36
- *
37
- * @example
38
- * ```ts
39
- * // Custom retry logic and delay
40
- * await retryAsync(
41
- * async () => myFetch('https://api.example.com/data'),
42
- * {
43
- * maxAttempts: 10,
44
- * shouldRetry: (error) => error instanceof NetworkError,
45
- * delayInMsCalculator: (attempt) => 100 * attempt,
46
- * onAttemptFail: (error, attempt, delay) => {
47
- * console.warn(`Attempt ${attempt} failed (waiting ${delay}ms):`, error);
48
- * },
49
- * }
50
- * );
51
- * ```
52
- */
2
+ * Retries an operation a configurable number of times.
3
+ *
4
+ * The flow is as follows:
5
+ * 1. Call the `operation` function.
6
+ * 2. If it resolves, return the resolved value.
7
+ * 3. If it throws an error, check if we should retry (based on `maxAttempts` and `shouldRetry`).
8
+ * 4. If we should retry, calculate the delay using `delayInMsCalculator`, call `onAttemptFail`, wait for that duration, and then repeat from step 1.
9
+ * 5. If we shouldn't retry (either because we've exhausted attempts or `shouldRetry` returned false), re-throw the error.
10
+ *
11
+ * By default, we use exponential backoff with jitter for delays between attempts.
12
+ *
13
+ * @param operation The function to execute and retry.
14
+ * @param config Configuration for the retry mechanism.
15
+ * @returns A Promise that resolves with the result of the successful operation.
16
+ * @throws Will throw if, and only if, all retry attempts failed. Only the last exception from `operation` will be re-thrown.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * // Basic usage: retry a function that may fail
21
+ * await retryAsync(() => {
22
+ * if (Math.random() < 0.7) throw new Error('Transient error');
23
+ * return 'success';
24
+ * });
25
+ * ```
26
+ *
27
+ * * @example
28
+ * ```ts
29
+ * try {
30
+ * return retryAsync(() => fetchAllUsers());
31
+ * } catch (err) {
32
+ * console.error('Failed to fetch users after several attempts:', err);
33
+ * notifyUser('Failed to fetch users. Please try again later.');
34
+ * }
35
+ * ```
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * // Custom retry logic and delay
40
+ * await retryAsync(
41
+ * async () => myFetch('https://api.example.com/data'),
42
+ * {
43
+ * maxAttempts: 10,
44
+ * shouldRetry: (error) => error instanceof NetworkError,
45
+ * delayInMsCalculator: (attempt) => 100 * attempt,
46
+ * onAttemptFail: (error, attempt, delay) => {
47
+ * console.warn(`Attempt ${attempt} failed (waiting ${delay}ms):`, error);
48
+ * },
49
+ * }
50
+ * );
51
+ * ```
52
+ */
53
53
  export declare function retryAsync<T>(operation: () => T | Promise<T>, options?: RetryAsyncOptions): Promise<T>;
54
54
  /**
55
- * Configuration options for {@link retryAsync}.
56
- */
55
+ * Configuration options for {@link retryAsync}.
56
+ */
57
57
  export type RetryAsyncOptions = {
58
- /**
59
- * The maximum number of attempts to make, including the initial one.
60
- * Must be in the range [1, 100].
61
- * @default 5
62
- */
63
- maxAttempts?: number;
64
- /**
65
- * A function to determine if the thrown error should trigger a retry.
66
- *
67
- * If this function returns `true`, a retry will be performed (up to `maxAttempts`).
68
- * If it returns `false`, the error will be immediately thrown and not retried.
69
- * @default (error) => true // Retries on any error.
70
- * @returns Whether to retry based on the provided error.
71
- */
72
- shouldRetry?: (error: unknown) => boolean;
73
- /**
74
- * An optional callback executed after a failed attempt, but before the next delay.
75
- *
76
- * Useful for logging or metrics.
77
- * @param error The error that caused the failure.
78
- * @param attempt The current failed attempt number (1, 2, 3, etc.).
79
- * @param delayInMs The calculated delay before the next attempt.
80
- */
81
- onAttemptFail?: (error: unknown, attempt: number, delayInMs: number) => void;
82
- /**
83
- * The function that calculates the delay (in milliseconds) before the
84
- * next attempt.
85
- *
86
- * It takes the current attempt number (starting at 1) and returns the delay.
87
- * @default Delay calculated using the {@link exponentialBackoffWithJitter} function.
88
- *
89
- * @returns The delay in milliseconds before the next attempt.
90
- */
91
- delayInMsCalculator?: (attempt: number) => number;
58
+ /**
59
+ * The maximum number of attempts to make, including the initial one.
60
+ * Must be in the range [1, 100].
61
+ * @default 5
62
+ */
63
+ maxAttempts?: number;
64
+ /**
65
+ * A function to determine if the thrown error should trigger a retry.
66
+ *
67
+ * If this function returns `true`, a retry will be performed (up to `maxAttempts`).
68
+ * If it returns `false`, the error will be immediately thrown and not retried.
69
+ * @default (error) => true // Retries on any error.
70
+ * @returns Whether to retry based on the provided error.
71
+ */
72
+ shouldRetry?: (error: unknown) => boolean;
73
+ /**
74
+ * An optional callback executed after a failed attempt, but before the next delay.
75
+ *
76
+ * Useful for logging or metrics.
77
+ * @param error The error that caused the failure.
78
+ * @param attempt The current failed attempt number (1, 2, 3, etc.).
79
+ * @param delayInMs The calculated delay before the next attempt.
80
+ */
81
+ onAttemptFail?: (error: unknown, attempt: number, delayInMs: number) => void;
82
+ /**
83
+ * The function that calculates the delay (in milliseconds) before the
84
+ * next attempt.
85
+ *
86
+ * It takes the current attempt number (starting at 1) and returns the delay.
87
+ * @default Delay calculated using the {@link exponentialBackoffWithJitter} function.
88
+ *
89
+ * @returns The delay in milliseconds before the next attempt.
90
+ */
91
+ delayInMsCalculator?: (attempt: number) => number;
92
92
  };
@@ -1,18 +1,89 @@
1
- import { exponentialBackoffWithJitter as e } from "./exponential-backoff-with-jitter.js";
2
- import { sleep as t } from "./sleep.js";
3
- //#region libs/shared/underscore/src/retry-async.ts
4
- async function n(n, r = {}) {
5
- let i = r.maxAttempts ?? 5, a = r.shouldRetry ?? (() => !0), o = r.onAttemptFail, s = r.delayInMsCalculator ?? e;
6
- if (i < 1) throw Error("`maxAttempts` must be 1 or greater");
7
- if (i > 100) throw Error("`maxAttempts` must be 100 or less");
8
- let c = 1;
9
- for (;;) try {
10
- return await n();
11
- } catch (e) {
12
- if (c >= i || !a(e)) throw e;
13
- let n = s(c);
14
- o?.(e, c, n), await t(n), c++;
15
- }
1
+ import { exponentialBackoffWithJitter } from "./exponential-backoff-with-jitter.js";
2
+ import { sleep } from "./sleep.js";
3
+ /**
4
+ * Retries an operation a configurable number of times.
5
+ *
6
+ * The flow is as follows:
7
+ * 1. Call the `operation` function.
8
+ * 2. If it resolves, return the resolved value.
9
+ * 3. If it throws an error, check if we should retry (based on `maxAttempts` and `shouldRetry`).
10
+ * 4. If we should retry, calculate the delay using `delayInMsCalculator`, call `onAttemptFail`, wait for that duration, and then repeat from step 1.
11
+ * 5. If we shouldn't retry (either because we've exhausted attempts or `shouldRetry` returned false), re-throw the error.
12
+ *
13
+ * By default, we use exponential backoff with jitter for delays between attempts.
14
+ *
15
+ * @param operation The function to execute and retry.
16
+ * @param config Configuration for the retry mechanism.
17
+ * @returns A Promise that resolves with the result of the successful operation.
18
+ * @throws Will throw if, and only if, all retry attempts failed. Only the last exception from `operation` will be re-thrown.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * // Basic usage: retry a function that may fail
23
+ * await retryAsync(() => {
24
+ * if (Math.random() < 0.7) throw new Error('Transient error');
25
+ * return 'success';
26
+ * });
27
+ * ```
28
+ *
29
+ * * @example
30
+ * ```ts
31
+ * try {
32
+ * return retryAsync(() => fetchAllUsers());
33
+ * } catch (err) {
34
+ * console.error('Failed to fetch users after several attempts:', err);
35
+ * notifyUser('Failed to fetch users. Please try again later.');
36
+ * }
37
+ * ```
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * // Custom retry logic and delay
42
+ * await retryAsync(
43
+ * async () => myFetch('https://api.example.com/data'),
44
+ * {
45
+ * maxAttempts: 10,
46
+ * shouldRetry: (error) => error instanceof NetworkError,
47
+ * delayInMsCalculator: (attempt) => 100 * attempt,
48
+ * onAttemptFail: (error, attempt, delay) => {
49
+ * console.warn(`Attempt ${attempt} failed (waiting ${delay}ms):`, error);
50
+ * },
51
+ * }
52
+ * );
53
+ * ```
54
+ */ export async function retryAsync(operation, options = {}) {
55
+ var _options_maxAttempts, _options_shouldRetry, _options_delayInMsCalculator;
56
+ let maxAttempts = (_options_maxAttempts = options.maxAttempts) !== null && _options_maxAttempts !== void 0 ? _options_maxAttempts : 5;
57
+ let shouldRetry = (_options_shouldRetry = options.shouldRetry) !== null && _options_shouldRetry !== void 0 ? _options_shouldRetry : ()=>true;
58
+ let onAttemptFail = options.onAttemptFail;
59
+ let delayInMsCalculator = (_options_delayInMsCalculator = options.delayInMsCalculator) !== null && _options_delayInMsCalculator !== void 0 ? _options_delayInMsCalculator : exponentialBackoffWithJitter;
60
+ if (maxAttempts < 1) {
61
+ throw new Error('`maxAttempts` must be 1 or greater');
62
+ }
63
+ if (maxAttempts > 100) {
64
+ throw new Error('`maxAttempts` must be 100 or less');
65
+ }
66
+ let attempts = 1;
67
+ // The "infinite" loop here is intentional, and it isn't "infinite" in practice.
68
+ // We have two exit paths for this loop (and one of them will occur eventually):
69
+ // 1. The operation succeeds and we return the result.
70
+ // 2. The operation fails and we exceed `maxAttempts` or `shouldRetry` returns `false`,
71
+ // and we throw the error. As `maxAttempts` is finite, we will eventually exit here.
72
+ for(;;){
73
+ try {
74
+ // Exit path 1
75
+ return await operation();
76
+ } catch (error) {
77
+ if (attempts >= maxAttempts || !shouldRetry(error)) {
78
+ // Exit path 2
79
+ throw error;
80
+ }
81
+ const delayInMs = delayInMsCalculator(attempts);
82
+ onAttemptFail === null || onAttemptFail === void 0 ? void 0 : onAttemptFail(error, attempts, delayInMs);
83
+ await sleep(delayInMs);
84
+ attempts++;
85
+ }
86
+ }
16
87
  }
17
- //#endregion
18
- export { n as retryAsync };
88
+
89
+ //# sourceMappingURL=retry-async.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/retry-async.ts"],"sourcesContent":["import { exponentialBackoffWithJitter } from './exponential-backoff-with-jitter';\nimport { sleep } from './sleep';\n\n/**\n * Retries an operation a configurable number of times.\n *\n * The flow is as follows:\n * 1. Call the `operation` function.\n * 2. If it resolves, return the resolved value.\n * 3. If it throws an error, check if we should retry (based on `maxAttempts` and `shouldRetry`).\n * 4. If we should retry, calculate the delay using `delayInMsCalculator`, call `onAttemptFail`, wait for that duration, and then repeat from step 1.\n * 5. If we shouldn't retry (either because we've exhausted attempts or `shouldRetry` returned false), re-throw the error.\n *\n * By default, we use exponential backoff with jitter for delays between attempts.\n *\n * @param operation The function to execute and retry.\n * @param config Configuration for the retry mechanism.\n * @returns A Promise that resolves with the result of the successful operation.\n * @throws Will throw if, and only if, all retry attempts failed. Only the last exception from `operation` will be re-thrown.\n *\n * @example\n * ```ts\n * // Basic usage: retry a function that may fail\n * await retryAsync(() => {\n * if (Math.random() < 0.7) throw new Error('Transient error');\n * return 'success';\n * });\n * ```\n *\n * * @example\n * ```ts\n * try {\n * return retryAsync(() => fetchAllUsers());\n * } catch (err) {\n * console.error('Failed to fetch users after several attempts:', err);\n * notifyUser('Failed to fetch users. Please try again later.');\n * }\n * ```\n *\n * @example\n * ```ts\n * // Custom retry logic and delay\n * await retryAsync(\n * async () => myFetch('https://api.example.com/data'),\n * {\n * maxAttempts: 10,\n * shouldRetry: (error) => error instanceof NetworkError,\n * delayInMsCalculator: (attempt) => 100 * attempt,\n * onAttemptFail: (error, attempt, delay) => {\n * console.warn(`Attempt ${attempt} failed (waiting ${delay}ms):`, error);\n * },\n * }\n * );\n * ```\n */\nexport async function retryAsync<T>(\n operation: () => T | Promise<T>,\n options: RetryAsyncOptions = {}\n): Promise<T> {\n let maxAttempts = options.maxAttempts ?? 5;\n let shouldRetry = options.shouldRetry ?? ((): boolean => true);\n let onAttemptFail = options.onAttemptFail;\n let delayInMsCalculator =\n options.delayInMsCalculator ?? exponentialBackoffWithJitter;\n\n if (maxAttempts < 1) {\n throw new Error('`maxAttempts` must be 1 or greater');\n }\n if (maxAttempts > 100) {\n throw new Error('`maxAttempts` must be 100 or less');\n }\n\n let attempts = 1;\n\n // The \"infinite\" loop here is intentional, and it isn't \"infinite\" in practice.\n // We have two exit paths for this loop (and one of them will occur eventually):\n // 1. The operation succeeds and we return the result.\n // 2. The operation fails and we exceed `maxAttempts` or `shouldRetry` returns `false`,\n // and we throw the error. As `maxAttempts` is finite, we will eventually exit here.\n for (;;) {\n try {\n // Exit path 1\n return await operation();\n } catch (error) {\n if (attempts >= maxAttempts || !shouldRetry(error)) {\n // Exit path 2\n throw error;\n }\n\n const delayInMs = delayInMsCalculator(attempts);\n onAttemptFail?.(error, attempts, delayInMs);\n await sleep(delayInMs);\n\n attempts++;\n }\n }\n}\n\n/**\n * Configuration options for {@link retryAsync}.\n */\nexport type RetryAsyncOptions = {\n /**\n * The maximum number of attempts to make, including the initial one.\n * Must be in the range [1, 100].\n * @default 5\n */\n maxAttempts?: number;\n\n /**\n * A function to determine if the thrown error should trigger a retry.\n *\n * If this function returns `true`, a retry will be performed (up to `maxAttempts`).\n * If it returns `false`, the error will be immediately thrown and not retried.\n * @default (error) => true // Retries on any error.\n * @returns Whether to retry based on the provided error.\n */\n shouldRetry?: (error: unknown) => boolean;\n\n /**\n * An optional callback executed after a failed attempt, but before the next delay.\n *\n * Useful for logging or metrics.\n * @param error The error that caused the failure.\n * @param attempt The current failed attempt number (1, 2, 3, etc.).\n * @param delayInMs The calculated delay before the next attempt.\n */\n onAttemptFail?: (error: unknown, attempt: number, delayInMs: number) => void;\n\n /**\n * The function that calculates the delay (in milliseconds) before the\n * next attempt.\n *\n * It takes the current attempt number (starting at 1) and returns the delay.\n * @default Delay calculated using the {@link exponentialBackoffWithJitter} function.\n *\n * @returns The delay in milliseconds before the next attempt.\n */\n delayInMsCalculator?: (attempt: number) => number;\n};\n"],"names":["exponentialBackoffWithJitter","sleep","retryAsync","operation","options","maxAttempts","shouldRetry","onAttemptFail","delayInMsCalculator","Error","attempts","error","delayInMs"],"mappings":"AAAA,SAASA,4BAA4B,QAAQ,uCAAoC;AACjF,SAASC,KAAK,QAAQ,aAAU;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmDC,GACD,OAAO,eAAeC,WACpBC,SAA+B,EAC/BC,UAA6B,CAAC,CAAC;QAEbA,sBACAA,sBAGhBA;IAJF,IAAIC,eAAcD,uBAAAA,QAAQC,WAAW,cAAnBD,kCAAAA,uBAAuB;IACzC,IAAIE,eAAcF,uBAAAA,QAAQE,WAAW,cAAnBF,kCAAAA,uBAAwB,IAAe;IACzD,IAAIG,gBAAgBH,QAAQG,aAAa;IACzC,IAAIC,uBACFJ,+BAAAA,QAAQI,mBAAmB,cAA3BJ,0CAAAA,+BAA+BJ;IAEjC,IAAIK,cAAc,GAAG;QACnB,MAAM,IAAII,MAAM;IAClB;IACA,IAAIJ,cAAc,KAAK;QACrB,MAAM,IAAII,MAAM;IAClB;IAEA,IAAIC,WAAW;IAEf,gFAAgF;IAChF,gFAAgF;IAChF,sDAAsD;IACtD,uFAAuF;IACvF,uFAAuF;IACvF,OAAS;QACP,IAAI;YACF,cAAc;YACd,OAAO,MAAMP;QACf,EAAE,OAAOQ,OAAO;YACd,IAAID,YAAYL,eAAe,CAACC,YAAYK,QAAQ;gBAClD,cAAc;gBACd,MAAMA;YACR;YAEA,MAAMC,YAAYJ,oBAAoBE;YACtCH,0BAAAA,oCAAAA,cAAgBI,OAAOD,UAAUE;YACjC,MAAMX,MAAMW;YAEZF;QACF;IACF;AACF"}
package/dist/sleep.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Pauses the execution for a specified duration.
3
- *
4
- * @param durationInMs - The duration to sleep in milliseconds.
5
- * @returns A promise that resolves after the specified duration.
6
- */
2
+ * Pauses the execution for a specified duration.
3
+ *
4
+ * @param durationInMs - The duration to sleep in milliseconds.
5
+ * @returns A promise that resolves after the specified duration.
6
+ */
7
7
  export declare function sleep(durationInMs: number): Promise<void>;
package/dist/sleep.js CHANGED
@@ -1,6 +1,10 @@
1
- //#region libs/shared/underscore/src/sleep.ts
2
- function e(e) {
3
- return new Promise((t) => setTimeout(t, e));
1
+ /**
2
+ * Pauses the execution for a specified duration.
3
+ *
4
+ * @param durationInMs - The duration to sleep in milliseconds.
5
+ * @returns A promise that resolves after the specified duration.
6
+ */ export function sleep(durationInMs) {
7
+ return new Promise((resolve)=>setTimeout(resolve, durationInMs));
4
8
  }
5
- //#endregion
6
- export { e as sleep };
9
+
10
+ //# sourceMappingURL=sleep.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/sleep.ts"],"sourcesContent":["/**\n * Pauses the execution for a specified duration.\n *\n * @param durationInMs - The duration to sleep in milliseconds.\n * @returns A promise that resolves after the specified duration.\n */\nexport function sleep(durationInMs: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, durationInMs));\n}\n"],"names":["sleep","durationInMs","Promise","resolve","setTimeout"],"mappings":"AAAA;;;;;CAKC,GACD,OAAO,SAASA,MAAMC,YAAoB;IACxC,OAAO,IAAIC,QAAQ,CAACC,UAAYC,WAAWD,SAASF;AACtD"}
package/dist/string.d.ts CHANGED
@@ -1,41 +1,41 @@
1
1
  /**
2
- * Capitalizes the first letter of the given string.
3
- *
4
- * @param str - The string to capitalize.
5
- * @returns The input string with the first letter capitalized.
6
- *
7
- * @example
8
- * ```ts
9
- * capitalizeFirstLetter('hello'); // returns 'Hello'
10
- * ```
11
- */
2
+ * Capitalizes the first letter of the given string.
3
+ *
4
+ * @param str - The string to capitalize.
5
+ * @returns The input string with the first letter capitalized.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * capitalizeFirstLetter('hello'); // returns 'Hello'
10
+ * ```
11
+ */
12
12
  export declare function capitalizeFirstLetter(str: string): string;
13
13
  /**
14
- * Converts a kebab-case string to PascalCase.
15
- *
16
- * @param str - The kebab-case string to convert.
17
- * @returns The converted PascalCase string.
18
- *
19
- * @example
20
- * ```ts
21
- * kebabToPascalCase('kebab-case-string'); // returns 'KebabCaseString'
22
- * ```
23
- */
14
+ * Converts a kebab-case string to PascalCase.
15
+ *
16
+ * @param str - The kebab-case string to convert.
17
+ * @returns The converted PascalCase string.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * kebabToPascalCase('kebab-case-string'); // returns 'KebabCaseString'
22
+ * ```
23
+ */
24
24
  export declare function kebabToPascalCase(str: string): string;
25
25
  /**
26
- * Converts a given string to kebab-case (dash-case).
27
- *
28
- * @param str - The input string to be converted.
29
- * @returns The kebab-case version of the input string.
30
- *
31
- * @example
32
- * ```ts
33
- * toKebabCase('HelloWorld'); // Returns 'hello-world'
34
- * toKebabCase('hello_world'); // Returns 'hello-world'
35
- * toKebabCase('hello world'); // Returns 'hello-world'
36
- * toKebabCase('Hello World_Test'); // Returns 'hello-world-test'
37
- * toKebabCase('special$Char'); // Returns 'special$-char'
38
- * ```
39
- *
40
- * */
26
+ * Converts a given string to kebab-case (dash-case).
27
+ *
28
+ * @param str - The input string to be converted.
29
+ * @returns The kebab-case version of the input string.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * toKebabCase('HelloWorld'); // Returns 'hello-world'
34
+ * toKebabCase('hello_world'); // Returns 'hello-world'
35
+ * toKebabCase('hello world'); // Returns 'hello-world'
36
+ * toKebabCase('Hello World_Test'); // Returns 'hello-world-test'
37
+ * toKebabCase('special$Char'); // Returns 'special$-char'
38
+ * ```
39
+ *
40
+ * */
41
41
  export declare function toKebabCase(str: string): string;
package/dist/string.js CHANGED
@@ -1,12 +1,51 @@
1
- //#region libs/shared/underscore/src/string.ts
2
- function e(e) {
3
- return e.charAt(0).toUpperCase() + e.slice(1);
1
+ /**
2
+ * Capitalizes the first letter of the given string.
3
+ *
4
+ * @param str - The string to capitalize.
5
+ * @returns The input string with the first letter capitalized.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * capitalizeFirstLetter('hello'); // returns 'Hello'
10
+ * ```
11
+ */ export function capitalizeFirstLetter(str) {
12
+ return str.charAt(0).toUpperCase() + str.slice(1);
4
13
  }
5
- function t(e) {
6
- return e.replace(/-./g, (e) => e.charAt(1).toUpperCase()).replace(/^\w/, (e) => e.toUpperCase());
14
+ /**
15
+ * Converts a kebab-case string to PascalCase.
16
+ *
17
+ * @param str - The kebab-case string to convert.
18
+ * @returns The converted PascalCase string.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * kebabToPascalCase('kebab-case-string'); // returns 'KebabCaseString'
23
+ * ```
24
+ */ export function kebabToPascalCase(str) {
25
+ return str.replace(/-./g, (match)=>match.charAt(1).toUpperCase()).replace(/^\w/, (c)=>c.toUpperCase());
7
26
  }
8
- function n(e) {
9
- return e.replace(/([a-z])([0-9])/gi, "$1-$2").replace(/([0-9])([a-zA-Z])/g, "$1-$2").replace(/([a-z0-9$])([A-Z])/g, "$1-$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
27
+ /**
28
+ * Converts a given string to kebab-case (dash-case).
29
+ *
30
+ * @param str - The input string to be converted.
31
+ * @returns The kebab-case version of the input string.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * toKebabCase('HelloWorld'); // Returns 'hello-world'
36
+ * toKebabCase('hello_world'); // Returns 'hello-world'
37
+ * toKebabCase('hello world'); // Returns 'hello-world'
38
+ * toKebabCase('Hello World_Test'); // Returns 'hello-world-test'
39
+ * toKebabCase('special$Char'); // Returns 'special$-char'
40
+ * ```
41
+ *
42
+ * */ export function toKebabCase(str) {
43
+ return str.replace(/([a-z])([0-9])/gi, '$1-$2') // Letter to digit
44
+ .replace(/([0-9])([a-zA-Z])/g, '$1-$2') // Digit to letter
45
+ .replace(/([a-z0-9$])([A-Z])/g, '$1-$2') // Add hyphen before uppercase letters
46
+ .replace(/([A-Z]+)([A-Z][a-z])/g, '$1-$2') // Handle cases like "HTTPRequest" -> "HTTP-Request"
47
+ .replace(/[\s_]+/g, '-') // Replace spaces and underscores with hyphens
48
+ .toLowerCase(); // Convert the entire string to lowercase
10
49
  }
11
- //#endregion
12
- export { e as capitalizeFirstLetter, t as kebabToPascalCase, n as toKebabCase };
50
+
51
+ //# sourceMappingURL=string.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/string.ts"],"sourcesContent":["/**\n * Capitalizes the first letter of the given string.\n *\n * @param str - The string to capitalize.\n * @returns The input string with the first letter capitalized.\n *\n * @example\n * ```ts\n * capitalizeFirstLetter('hello'); // returns 'Hello'\n * ```\n */\nexport function capitalizeFirstLetter(str: string): string {\n return str.charAt(0).toUpperCase() + str.slice(1);\n}\n\n/**\n * Converts a kebab-case string to PascalCase.\n *\n * @param str - The kebab-case string to convert.\n * @returns The converted PascalCase string.\n *\n * @example\n * ```ts\n * kebabToPascalCase('kebab-case-string'); // returns 'KebabCaseString'\n * ```\n */\nexport function kebabToPascalCase(str: string): string {\n return str\n .replace(/-./g, (match) => match.charAt(1).toUpperCase())\n .replace(/^\\w/, (c) => c.toUpperCase());\n}\n\n/**\n * Converts a given string to kebab-case (dash-case).\n *\n * @param str - The input string to be converted.\n * @returns The kebab-case version of the input string.\n *\n * @example\n * ```ts\n * toKebabCase('HelloWorld'); // Returns 'hello-world'\n * toKebabCase('hello_world'); // Returns 'hello-world'\n * toKebabCase('hello world'); // Returns 'hello-world'\n * toKebabCase('Hello World_Test'); // Returns 'hello-world-test'\n * toKebabCase('special$Char'); // Returns 'special$-char'\n * ```\n *\n * */\nexport function toKebabCase(str: string): string {\n return str\n .replace(/([a-z])([0-9])/gi, '$1-$2') // Letter to digit\n .replace(/([0-9])([a-zA-Z])/g, '$1-$2') // Digit to letter\n .replace(/([a-z0-9$])([A-Z])/g, '$1-$2') // Add hyphen before uppercase letters\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1-$2') // Handle cases like \"HTTPRequest\" -> \"HTTP-Request\"\n .replace(/[\\s_]+/g, '-') // Replace spaces and underscores with hyphens\n .toLowerCase(); // Convert the entire string to lowercase\n}\n"],"names":["capitalizeFirstLetter","str","charAt","toUpperCase","slice","kebabToPascalCase","replace","match","c","toKebabCase","toLowerCase"],"mappings":"AAAA;;;;;;;;;;CAUC,GACD,OAAO,SAASA,sBAAsBC,GAAW;IAC/C,OAAOA,IAAIC,MAAM,CAAC,GAAGC,WAAW,KAAKF,IAAIG,KAAK,CAAC;AACjD;AAEA;;;;;;;;;;CAUC,GACD,OAAO,SAASC,kBAAkBJ,GAAW;IAC3C,OAAOA,IACJK,OAAO,CAAC,OAAO,CAACC,QAAUA,MAAML,MAAM,CAAC,GAAGC,WAAW,IACrDG,OAAO,CAAC,OAAO,CAACE,IAAMA,EAAEL,WAAW;AACxC;AAEA;;;;;;;;;;;;;;;GAeG,GACH,OAAO,SAASM,YAAYR,GAAW;IACrC,OAAOA,IACJK,OAAO,CAAC,oBAAoB,SAAS,kBAAkB;KACvDA,OAAO,CAAC,sBAAsB,SAAS,kBAAkB;KACzDA,OAAO,CAAC,uBAAuB,SAAS,sCAAsC;KAC9EA,OAAO,CAAC,yBAAyB,SAAS,oDAAoD;KAC9FA,OAAO,CAAC,WAAW,KAAK,8CAA8C;KACtEI,WAAW,IAAI,yCAAyC;AAC7D"}
@@ -1,3 +1,3 @@
1
- export { StructMap } from './structMap';
2
- export type { KeySerializer } from './types';
3
- export { stableStringify } from './stableStringify';
1
+ export { StructMap } from "./structMap";
2
+ export type { KeySerializer } from "./types";
3
+ export { stableStringify } from "./stableStringify";
@@ -0,0 +1,4 @@
1
+ export { StructMap } from "./structMap.js";
2
+ export { stableStringify } from "./stableStringify.js";
3
+
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/structMap/index.ts"],"sourcesContent":["export { StructMap } from './structMap';\nexport type { KeySerializer } from './types';\nexport { stableStringify } from './stableStringify';\n"],"names":["StructMap","stableStringify"],"mappings":"AAAA,SAASA,SAAS,QAAQ,iBAAc;AAExC,SAASC,eAAe,QAAQ,uBAAoB"}
@@ -1,23 +1,23 @@
1
1
  /**
2
- * Stringifies any value using JSON.stringify under the hood, but treating certain cases differently.
3
- * - Objects - Properties are sorted alphabetically to ensure stable output
4
- * - Non-object values - plain JSON.stringify
5
- * - Functions, symbols, undefined - removed during serialization
6
- *
7
- * @param value - A value to serialize into a string
8
- * @returns Stringified version of the provided value
9
- * @throws Throws when BigInt value is encountered at any point or a circular dependency is detected
10
- *
11
- * @example
12
- * ```ts
13
- * const fileId = { externalId: 'file-1', space: 's1' };
14
- * const fileIdReversed = { space: 's1', externalId: 'file-1' };
15
- *
16
- * console.log(stableStringify(fileId) === stableStringify(fileIdReversed)); // true
17
- *
18
- * const user = { name: 'Bob', age: 35, pets: ['Felix', 'Alex'] };
19
- *
20
- * console.log(stableStringify(user)); // {"age":35,"name":"Bob","pets":["Felix","Alex"] }
21
- * ```
22
- */
2
+ * Stringifies any value using JSON.stringify under the hood, but treating certain cases differently.
3
+ * - Objects - Properties are sorted alphabetically to ensure stable output
4
+ * - Non-object values - plain JSON.stringify
5
+ * - Functions, symbols, undefined - removed during serialization
6
+ *
7
+ * @param value - A value to serialize into a string
8
+ * @returns Stringified version of the provided value
9
+ * @throws Throws when BigInt value is encountered at any point or a circular dependency is detected
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const fileId = { externalId: 'file-1', space: 's1' };
14
+ * const fileIdReversed = { space: 's1', externalId: 'file-1' };
15
+ *
16
+ * console.log(stableStringify(fileId) === stableStringify(fileIdReversed)); // true
17
+ *
18
+ * const user = { name: 'Bob', age: 35, pets: ['Felix', 'Alex'] };
19
+ *
20
+ * console.log(stableStringify(user)); // {"age":35,"name":"Bob","pets":["Felix","Alex"] }
21
+ * ```
22
+ */
23
23
  export declare function stableStringify(value: unknown): string | undefined;