@alextheman/utility 5.9.0 → 5.10.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/index.cjs CHANGED
@@ -1570,6 +1570,32 @@ function kebabToCamel(input, options) {
1570
1570
  return outputString;
1571
1571
  }
1572
1572
  //#endregion
1573
+ //#region src/root/functions/stringHelpers/toTitleCase.ts
1574
+ /**
1575
+ * Converts a string to a human-readable Title Case string.
1576
+ *
1577
+ * Words are split on spaces, underscores, and hyphens. Every first letter of each word is capitalised except for words specified in `options.preserveWords`.
1578
+ *
1579
+ * The comparison for preserved words is case-insensitive, but the original casing provided in `preserveWords` is retained in the output.
1580
+ *
1581
+ * @param input - The string to convert.
1582
+ * @param options - Additional options to apply.
1583
+ *
1584
+ * @returns A new string, converted into Title Case.
1585
+ */
1586
+ function toTitleCase(input, options) {
1587
+ const preservedWords = removeDuplicates(options?.preserveWords?.map((word) => {
1588
+ return {
1589
+ normalised: word.toLowerCase(),
1590
+ original: word
1591
+ };
1592
+ }) ?? []);
1593
+ return input.split(/[_\s-]+/).filter(Boolean).map((word) => {
1594
+ for (const preservedWord of preservedWords) if (preservedWord.normalised === word.toLowerCase()) return preservedWord.original;
1595
+ return word[0].toUpperCase() + word.slice(1).toLowerCase();
1596
+ }).join(" ");
1597
+ }
1598
+ //#endregion
1573
1599
  //#region src/root/functions/stringHelpers/truncate.ts
1574
1600
  /**
1575
1601
  * Truncates a string and appends `...` to the end of it
@@ -1641,6 +1667,7 @@ exports.removeUndefinedFromObject = removeUndefinedFromObject;
1641
1667
  exports.sayHello = sayHello;
1642
1668
  exports.stringListToArray = stringListToArray;
1643
1669
  exports.stringifyDotenv = stringifyDotenv;
1670
+ exports.toTitleCase = toTitleCase;
1644
1671
  exports.truncate = truncate;
1645
1672
  exports.wait = wait;
1646
1673
  exports.zodVersionNumber = zodVersionNumber;
package/dist/index.d.cts CHANGED
@@ -933,6 +933,29 @@ interface KebabToCamelOptions {
933
933
  */
934
934
  declare function kebabToCamel(input: string, options?: KebabToCamelOptions): string;
935
935
  //#endregion
936
+ //#region src/root/functions/stringHelpers/toTitleCase.d.ts
937
+ interface ToTitleCaseOptions {
938
+ /**
939
+ * An array of words to keep as is in the title.
940
+ *
941
+ * Note that the comparison is case insensitive, and if a match is found it will use the casing as found in the options.
942
+ */
943
+ preserveWords?: Array<string>;
944
+ }
945
+ /**
946
+ * Converts a string to a human-readable Title Case string.
947
+ *
948
+ * Words are split on spaces, underscores, and hyphens. Every first letter of each word is capitalised except for words specified in `options.preserveWords`.
949
+ *
950
+ * The comparison for preserved words is case-insensitive, but the original casing provided in `preserveWords` is retained in the output.
951
+ *
952
+ * @param input - The string to convert.
953
+ * @param options - Additional options to apply.
954
+ *
955
+ * @returns A new string, converted into Title Case.
956
+ */
957
+ declare function toTitleCase(input: string, options?: ToTitleCaseOptions): string;
958
+ //#endregion
936
959
  //#region src/root/functions/stringHelpers/truncate.d.ts
937
960
  /**
938
961
  * Truncates a string and appends `...` to the end of it
@@ -1124,4 +1147,4 @@ declare const normalizeIndents: typeof normaliseIndents;
1124
1147
  */
1125
1148
  type RecordKey = string | number | symbol;
1126
1149
  //#endregion
