@gtkx/utils 0.21.0 → 1.0.0-rc.1
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/README.md +173 -0
- package/dist/class.d.ts +17 -11
- package/dist/class.d.ts.map +1 -1
- package/dist/class.js +27 -1
- package/dist/class.js.map +1 -1
- package/dist/collection.d.ts +17 -45
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +42 -76
- package/dist/collection.js.map +1 -1
- package/dist/error.d.ts +16 -8
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +35 -8
- package/dist/error.js.map +1 -1
- package/dist/graceful-shutdown.d.ts +9 -57
- package/dist/graceful-shutdown.d.ts.map +1 -1
- package/dist/graceful-shutdown.js +70 -75
- package/dist/graceful-shutdown.js.map +1 -1
- package/dist/index.d.ts +9 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -5
- package/dist/index.js.map +1 -1
- package/dist/log.d.ts +103 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/log.js +129 -0
- package/dist/log.js.map +1 -0
- package/dist/package-version.d.ts +7 -0
- package/dist/package-version.d.ts.map +1 -0
- package/dist/package-version.js +8 -0
- package/dist/package-version.js.map +1 -0
- package/dist/reflect.d.ts +11 -0
- package/dist/reflect.d.ts.map +1 -0
- package/dist/reflect.js +14 -0
- package/dist/reflect.js.map +1 -0
- package/dist/source.d.ts +12 -25
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +20 -41
- package/dist/source.js.map +1 -1
- package/dist/string.d.ts +13 -40
- package/dist/string.d.ts.map +1 -1
- package/dist/string.js +18 -48
- package/dist/string.js.map +1 -1
- package/package.json +20 -7
- package/src/class.ts +30 -11
- package/src/collection.ts +43 -81
- package/src/error.ts +38 -8
- package/src/graceful-shutdown.ts +87 -114
- package/src/index.ts +18 -9
- package/src/log.ts +164 -0
- package/src/package-version.ts +9 -0
- package/src/reflect.ts +13 -0
- package/src/source.ts +24 -43
- package/src/string.ts +19 -47
package/src/string.ts
CHANGED
|
@@ -1,74 +1,46 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Returns the string with its first character uppercased.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* PascalCase. They split only on underscores and hyphens and preserve the case
|
|
6
|
-
* of each segment, so they are not a substitute for a full Unicode-aware case
|
|
7
|
-
* transform.
|
|
4
|
+
* @param value The string to transform.
|
|
8
5
|
*/
|
|
6
|
+
export const upperFirst = (value: string): string => value.charAt(0).toUpperCase() + value.slice(1);
|
|
9
7
|
|
|
10
8
|
/**
|
|
11
|
-
*
|
|
12
|
-
* untouched.
|
|
9
|
+
* Returns the string with its first character lowercased.
|
|
13
10
|
*
|
|
14
|
-
*
|
|
15
|
-
* `toUpperFirst("fooBar")` is `"FooBar"` and `toUpperFirst("URL")` is `"URL"`. An
|
|
16
|
-
* empty string returns an empty string.
|
|
17
|
-
*
|
|
18
|
-
* @param value - The string to transform.
|
|
19
|
-
* @returns `value` with its first character uppercased.
|
|
11
|
+
* @param value The string to transform.
|
|
20
12
|
*/
|
|
21
|
-
export const
|
|
13
|
+
export const lowerFirst = (value: string): string => value.charAt(0).toLowerCase() + value.slice(1);
|
|
14
|
+
|
|
15
|
+
const splitWords = (input: string): string[] => input.split(/[_-]/g).filter((part) => part.length > 0);
|
|
22
16
|
|
|
23
17
|
/**
|
|
24
|
-
* Converts
|
|
25
|
-
*
|
|
26
|
-
* The input is split on underscores and hyphens, dropping empty segments from
|
|
27
|
-
* leading, trailing, or repeated separators. The first segment is kept
|
|
28
|
-
* verbatim and every later segment is {@link toUpperFirst}-cased before joining,
|
|
29
|
-
* so `toCamelCase("icon_name")` is `"iconName"` and `toCamelCase("Box")` is
|
|
30
|
-
* `"Box"`. A string with no separators is returned unchanged.
|
|
18
|
+
* Converts an underscore- or hyphen-delimited string to camelCase.
|
|
31
19
|
*
|
|
32
|
-
* @param input
|
|
33
|
-
* @returns The camelCase form of `input`.
|
|
20
|
+
* @param input The string to convert.
|
|
34
21
|
*/
|
|
35
22
|
export const toCamelCase = (input: string): string => {
|
|
36
|
-
const parts = input
|
|
23
|
+
const parts = splitWords(input);
|
|
37
24
|
if (parts.length === 0) return input;
|
|
38
|
-
|
|
39
|
-
const head = first ?? "";
|
|
40
|
-
return head + rest.map(toUpperFirst).join("");
|
|
25
|
+
return parts.map((part, index) => (index === 0 ? part : upperFirst(part))).join("");
|
|
41
26
|
};
|
|
42
27
|
|
|
43
28
|
/**
|
|
44
|
-
* Converts
|
|
45
|
-
* PascalCase.
|
|
29
|
+
* Converts an underscore- or hyphen-delimited string to PascalCase.
|
|
46
30
|
*
|
|
47
|
-
*
|
|
48
|
-
* every remaining segment is {@link toUpperFirst}-cased before joining, so
|
|
49
|
-
* `toPascalCase("icon_name")` is `"IconName"` and `toPascalCase("Box")` is
|
|
50
|
-
* `"Box"`. An empty string is returned unchanged.
|
|
51
|
-
*
|
|
52
|
-
* @param input - The identifier to transform.
|
|
53
|
-
* @returns The PascalCase form of `input`.
|
|
31
|
+
* @param input The string to convert.
|
|
54
32
|
*/
|
|
55
33
|
export const toPascalCase = (input: string): string => {
|
|
56
|
-
|
|
57
|
-
const parts = input.split(/[_-]/g).filter((part) => part.length > 0);
|
|
34
|
+
const parts = splitWords(input);
|
|
58
35
|
if (parts.length === 0) return input;
|
|
59
|
-
return parts.map(
|
|
36
|
+
return parts.map(upperFirst).join("");
|
|
60
37
|
};
|
|
61
38
|
|
|
62
39
|
/**
|
|
63
|
-
* Converts a camelCase or PascalCase string to kebab-case
|
|
64
|
-
*
|
|
65
|
-
* Each uppercase character is lowercased; every uppercase character other than
|
|
66
|
-
* the first is additionally prefixed with a hyphen, so `toKebabCase("iconName")`
|
|
67
|
-
* is `"icon-name"` and `toKebabCase("Title")` is `"title"`. The leading
|
|
68
|
-
* character is never prefixed with a hyphen.
|
|
40
|
+
* Converts a camelCase or PascalCase string to kebab-case by lowercasing uppercase letters and
|
|
41
|
+
* inserting hyphens before interior ones.
|
|
69
42
|
*
|
|
70
|
-
* @param input
|
|
71
|
-
* @returns The kebab-case form of `input`.
|
|
43
|
+
* @param input The string to convert.
|
|
72
44
|
*/
|
|
73
45
|
export const toKebabCase = (input: string): string =>
|
|
74
46
|
input.replaceAll(/[A-Z]/g, (char, index: number) => (index === 0 ? char.toLowerCase() : `-${char.toLowerCase()}`));
|