@alextheman/utility 5.9.0 → 5.10.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/dist/index.cjs CHANGED
@@ -1570,6 +1570,34 @@ 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
+ * @category String Helpers
1582
+ *
1583
+ * @param input - The string to convert.
1584
+ * @param options - Additional options to apply.
1585
+ *
1586
+ * @returns A new string, converted into Title Case.
1587
+ */
1588
+ function toTitleCase(input, options) {
1589
+ const preservedWords = removeDuplicates(options?.preserveWords?.map((word) => {
1590
+ return {
1591
+ normalised: word.toLowerCase(),
1592
+ original: word
1593
+ };
1594
+ }) ?? []);
1595
+ return input.split(/[_\s-]+/).filter(Boolean).map((word) => {
1596
+ for (const preservedWord of preservedWords) if (preservedWord.normalised === word.toLowerCase()) return preservedWord.original;
1597
+ return word[0].toUpperCase() + word.slice(1).toLowerCase();
1598
+ }).join(" ");
1599
+ }
1600
+ //#endregion
1573
1601
  //#region src/root/functions/stringHelpers/truncate.ts
1574
1602
  /**
1575
1603
  * Truncates a string and appends `...` to the end of it
@@ -1641,6 +1669,7 @@ exports.removeUndefinedFromObject = removeUndefinedFromObject;
1641
1669
  exports.sayHello = sayHello;
1642
1670
  exports.stringListToArray = stringListToArray;
1643
1671
  exports.stringifyDotenv = stringifyDotenv;
1672
+ exports.toTitleCase = toTitleCase;
1644
1673
  exports.truncate = truncate;
1645
1674
  exports.wait = wait;
1646
1675
  exports.zodVersionNumber = zodVersionNumber;
package/dist/index.d.cts CHANGED
@@ -933,6 +933,31 @@ 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
+ * @category String Helpers
953
+ *
954
+ * @param input - The string to convert.
955
+ * @param options - Additional options to apply.
956
+ *
957
+ * @returns A new string, converted into Title Case.
958
+ */
959
+ declare function toTitleCase(input: string, options?: ToTitleCaseOptions): string;
960
+ //#endregion
936
961
  //#region src/root/functions/stringHelpers/truncate.d.ts
937
962
  /**
938
963
  * Truncates a string and appends `...` to the end of it
@@ -1124,4 +1149,4 @@ declare const normalizeIndents: typeof normaliseIndents;
1124
1149
  */
1125
1150
  type RecordKey = string | number | symbol;
1126
1151
  //#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 };
1152
+ 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,31 @@ 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
+ * @category String Helpers
953
+ *
954
+ * @param input - The string to convert.
955
+ * @param options - Additional options to apply.
956
+ *
957
+ * @returns A new string, converted into Title Case.
958
+ */
959
+ declare function toTitleCase(input: string, options?: ToTitleCaseOptions): string;
960
+ //#endregion
936
961
  //#region src/root/functions/stringHelpers/truncate.d.ts
937
962
  /**
938
963
  * Truncates a string and appends `...` to the end of it
@@ -1124,4 +1149,4 @@ declare const normalizeIndents: typeof normaliseIndents;
1124
1149
  */
1125
1150
  type RecordKey = string | number | symbol;
1126
1151
  //#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 };
1152
+ 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,34 @@ 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
+ * @category String Helpers
1558
+ *
1559
+ * @param input - The string to convert.
1560
+ * @param options - Additional options to apply.
1561
+ *
1562
+ * @returns A new string, converted into Title Case.
1563
+ */
1564
+ function toTitleCase(input, options) {
1565
+ const preservedWords = removeDuplicates(options?.preserveWords?.map((word) => {
1566
+ return {
1567
+ normalised: word.toLowerCase(),
1568
+ original: word
1569
+ };
1570
+ }) ?? []);
1571
+ return input.split(/[_\s-]+/).filter(Boolean).map((word) => {
1572
+ for (const preservedWord of preservedWords) if (preservedWord.normalised === word.toLowerCase()) return preservedWord.original;
1573
+ return word[0].toUpperCase() + word.slice(1).toLowerCase();
1574
+ }).join(" ");
1575
+ }
1576
+ //#endregion
1549
1577
  //#region src/root/functions/stringHelpers/truncate.ts
1550
1578
  /**
1551
1579
  * Truncates a string and appends `...` to the end of it
@@ -1561,4 +1589,4 @@ function truncate(stringToTruncate, maxLength = 5) {
1561
1589
  return stringToTruncate.length > maxLength ? `${stringToTruncate.slice(0, maxLength)}...` : stringToTruncate;
1562
1590
  }
1563
1591
  //#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 };
1592
+ 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.1",
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.12.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",