1127
- export { APIError, type ArrayElement, type CallReturnType, CamelToKebabOptions, type CreateEnumType, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, DataError, type DisallowUndefined, Env, FILE_PATH_PATTERN, FILE_PATH_REGEX, type FormDataArrayResolutionStrategy, type FormDataNullableResolutionStrategy, type HTTPErrorCode, type IgnoreCase, type IsTypeArgumentString, KebabToCamelOptions, type NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, type NullableOnCondition, ONE_DAY_IN_MILLISECONDS, type OptionalOnCondition, ParallelTuple, RecordKey, RemoveUndefined, type StringListToArrayOptions, UUID_PATTERN, UUID_REGEX, VERSION_NUMBER_PATTERN, VERSION_NUMBER_REGEX, VersionNumber, type FormatOptionsBase as VersionNumberToStringOptions, VersionType, addDaysToDate, appendSemicolon, calculateMonthlyDifference, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, escapeRegexPattern, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseIndents, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseUUID, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, stringListToArray, stringifyDotenv, truncate, wait, zodVersionNumber };
1150
+ export { APIError, type ArrayElement, type CallReturnType, CamelToKebabOptions, type CreateEnumType, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, DataError, type DisallowUndefined, Env, FILE_PATH_PATTERN, FILE_PATH_REGEX, type FormDataArrayResolutionStrategy, type FormDataNullableResolutionStrategy, type HTTPErrorCode, type IgnoreCase, type IsTypeArgumentString, KebabToCamelOptions, type NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, type NullableOnCondition, ONE_DAY_IN_MILLISECONDS, type OptionalOnCondition, ParallelTuple, RecordKey, RemoveUndefined, type StringListToArrayOptions, ToTitleCaseOptions, UUID_PATTERN, UUID_REGEX, VERSION_NUMBER_PATTERN, VERSION_NUMBER_REGEX, VersionNumber, type FormatOptionsBase as VersionNumberToStringOptions, VersionType, addDaysToDate, appendSemicolon, calculateMonthlyDifference, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, escapeRegexPattern, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseIndents, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseUUID, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, stringListToArray, stringifyDotenv, toTitleCase, truncate, wait, zodVersionNumber };
package/dist/index.d.ts CHANGED
@@ -933,6 +933,29 @@ interface KebabToCamelOptions {
933
933
  */
934
934
  declare function kebabToCamel(input: string, options?: KebabToCamelOptions): string;
935
935
  //#endregion
936
+ //#region src/root/functions/stringHelpers/toTitleCase.d.ts
937
+ interface ToTitleCaseOptions {
938
+ /**
939
+ * An array of words to keep as is in the title.
940
+ *
941
+ * Note that the comparison is case insensitive, and if a match is found it will use the casing as found in the options.
942
+ */
943
+ preserveWords?: Array<string>;
944
+ }
945
+ /**
946
+ * Converts a string to a human-readable Title Case string.
947
+ *
948
+ * Words are split on spaces, underscores, and hyphens. Every first letter of each word is capitalised except for words specified in `options.preserveWords`.
949
+ *
950
+ * The comparison for preserved words is case-insensitive, but the original casing provided in `preserveWords` is retained in the output.
951
+ *
952
+ * @param input - The string to convert.
953
+ * @param options - Additional options to apply.
954
+ *
955
+ * @returns A new string, converted into Title Case.
956
+ */
957
+ declare function toTitleCase(input: string, options?: ToTitleCaseOptions): string;
958
+ //#endregion
936
959
  //#region src/root/functions/stringHelpers/truncate.d.ts
937
960
  /**
938
961
  * Truncates a string and appends `...` to the end of it
@@ -1124,4 +1147,4 @@ declare const normalizeIndents: typeof normaliseIndents;
1124
1147
  */
1125
1148
  type RecordKey = string | number | symbol;
1126
1149
  //#endregion
1127
- export { APIError, type ArrayElement, type CallReturnType, CamelToKebabOptions, type CreateEnumType, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, DataError, type DisallowUndefined, Env, FILE_PATH_PATTERN, FILE_PATH_REGEX, type FormDataArrayResolutionStrategy, type FormDataNullableResolutionStrategy, type HTTPErrorCode, type IgnoreCase, type IsTypeArgumentString, KebabToCamelOptions, type NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, type NullableOnCondition, ONE_DAY_IN_MILLISECONDS, type OptionalOnCondition, ParallelTuple, RecordKey, RemoveUndefined, type StringListToArrayOptions, UUID_PATTERN, UUID_REGEX, VERSION_NUMBER_PATTERN, VERSION_NUMBER_REGEX, VersionNumber, type FormatOptionsBase as VersionNumberToStringOptions, VersionType, addDaysToDate, appendSemicolon, calculateMonthlyDifference, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, escapeRegexPattern, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseIndents, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseUUID, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, stringListToArray, stringifyDotenv, truncate, wait, zodVersionNumber };
1150
+ export { APIError, type ArrayElement, type CallReturnType, CamelToKebabOptions, type CreateEnumType, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, DataError, type DisallowUndefined, Env, FILE_PATH_PATTERN, FILE_PATH_REGEX, type FormDataArrayResolutionStrategy, type FormDataNullableResolutionStrategy, type HTTPErrorCode, type IgnoreCase, type IsTypeArgumentString, KebabToCamelOptions, type NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, type NullableOnCondition, ONE_DAY_IN_MILLISECONDS, type OptionalOnCondition, ParallelTuple, RecordKey, RemoveUndefined, type StringListToArrayOptions, ToTitleCaseOptions, UUID_PATTERN, UUID_REGEX, VERSION_NUMBER_PATTERN, VERSION_NUMBER_REGEX, VersionNumber, type FormatOptionsBase as VersionNumberToStringOptions, VersionType, addDaysToDate, appendSemicolon, calculateMonthlyDifference, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, escapeRegexPattern, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseIndents, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseUUID, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, stringListToArray, stringifyDotenv, toTitleCase, truncate, wait, zodVersionNumber };
package/dist/index.js CHANGED
@@ -1546,6 +1546,32 @@ function kebabToCamel(input, options) {
1546
1546
  return outputString;
1547
1547
  }
1548
1548
  //#endregion
1549
+ //#region src/root/functions/stringHelpers/toTitleCase.ts
1550
+ /**
1551
+ * Converts a string to a human-readable Title Case string.
1552
+ *
1553
+ * Words are split on spaces, underscores, and hyphens. Every first letter of each word is capitalised except for words specified in `options.preserveWords`.
1554
+ *
1555
+ * The comparison for preserved words is case-insensitive, but the original casing provided in `preserveWords` is retained in the output.
1556
+ *
1557
+ * @param input - The string to convert.
1558
+ * @param options - Additional options to apply.
1559
+ *
1560
+ * @returns A new string, converted into Title Case.
1561
+ */
1562
+ function toTitleCase(input, options) {
1563
+ const preservedWords = removeDuplicates(options?.preserveWords?.map((word) => {
1564
+ return {
1565
+ normalised: word.toLowerCase(),
1566
+ original: word
1567
+ };
1568
+ }) ?? []);
1569
+ return input.split(/[_\s-]+/).filter(Boolean).map((word) => {
1570
+ for (const preservedWord of preservedWords) if (preservedWord.normalised === word.toLowerCase()) return preservedWord.original;
1571
+ return word[0].toUpperCase() + word.slice(1).toLowerCase();
1572
+ }).join(" ");
1573
+ }
1574
+ //#endregion
1549
1575
  //#region src/root/functions/stringHelpers/truncate.ts
1550
1576
  /**
1551
1577
  * Truncates a string and appends `...` to the end of it
@@ -1561,4 +1587,4 @@ function truncate(stringToTruncate, maxLength = 5) {
1561
1587
  return stringToTruncate.length > maxLength ? `${stringToTruncate.slice(0, maxLength)}...` : stringToTruncate;
1562
1588
  }
1563
1589
  //#endregion
1564
- export { APIError, DataError, Env, FILE_PATH_PATTERN, FILE_PATH_REGEX, ONE_DAY_IN_MILLISECONDS, UUID_PATTERN, UUID_REGEX, VERSION_NUMBER_PATTERN, VERSION_NUMBER_REGEX, VersionNumber, VersionType, addDaysToDate, appendSemicolon, calculateMonthlyDifference, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, escapeRegexPattern, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseIndents, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseUUID, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, stringListToArray, stringifyDotenv, truncate, wait, zodVersionNumber };
1590
+ export { APIError, DataError, Env, FILE_PATH_PATTERN, FILE_PATH_REGEX, ONE_DAY_IN_MILLISECONDS, UUID_PATTERN, UUID_REGEX, VERSION_NUMBER_PATTERN, VERSION_NUMBER_REGEX, VersionNumber, VersionType, addDaysToDate, appendSemicolon, calculateMonthlyDifference, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, escapeRegexPattern, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseIndents, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseUUID, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, stringListToArray, stringifyDotenv, toTitleCase, truncate, wait, zodVersionNumber };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alextheman/utility",
3
- "version": "5.9.0",
3
+ "version": "5.10.0",
4
4
  "description": "Helpful utility functions.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -30,36 +30,37 @@
30
30
  "dist"
31
31
  ],
32
32
  "dependencies": {
33
- "dotenv": "^17.3.1",
34
- "execa": "^9.6.1",
35
- "libsodium-wrappers": "^0.8.2",
36
- "zod": "^4.3.6"
33
+ "dotenv": "17.4.0",
34
+ "execa": "9.6.1",
35
+ "libsodium-wrappers": "0.8.2",
36
+ "zod": "4.3.6"
37
37
  },
38
38
  "devDependencies": {
39
- "@alextheman/eslint-plugin": "^5.10.4",
40
- "@types/node": "^25.5.0",
41
- "alex-c-line": "^2.4.0",
42
- "cross-env": "^10.1.0",
43
- "dotenv-cli": "^11.0.0",
44
- "eslint": "^10.1.0",
45
- "globals": "^17.4.0",
46
- "husky": "^9.1.7",
47
- "jsdom": "^29.0.1",
48
- "prettier": "^3.8.1",
49
- "tempy": "^3.2.0",
50
- "tsdown": "^0.21.7",
51
- "tsx": "^4.21.0",
52
- "typedoc": "^0.28.18",
53
- "typescript": "^6.0.2",
54
- "typescript-eslint": "^8.58.0",
55
- "vite-tsconfig-paths": "^6.1.1",
56
- "vitest": "^4.1.2"
39
+ "@alextheman/eslint-plugin": "5.11.0",
40
+ "@types/node": "25.5.2",
41
+ "alex-c-line": "2.5.0",
42
+ "cross-env": "10.1.0",
43
+ "dotenv-cli": "11.0.0",
44
+ "eslint": "10.2.0",
45
+ "globals": "17.4.0",
46
+ "husky": "9.1.7",
47
+ "jsdom": "29.0.1",
48
+ "prettier": "3.8.1",
49
+ "tempy": "3.2.0",
50
+ "tsdown": "0.21.7",
51
+ "tsx": "4.21.0",
52
+ "typedoc": "0.28.18",
53
+ "typescript": "6.0.2",
54
+ "typescript-eslint": "8.58.0",
55
+ "vite-tsconfig-paths": "6.1.1",
56
+ "vitest": "4.1.2"
57
57
  },
58
58
  "engines": {
59
59
  "node": ">=22.3.0"
60
60
  },
61
61
  "scripts": {
62
62
  "build": "tsdown",
63
+ "build-configs": "tsdown --config tsdown.configs.config.ts",
63
64
  "create-feature-docs": "typedoc",
64
65
  "create-local-package": "pnpm run build && rm -f alextheman-utility-*.tgz && pnpm pack",
65
66
  "create-release-note": "bash -c 'git pull origin main && alex-c-line template release-note create $@' --",
@@ -77,7 +78,7 @@
77
78
  "lint-prettier-typescript": "prettier --check --parser typescript \"./**/*.ts\"",
78
79
  "lint-prettier-yml": "prettier --check \"./**/*.{yml,yaml}\"",
79
80
  "lint-tsc": "tsc --noEmit",
80
- "pre-commit": "alex-c-line pre-commit",
81
+ "pre-commit": "pnpm run build-configs && alex-c-line pre-commit",
81
82
  "prepare-live-eslint-plugin": "pnpm uninstall @alextheman/eslint-plugin && pnpm install --save-dev @alextheman/eslint-plugin",
82
83
  "prepare-local-eslint-plugin": "dotenv -e .env -- sh -c 'ESLINT_PLUGIN_PATH=${LOCAL_ESLINT_PLUGIN_PATH:-../eslint-plugin}; pnpm --prefix \"$ESLINT_PLUGIN_PATH\" run build && pnpm uninstall @alextheman/eslint-plugin && pnpm install --save-dev file:\"$ESLINT_PLUGIN_PATH\"'",
83
84
  "test": "vitest run",