@ls-stack/utils 3.54.0 → 3.56.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.
- package/dist/{chunk-7L4KCZJJ.js → chunk-B6DNOZCP.js} +1 -1
- package/dist/{chunk-B3KFV2MH.js → chunk-BM4PYVOX.js} +48 -0
- package/dist/concurrentCalls.js +1 -1
- package/dist/stringUtils.cjs +60 -0
- package/dist/stringUtils.d.cts +31 -1
- package/dist/stringUtils.d.ts +31 -1
- package/dist/stringUtils.js +25 -1
- package/dist/testUtils.js +2 -2
- package/dist/timers.cjs +45 -24
- package/dist/timers.d.cts +1 -1
- package/dist/timers.d.ts +1 -1
- package/dist/timers.js +45 -24
- package/dist/yamlStringify.js +2 -2
- package/package.json +1 -1
|
@@ -22,6 +22,33 @@ function formatNum(num, maxDecimalsOrOptions = 2) {
|
|
|
22
22
|
function isSnakeCase(str) {
|
|
23
23
|
return /^[a-z0-9_]+$/.test(str);
|
|
24
24
|
}
|
|
25
|
+
function isKebabCase(str) {
|
|
26
|
+
return /^[a-z0-9]+(-[a-z0-9]+)*$/.test(str);
|
|
27
|
+
}
|
|
28
|
+
function isPascalCase(str) {
|
|
29
|
+
return /^[A-Z][a-zA-Z0-9]*$/.test(str);
|
|
30
|
+
}
|
|
31
|
+
function isCamelCase(str) {
|
|
32
|
+
return /^[a-z][a-zA-Z0-9]*$/.test(str);
|
|
33
|
+
}
|
|
34
|
+
function isTitleCase(str) {
|
|
35
|
+
return /^[A-Z][a-z0-9]*( ([A-Z][a-z0-9]*|[0-9]+))*$/.test(str);
|
|
36
|
+
}
|
|
37
|
+
function isSentenceCase(str) {
|
|
38
|
+
return /^[A-Z][a-z0-9]*( [a-z0-9]+)*$/.test(str);
|
|
39
|
+
}
|
|
40
|
+
function isConstantCase(str) {
|
|
41
|
+
return /^[A-Z_][A-Z0-9_]*$/.test(str);
|
|
42
|
+
}
|
|
43
|
+
function isDotCase(str) {
|
|
44
|
+
return /^[a-z0-9]+(\.[a-z0-9]+)*$/.test(str);
|
|
45
|
+
}
|
|
46
|
+
function isPathCase(str) {
|
|
47
|
+
return /^[a-z0-9]+(\/[a-z0-9]+)*$/.test(str);
|
|
48
|
+
}
|
|
49
|
+
function convertToKebabCase(str) {
|
|
50
|
+
return convertToSnakeCase(str).replace(/_/g, "-");
|
|
51
|
+
}
|
|
25
52
|
function convertToSnakeCase(str) {
|
|
26
53
|
return str.replace(/[\s\-.]+/g, "_").replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/([A-Z])([A-Z][a-z])/g, "$1_$2").toLowerCase().replace(/[^a-z0-9_]/g, "").replace(/^_+|_+$/g, "").replace(/_+/g, "_");
|
|
27
54
|
}
|
|
@@ -38,6 +65,15 @@ function convertToSentenceCase(str) {
|
|
|
38
65
|
function convertToTitleCase(str) {
|
|
39
66
|
return str.replace(/[\s\-.]+/g, " ").replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/([A-Z])([A-Z][a-z])/g, "$1 $2").split(/[\s_-]+/).map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
|
|
40
67
|
}
|
|
68
|
+
function convertToConstantCase(str) {
|
|
69
|
+
return convertToSnakeCase(str).toUpperCase();
|
|
70
|
+
}
|
|
71
|
+
function convertToDotCase(str) {
|
|
72
|
+
return convertToSnakeCase(str).replace(/_/g, ".");
|
|
73
|
+
}
|
|
74
|
+
function convertToPathCase(str) {
|
|
75
|
+
return convertToSnakeCase(str).replace(/_/g, "/");
|
|
76
|
+
}
|
|
41
77
|
function truncateString(str, length, ellipsis = "\u2026") {
|
|
42
78
|
if (str.length <= length) return str;
|
|
43
79
|
return str.slice(0, length - 1) + ellipsis;
|
|
@@ -51,11 +87,23 @@ export {
|
|
|
51
87
|
joinStrings,
|
|
52
88
|
formatNum,
|
|
53
89
|
isSnakeCase,
|
|
90
|
+
isKebabCase,
|
|
91
|
+
isPascalCase,
|
|
92
|
+
isCamelCase,
|
|
93
|
+
isTitleCase,
|
|
94
|
+
isSentenceCase,
|
|
95
|
+
isConstantCase,
|
|
96
|
+
isDotCase,
|
|
97
|
+
isPathCase,
|
|
98
|
+
convertToKebabCase,
|
|
54
99
|
convertToSnakeCase,
|
|
55
100
|
convertToPascalCase,
|
|
56
101
|
convertToCamelCase,
|
|
57
102
|
convertToSentenceCase,
|
|
58
103
|
convertToTitleCase,
|
|
104
|
+
convertToConstantCase,
|
|
105
|
+
convertToDotCase,
|
|
106
|
+
convertToPathCase,
|
|
59
107
|
truncateString,
|
|
60
108
|
removeANSIColors
|
|
61
109
|
};
|
package/dist/concurrentCalls.js
CHANGED
package/dist/stringUtils.cjs
CHANGED
|
@@ -22,12 +22,24 @@ var stringUtils_exports = {};
|
|
|
22
22
|
__export(stringUtils_exports, {
|
|
23
23
|
concatStrings: () => concatStrings,
|
|
24
24
|
convertToCamelCase: () => convertToCamelCase,
|
|
25
|
+
convertToConstantCase: () => convertToConstantCase,
|
|
26
|
+
convertToDotCase: () => convertToDotCase,
|
|
27
|
+
convertToKebabCase: () => convertToKebabCase,
|
|
25
28
|
convertToPascalCase: () => convertToPascalCase,
|
|
29
|
+
convertToPathCase: () => convertToPathCase,
|
|
26
30
|
convertToSentenceCase: () => convertToSentenceCase,
|
|
27
31
|
convertToSnakeCase: () => convertToSnakeCase,
|
|
28
32
|
convertToTitleCase: () => convertToTitleCase,
|
|
29
33
|
formatNum: () => formatNum,
|
|
34
|
+
isCamelCase: () => isCamelCase,
|
|
35
|
+
isConstantCase: () => isConstantCase,
|
|
36
|
+
isDotCase: () => isDotCase,
|
|
37
|
+
isKebabCase: () => isKebabCase,
|
|
38
|
+
isPascalCase: () => isPascalCase,
|
|
39
|
+
isPathCase: () => isPathCase,
|
|
40
|
+
isSentenceCase: () => isSentenceCase,
|
|
30
41
|
isSnakeCase: () => isSnakeCase,
|
|
42
|
+
isTitleCase: () => isTitleCase,
|
|
31
43
|
joinStrings: () => joinStrings,
|
|
32
44
|
removeANSIColors: () => removeANSIColors,
|
|
33
45
|
truncateString: () => truncateString
|
|
@@ -56,6 +68,33 @@ function formatNum(num, maxDecimalsOrOptions = 2) {
|
|
|
56
68
|
function isSnakeCase(str) {
|
|
57
69
|
return /^[a-z0-9_]+$/.test(str);
|
|
58
70
|
}
|
|
71
|
+
function isKebabCase(str) {
|
|
72
|
+
return /^[a-z0-9]+(-[a-z0-9]+)*$/.test(str);
|
|
73
|
+
}
|
|
74
|
+
function isPascalCase(str) {
|
|
75
|
+
return /^[A-Z][a-zA-Z0-9]*$/.test(str);
|
|
76
|
+
}
|
|
77
|
+
function isCamelCase(str) {
|
|
78
|
+
return /^[a-z][a-zA-Z0-9]*$/.test(str);
|
|
79
|
+
}
|
|
80
|
+
function isTitleCase(str) {
|
|
81
|
+
return /^[A-Z][a-z0-9]*( ([A-Z][a-z0-9]*|[0-9]+))*$/.test(str);
|
|
82
|
+
}
|
|
83
|
+
function isSentenceCase(str) {
|
|
84
|
+
return /^[A-Z][a-z0-9]*( [a-z0-9]+)*$/.test(str);
|
|
85
|
+
}
|
|
86
|
+
function isConstantCase(str) {
|
|
87
|
+
return /^[A-Z_][A-Z0-9_]*$/.test(str);
|
|
88
|
+
}
|
|
89
|
+
function isDotCase(str) {
|
|
90
|
+
return /^[a-z0-9]+(\.[a-z0-9]+)*$/.test(str);
|
|
91
|
+
}
|
|
92
|
+
function isPathCase(str) {
|
|
93
|
+
return /^[a-z0-9]+(\/[a-z0-9]+)*$/.test(str);
|
|
94
|
+
}
|
|
95
|
+
function convertToKebabCase(str) {
|
|
96
|
+
return convertToSnakeCase(str).replace(/_/g, "-");
|
|
97
|
+
}
|
|
59
98
|
function convertToSnakeCase(str) {
|
|
60
99
|
return str.replace(/[\s\-.]+/g, "_").replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/([A-Z])([A-Z][a-z])/g, "$1_$2").toLowerCase().replace(/[^a-z0-9_]/g, "").replace(/^_+|_+$/g, "").replace(/_+/g, "_");
|
|
61
100
|
}
|
|
@@ -72,6 +111,15 @@ function convertToSentenceCase(str) {
|
|
|
72
111
|
function convertToTitleCase(str) {
|
|
73
112
|
return str.replace(/[\s\-.]+/g, " ").replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/([A-Z])([A-Z][a-z])/g, "$1 $2").split(/[\s_-]+/).map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
|
|
74
113
|
}
|
|
114
|
+
function convertToConstantCase(str) {
|
|
115
|
+
return convertToSnakeCase(str).toUpperCase();
|
|
116
|
+
}
|
|
117
|
+
function convertToDotCase(str) {
|
|
118
|
+
return convertToSnakeCase(str).replace(/_/g, ".");
|
|
119
|
+
}
|
|
120
|
+
function convertToPathCase(str) {
|
|
121
|
+
return convertToSnakeCase(str).replace(/_/g, "/");
|
|
122
|
+
}
|
|
75
123
|
function truncateString(str, length, ellipsis = "\u2026") {
|
|
76
124
|
if (str.length <= length) return str;
|
|
77
125
|
return str.slice(0, length - 1) + ellipsis;
|
|
@@ -83,12 +131,24 @@ function removeANSIColors(str) {
|
|
|
83
131
|
0 && (module.exports = {
|
|
84
132
|
concatStrings,
|
|
85
133
|
convertToCamelCase,
|
|
134
|
+
convertToConstantCase,
|
|
135
|
+
convertToDotCase,
|
|
136
|
+
convertToKebabCase,
|
|
86
137
|
convertToPascalCase,
|
|
138
|
+
convertToPathCase,
|
|
87
139
|
convertToSentenceCase,
|
|
88
140
|
convertToSnakeCase,
|
|
89
141
|
convertToTitleCase,
|
|
90
142
|
formatNum,
|
|
143
|
+
isCamelCase,
|
|
144
|
+
isConstantCase,
|
|
145
|
+
isDotCase,
|
|
146
|
+
isKebabCase,
|
|
147
|
+
isPascalCase,
|
|
148
|
+
isPathCase,
|
|
149
|
+
isSentenceCase,
|
|
91
150
|
isSnakeCase,
|
|
151
|
+
isTitleCase,
|
|
92
152
|
joinStrings,
|
|
93
153
|
removeANSIColors,
|
|
94
154
|
truncateString
|
package/dist/stringUtils.d.cts
CHANGED
|
@@ -13,13 +13,43 @@ declare function concatStrings(...args: (Arg | Arg[])[]): string;
|
|
|
13
13
|
/** @deprecated Use {@link concatStrings} instead */
|
|
14
14
|
declare const joinStrings: typeof concatStrings;
|
|
15
15
|
declare function formatNum(num: number, maxDecimalsOrOptions?: number | Intl.NumberFormatOptions): string;
|
|
16
|
+
/** Check if a string is `snake_case` */
|
|
16
17
|
declare function isSnakeCase(str: string): boolean;
|
|
18
|
+
/** Check if a string is `kebab-case` */
|
|
19
|
+
declare function isKebabCase(str: string): boolean;
|
|
20
|
+
/** Check if a string is `PascalCase` */
|
|
21
|
+
declare function isPascalCase(str: string): boolean;
|
|
22
|
+
/** Check if a string is `camelCase` */
|
|
23
|
+
declare function isCamelCase(str: string): boolean;
|
|
24
|
+
/** Check if a string is `Title Case` */
|
|
25
|
+
declare function isTitleCase(str: string): boolean;
|
|
26
|
+
/** Check if a string is `Sentence Case` */
|
|
27
|
+
declare function isSentenceCase(str: string): boolean;
|
|
28
|
+
/** Check if a string is `CONSTANT_CASE` */
|
|
29
|
+
declare function isConstantCase(str: string): boolean;
|
|
30
|
+
/** Check if a string is `dot.case` */
|
|
31
|
+
declare function isDotCase(str: string): boolean;
|
|
32
|
+
/** Check if a string is `path/case` */
|
|
33
|
+
declare function isPathCase(str: string): boolean;
|
|
34
|
+
/** Convert a string to `kebab-case` */
|
|
35
|
+
declare function convertToKebabCase(str: string): string;
|
|
36
|
+
/** Convert a string to `snake_case` */
|
|
17
37
|
declare function convertToSnakeCase(str: string): string;
|
|
38
|
+
/** Convert a string to `PascalCase` */
|
|
18
39
|
declare function convertToPascalCase(str: string): string;
|
|
40
|
+
/** Convert a string to `camelCase` */
|
|
19
41
|
declare function convertToCamelCase(str: string): string;
|
|
42
|
+
/** Convert a string to `Sentence Case` */
|
|
20
43
|
declare function convertToSentenceCase(str: string): string;
|
|
44
|
+
/** Convert a string to `Title Case` */
|
|
21
45
|
declare function convertToTitleCase(str: string): string;
|
|
46
|
+
/** Convert a string to `CONSTANT_CASE` */
|
|
47
|
+
declare function convertToConstantCase(str: string): string;
|
|
48
|
+
/** Convert a string to `dot.case` */
|
|
49
|
+
declare function convertToDotCase(str: string): string;
|
|
50
|
+
/** Convert a string to `path/case` */
|
|
51
|
+
declare function convertToPathCase(str: string): string;
|
|
22
52
|
declare function truncateString(str: string, length: number, ellipsis?: string): string;
|
|
23
53
|
declare function removeANSIColors(str: string): string;
|
|
24
54
|
|
|
25
|
-
export { concatStrings, convertToCamelCase, convertToPascalCase, convertToSentenceCase, convertToSnakeCase, convertToTitleCase, formatNum, isSnakeCase, joinStrings, removeANSIColors, truncateString };
|
|
55
|
+
export { concatStrings, convertToCamelCase, convertToConstantCase, convertToDotCase, convertToKebabCase, convertToPascalCase, convertToPathCase, convertToSentenceCase, convertToSnakeCase, convertToTitleCase, formatNum, isCamelCase, isConstantCase, isDotCase, isKebabCase, isPascalCase, isPathCase, isSentenceCase, isSnakeCase, isTitleCase, joinStrings, removeANSIColors, truncateString };
|
package/dist/stringUtils.d.ts
CHANGED
|
@@ -13,13 +13,43 @@ declare function concatStrings(...args: (Arg | Arg[])[]): string;
|
|
|
13
13
|
/** @deprecated Use {@link concatStrings} instead */
|
|
14
14
|
declare const joinStrings: typeof concatStrings;
|
|
15
15
|
declare function formatNum(num: number, maxDecimalsOrOptions?: number | Intl.NumberFormatOptions): string;
|
|
16
|
+
/** Check if a string is `snake_case` */
|
|
16
17
|
declare function isSnakeCase(str: string): boolean;
|
|
18
|
+
/** Check if a string is `kebab-case` */
|
|
19
|
+
declare function isKebabCase(str: string): boolean;
|
|
20
|
+
/** Check if a string is `PascalCase` */
|
|
21
|
+
declare function isPascalCase(str: string): boolean;
|
|
22
|
+
/** Check if a string is `camelCase` */
|
|
23
|
+
declare function isCamelCase(str: string): boolean;
|
|
24
|
+
/** Check if a string is `Title Case` */
|
|
25
|
+
declare function isTitleCase(str: string): boolean;
|
|
26
|
+
/** Check if a string is `Sentence Case` */
|
|
27
|
+
declare function isSentenceCase(str: string): boolean;
|
|
28
|
+
/** Check if a string is `CONSTANT_CASE` */
|
|
29
|
+
declare function isConstantCase(str: string): boolean;
|
|
30
|
+
/** Check if a string is `dot.case` */
|
|
31
|
+
declare function isDotCase(str: string): boolean;
|
|
32
|
+
/** Check if a string is `path/case` */
|
|
33
|
+
declare function isPathCase(str: string): boolean;
|
|
34
|
+
/** Convert a string to `kebab-case` */
|
|
35
|
+
declare function convertToKebabCase(str: string): string;
|
|
36
|
+
/** Convert a string to `snake_case` */
|
|
17
37
|
declare function convertToSnakeCase(str: string): string;
|
|
38
|
+
/** Convert a string to `PascalCase` */
|
|
18
39
|
declare function convertToPascalCase(str: string): string;
|
|
40
|
+
/** Convert a string to `camelCase` */
|
|
19
41
|
declare function convertToCamelCase(str: string): string;
|
|
42
|
+
/** Convert a string to `Sentence Case` */
|
|
20
43
|
declare function convertToSentenceCase(str: string): string;
|
|
44
|
+
/** Convert a string to `Title Case` */
|
|
21
45
|
declare function convertToTitleCase(str: string): string;
|
|
46
|
+
/** Convert a string to `CONSTANT_CASE` */
|
|
47
|
+
declare function convertToConstantCase(str: string): string;
|
|
48
|
+
/** Convert a string to `dot.case` */
|
|
49
|
+
declare function convertToDotCase(str: string): string;
|
|
50
|
+
/** Convert a string to `path/case` */
|
|
51
|
+
declare function convertToPathCase(str: string): string;
|
|
22
52
|
declare function truncateString(str: string, length: number, ellipsis?: string): string;
|
|
23
53
|
declare function removeANSIColors(str: string): string;
|
|
24
54
|
|
|
25
|
-
export { concatStrings, convertToCamelCase, convertToPascalCase, convertToSentenceCase, convertToSnakeCase, convertToTitleCase, formatNum, isSnakeCase, joinStrings, removeANSIColors, truncateString };
|
|
55
|
+
export { concatStrings, convertToCamelCase, convertToConstantCase, convertToDotCase, convertToKebabCase, convertToPascalCase, convertToPathCase, convertToSentenceCase, convertToSnakeCase, convertToTitleCase, formatNum, isCamelCase, isConstantCase, isDotCase, isKebabCase, isPascalCase, isPathCase, isSentenceCase, isSnakeCase, isTitleCase, joinStrings, removeANSIColors, truncateString };
|
package/dist/stringUtils.js
CHANGED
|
@@ -1,25 +1,49 @@
|
|
|
1
1
|
import {
|
|
2
2
|
concatStrings,
|
|
3
3
|
convertToCamelCase,
|
|
4
|
+
convertToConstantCase,
|
|
5
|
+
convertToDotCase,
|
|
6
|
+
convertToKebabCase,
|
|
4
7
|
convertToPascalCase,
|
|
8
|
+
convertToPathCase,
|
|
5
9
|
convertToSentenceCase,
|
|
6
10
|
convertToSnakeCase,
|
|
7
11
|
convertToTitleCase,
|
|
8
12
|
formatNum,
|
|
13
|
+
isCamelCase,
|
|
14
|
+
isConstantCase,
|
|
15
|
+
isDotCase,
|
|
16
|
+
isKebabCase,
|
|
17
|
+
isPascalCase,
|
|
18
|
+
isPathCase,
|
|
19
|
+
isSentenceCase,
|
|
9
20
|
isSnakeCase,
|
|
21
|
+
isTitleCase,
|
|
10
22
|
joinStrings,
|
|
11
23
|
removeANSIColors,
|
|
12
24
|
truncateString
|
|
13
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-BM4PYVOX.js";
|
|
14
26
|
export {
|
|
15
27
|
concatStrings,
|
|
16
28
|
convertToCamelCase,
|
|
29
|
+
convertToConstantCase,
|
|
30
|
+
convertToDotCase,
|
|
31
|
+
convertToKebabCase,
|
|
17
32
|
convertToPascalCase,
|
|
33
|
+
convertToPathCase,
|
|
18
34
|
convertToSentenceCase,
|
|
19
35
|
convertToSnakeCase,
|
|
20
36
|
convertToTitleCase,
|
|
21
37
|
formatNum,
|
|
38
|
+
isCamelCase,
|
|
39
|
+
isConstantCase,
|
|
40
|
+
isDotCase,
|
|
41
|
+
isKebabCase,
|
|
42
|
+
isPascalCase,
|
|
43
|
+
isPathCase,
|
|
44
|
+
isSentenceCase,
|
|
22
45
|
isSnakeCase,
|
|
46
|
+
isTitleCase,
|
|
23
47
|
joinStrings,
|
|
24
48
|
removeANSIColors,
|
|
25
49
|
truncateString
|
package/dist/testUtils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
yamlStringify
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-B6DNOZCP.js";
|
|
4
4
|
import {
|
|
5
5
|
omit,
|
|
6
6
|
pick
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
import {
|
|
23
23
|
clampMin
|
|
24
24
|
} from "./chunk-HTCYUMDR.js";
|
|
25
|
-
import "./chunk-
|
|
25
|
+
import "./chunk-BM4PYVOX.js";
|
|
26
26
|
import {
|
|
27
27
|
arrayWithPrevAndIndex,
|
|
28
28
|
filterAndMap
|
package/dist/timers.cjs
CHANGED
|
@@ -125,9 +125,11 @@ async function waitFor(condition, { polling, timeout }) {
|
|
|
125
125
|
cleanup();
|
|
126
126
|
resolve(result);
|
|
127
127
|
}
|
|
128
|
-
function checkCondition() {
|
|
128
|
+
async function checkCondition() {
|
|
129
129
|
try {
|
|
130
|
-
|
|
130
|
+
const result = condition();
|
|
131
|
+
const conditionMet = result instanceof Promise ? await result : result;
|
|
132
|
+
if (conditionMet) {
|
|
131
133
|
resolveWith(import_t_result.Result.ok(void 0));
|
|
132
134
|
return true;
|
|
133
135
|
}
|
|
@@ -137,30 +139,49 @@ async function waitFor(condition, { polling, timeout }) {
|
|
|
137
139
|
return true;
|
|
138
140
|
}
|
|
139
141
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
142
|
+
checkCondition().then((resolved) => {
|
|
143
|
+
if (resolved) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
timeoutId = setTimeout(() => {
|
|
147
|
+
resolveWith(
|
|
148
|
+
import_t_result.Result.err(
|
|
149
|
+
new Error(
|
|
150
|
+
`Timeout of ${timeout}ms exceeded while waiting for condition`
|
|
151
|
+
)
|
|
152
|
+
)
|
|
153
|
+
);
|
|
154
|
+
}, timeout);
|
|
155
|
+
if (polling === "raf") {
|
|
156
|
+
let rafCheck2 = function() {
|
|
157
|
+
if (isResolved) return;
|
|
158
|
+
checkCondition().then((conditionResolved) => {
|
|
159
|
+
if (!conditionResolved && !isResolved) {
|
|
160
|
+
rafId = requestAnimationFrame(rafCheck2);
|
|
161
|
+
}
|
|
162
|
+
}).catch(() => {
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
var rafCheck = rafCheck2;
|
|
166
|
+
if (typeof requestAnimationFrame === "undefined") {
|
|
167
|
+
resolveWith(
|
|
168
|
+
import_t_result.Result.err(
|
|
169
|
+
new Error(
|
|
170
|
+
"requestAnimationFrame is not available in this environment"
|
|
171
|
+
)
|
|
172
|
+
)
|
|
173
|
+
);
|
|
174
|
+
return;
|
|
151
175
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
176
|
+
rafId = requestAnimationFrame(rafCheck2);
|
|
177
|
+
} else {
|
|
178
|
+
intervalId = setInterval(() => {
|
|
179
|
+
checkCondition().catch(() => {
|
|
180
|
+
});
|
|
181
|
+
}, polling);
|
|
157
182
|
}
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
intervalId = setInterval(() => {
|
|
161
|
-
checkCondition();
|
|
162
|
-
}, polling);
|
|
163
|
-
}
|
|
183
|
+
}).catch(() => {
|
|
184
|
+
});
|
|
164
185
|
return promise;
|
|
165
186
|
}
|
|
166
187
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/timers.d.cts
CHANGED
|
@@ -113,7 +113,7 @@ declare function createWaitUntil<T extends NonNullable<unknown>>({ condition, ma
|
|
|
113
113
|
callback: (value: T) => void;
|
|
114
114
|
checkIntervalMs?: number;
|
|
115
115
|
}): CleanupTimer;
|
|
116
|
-
declare function waitFor(condition: () => boolean
|
|
116
|
+
declare function waitFor(condition: () => boolean | Promise<boolean>, { polling, timeout }: {
|
|
117
117
|
polling: number | 'raf';
|
|
118
118
|
timeout: number;
|
|
119
119
|
}): Promise<Result<void, Error>>;
|
package/dist/timers.d.ts
CHANGED
|
@@ -113,7 +113,7 @@ declare function createWaitUntil<T extends NonNullable<unknown>>({ condition, ma
|
|
|
113
113
|
callback: (value: T) => void;
|
|
114
114
|
checkIntervalMs?: number;
|
|
115
115
|
}): CleanupTimer;
|
|
116
|
-
declare function waitFor(condition: () => boolean
|
|
116
|
+
declare function waitFor(condition: () => boolean | Promise<boolean>, { polling, timeout }: {
|
|
117
117
|
polling: number | 'raf';
|
|
118
118
|
timeout: number;
|
|
119
119
|
}): Promise<Result<void, Error>>;
|
package/dist/timers.js
CHANGED
|
@@ -88,9 +88,11 @@ async function waitFor(condition, { polling, timeout }) {
|
|
|
88
88
|
cleanup();
|
|
89
89
|
resolve(result);
|
|
90
90
|
}
|
|
91
|
-
function checkCondition() {
|
|
91
|
+
async function checkCondition() {
|
|
92
92
|
try {
|
|
93
|
-
|
|
93
|
+
const result = condition();
|
|
94
|
+
const conditionMet = result instanceof Promise ? await result : result;
|
|
95
|
+
if (conditionMet) {
|
|
94
96
|
resolveWith(Result.ok(void 0));
|
|
95
97
|
return true;
|
|
96
98
|
}
|
|
@@ -100,30 +102,49 @@ async function waitFor(condition, { polling, timeout }) {
|
|
|
100
102
|
return true;
|
|
101
103
|
}
|
|
102
104
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
105
|
+
checkCondition().then((resolved) => {
|
|
106
|
+
if (resolved) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
timeoutId = setTimeout(() => {
|
|
110
|
+
resolveWith(
|
|
111
|
+
Result.err(
|
|
112
|
+
new Error(
|
|
113
|
+
`Timeout of ${timeout}ms exceeded while waiting for condition`
|
|
114
|
+
)
|
|
115
|
+
)
|
|
116
|
+
);
|
|
117
|
+
}, timeout);
|
|
118
|
+
if (polling === "raf") {
|
|
119
|
+
let rafCheck2 = function() {
|
|
120
|
+
if (isResolved) return;
|
|
121
|
+
checkCondition().then((conditionResolved) => {
|
|
122
|
+
if (!conditionResolved && !isResolved) {
|
|
123
|
+
rafId = requestAnimationFrame(rafCheck2);
|
|
124
|
+
}
|
|
125
|
+
}).catch(() => {
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
var rafCheck = rafCheck2;
|
|
129
|
+
if (typeof requestAnimationFrame === "undefined") {
|
|
130
|
+
resolveWith(
|
|
131
|
+
Result.err(
|
|
132
|
+
new Error(
|
|
133
|
+
"requestAnimationFrame is not available in this environment"
|
|
134
|
+
)
|
|
135
|
+
)
|
|
136
|
+
);
|
|
137
|
+
return;
|
|
114
138
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
139
|
+
rafId = requestAnimationFrame(rafCheck2);
|
|
140
|
+
} else {
|
|
141
|
+
intervalId = setInterval(() => {
|
|
142
|
+
checkCondition().catch(() => {
|
|
143
|
+
});
|
|
144
|
+
}, polling);
|
|
120
145
|
}
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
intervalId = setInterval(() => {
|
|
124
|
-
checkCondition();
|
|
125
|
-
}, polling);
|
|
126
|
-
}
|
|
146
|
+
}).catch(() => {
|
|
147
|
+
});
|
|
127
148
|
return promise;
|
|
128
149
|
}
|
|
129
150
|
export {
|
package/dist/yamlStringify.js
CHANGED