@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.
Files changed (52) hide show
  1. package/README.md +173 -0
  2. package/dist/class.d.ts +17 -11
  3. package/dist/class.d.ts.map +1 -1
  4. package/dist/class.js +27 -1
  5. package/dist/class.js.map +1 -1
  6. package/dist/collection.d.ts +17 -45
  7. package/dist/collection.d.ts.map +1 -1
  8. package/dist/collection.js +42 -76
  9. package/dist/collection.js.map +1 -1
  10. package/dist/error.d.ts +16 -8
  11. package/dist/error.d.ts.map +1 -1
  12. package/dist/error.js +35 -8
  13. package/dist/error.js.map +1 -1
  14. package/dist/graceful-shutdown.d.ts +9 -57
  15. package/dist/graceful-shutdown.d.ts.map +1 -1
  16. package/dist/graceful-shutdown.js +70 -75
  17. package/dist/graceful-shutdown.js.map +1 -1
  18. package/dist/index.d.ts +9 -6
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +9 -5
  21. package/dist/index.js.map +1 -1
  22. package/dist/log.d.ts +103 -0
  23. package/dist/log.d.ts.map +1 -0
  24. package/dist/log.js +129 -0
  25. package/dist/log.js.map +1 -0
  26. package/dist/package-version.d.ts +7 -0
  27. package/dist/package-version.d.ts.map +1 -0
  28. package/dist/package-version.js +8 -0
  29. package/dist/package-version.js.map +1 -0
  30. package/dist/reflect.d.ts +11 -0
  31. package/dist/reflect.d.ts.map +1 -0
  32. package/dist/reflect.js +14 -0
  33. package/dist/reflect.js.map +1 -0
  34. package/dist/source.d.ts +12 -25
  35. package/dist/source.d.ts.map +1 -1
  36. package/dist/source.js +20 -41
  37. package/dist/source.js.map +1 -1
  38. package/dist/string.d.ts +13 -40
  39. package/dist/string.d.ts.map +1 -1
  40. package/dist/string.js +18 -48
  41. package/dist/string.js.map +1 -1
  42. package/package.json +20 -7
  43. package/src/class.ts +30 -11
  44. package/src/collection.ts +43 -81
  45. package/src/error.ts +38 -8
  46. package/src/graceful-shutdown.ts +87 -114
  47. package/src/index.ts +18 -9
  48. package/src/log.ts +164 -0
  49. package/src/package-version.ts +9 -0
  50. package/src/reflect.ts +13 -0
  51. package/src/source.ts +24 -43
  52. package/src/string.ts +19 -47
package/src/string.ts CHANGED
@@ -1,74 +1,46 @@
1
1
  /**
2
- * Pure, runtime-agnostic string-case helpers.
2
+ * Returns the string with its first character uppercased.
3
3
  *
4
- * The conversions translate between snake_case, kebab-case, camelCase, and
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
- * Uppercases the first character of `value`, leaving the remaining characters
12
- * untouched.
9
+ * Returns the string with its first character lowercased.
13
10
  *
14
- * The tail is preserved verbatim rather than lowercased, so
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 toUpperFirst = (value: string): string => value.charAt(0).toUpperCase() + value.slice(1);
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 a snake_case or kebab-case string to camelCase.
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 - The snake_case or kebab-case identifier.
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.split(/[_-]/g).filter((part) => part.length > 0);
23
+ const parts = splitWords(input);
37
24
  if (parts.length === 0) return input;
38
- const [first, ...rest] = parts;
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 a snake_case, kebab-case, or already-PascalCase string to
45
- * PascalCase.
29
+ * Converts an underscore- or hyphen-delimited string to PascalCase.
46
30
  *
47
- * The input is split on underscores and hyphens, dropping empty segments, and
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
- if (input.length === 0) return input;
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(toUpperFirst).join("");
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 - The camelCase or PascalCase identifier.
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()}`));