@alextheman/utility 4.0.0 → 4.1.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 +29 -5
- package/dist/index.d.cts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +27 -3
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -27,8 +27,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
//#endregion
|
|
28
28
|
let zod = require("zod");
|
|
29
29
|
zod = __toESM(zod);
|
|
30
|
-
let
|
|
31
|
-
|
|
30
|
+
let node_path = require("node:path");
|
|
31
|
+
node_path = __toESM(node_path);
|
|
32
32
|
|
|
33
33
|
//#region src/constants/NAMESPACE_EXPORT_REGEX.ts
|
|
34
34
|
const NAMESPACE_EXPORT_REGEX = "export\\s+\\*\\s+from";
|
|
@@ -795,11 +795,35 @@ var appendSemicolon_default = appendSemicolon;
|
|
|
795
795
|
* Converts a string from camelCase to kebab-case
|
|
796
796
|
*
|
|
797
797
|
* @param string - The string to convert.
|
|
798
|
+
* @param options - Options to apply to the conversion.
|
|
798
799
|
*
|
|
799
800
|
* @returns The string converted to kebab-case.
|
|
800
801
|
*/
|
|
801
|
-
function camelToKebab(string) {
|
|
802
|
-
|
|
802
|
+
function camelToKebab(string, options = { preserveConsecutiveCapitals: true }) {
|
|
803
|
+
let result = "";
|
|
804
|
+
let outerIndex = 0;
|
|
805
|
+
while (outerIndex < string.length) {
|
|
806
|
+
const character = string[outerIndex];
|
|
807
|
+
if (/[A-Z]/.test(character)) {
|
|
808
|
+
let innerIndex = outerIndex + 1;
|
|
809
|
+
while (innerIndex < string.length && /[A-Z]/.test(string[innerIndex]) && (options.preserveConsecutiveCapitals ? innerIndex + 1 < string.length && /[a-z]/.test(string[innerIndex + 1]) ? false : true : true)) innerIndex++;
|
|
810
|
+
const sequenceOfCapitals = string.slice(outerIndex, innerIndex);
|
|
811
|
+
if (options.preserveConsecutiveCapitals) {
|
|
812
|
+
if (result) result += "-";
|
|
813
|
+
result += sequenceOfCapitals.toLowerCase();
|
|
814
|
+
} else {
|
|
815
|
+
if (result) result += "-";
|
|
816
|
+
result += sequenceOfCapitals.split("").map((character$1) => {
|
|
817
|
+
return character$1.toLowerCase();
|
|
818
|
+
}).join("-");
|
|
819
|
+
}
|
|
820
|
+
outerIndex = innerIndex;
|
|
821
|
+
} else {
|
|
822
|
+
result += character;
|
|
823
|
+
outerIndex++;
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
return result;
|
|
803
827
|
}
|
|
804
828
|
var camelToKebab_default = camelToKebab;
|
|
805
829
|
|
|
@@ -857,7 +881,7 @@ var kebabToCamel_default = kebabToCamel;
|
|
|
857
881
|
* @returns The import path normalized.
|
|
858
882
|
*/
|
|
859
883
|
function normalizeImportPath(importPath) {
|
|
860
|
-
const normalizedPath =
|
|
884
|
+
const normalizedPath = node_path.default.posix.normalize(importPath);
|
|
861
885
|
if (importPath.startsWith("./") && !normalizedPath.startsWith("./")) return `./${normalizedPath}`;
|
|
862
886
|
return normalizedPath;
|
|
863
887
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -524,14 +524,19 @@ declare function deepFreeze<ObjectType extends object>(object: ObjectType): Read
|
|
|
524
524
|
declare function appendSemicolon(stringToAppendTo: string): string;
|
|
525
525
|
//#endregion
|
|
526
526
|
//#region src/functions/stringHelpers/camelToKebab.d.ts
|
|
527
|
+
interface CamelToKebabOptions {
|
|
528
|
+
/** Whether to leave consecutive capitals alone in the conversion or not (e.g. `validateAPIUser` becomes `validate-a-p-i-user` if `false`, and `validate-api-user` if `true`) */
|
|
529
|
+
preserveConsecutiveCapitals?: boolean;
|
|
530
|
+
}
|
|
527
531
|
/**
|
|
528
532
|
* Converts a string from camelCase to kebab-case
|
|
529
533
|
*
|
|
530
534
|
* @param string - The string to convert.
|
|
535
|
+
* @param options - Options to apply to the conversion.
|
|
531
536
|
*
|
|
532
537
|
* @returns The string converted to kebab-case.
|
|
533
538
|
*/
|
|
534
|
-
declare function camelToKebab(string: string): string;
|
|
539
|
+
declare function camelToKebab(string: string, options?: CamelToKebabOptions): string;
|
|
535
540
|
//#endregion
|
|
536
541
|
//#region src/functions/stringHelpers/kebabToCamel.d.ts
|
|
537
542
|
interface KebabToCamelOptions {
|
|
@@ -742,4 +747,4 @@ interface ParseVersionOptions {
|
|
|
742
747
|
*/
|
|
743
748
|
declare function parseVersion(input: string, options?: ParseVersionOptions): string;
|
|
744
749
|
//#endregion
|
|
745
|
-
export { APIError, ArrayElement, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DisallowUndefined, Env, FormDataArrayResolutionStrategy, FormDataNullableResolutionStrategy, HTTPErrorCode, IgnoreCase, IncrementVersionOptions, KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, OptionalOnCondition, ParseVersionOptions, RecordKey, StringListToArrayOptions, VERSION_NUMBER_REGEX, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, determineVersionType, fillArray, formatDateAndTime, getIndividualVersionNumbers, getRandomNumber, getRecordKeys, httpErrorCodeLookup, incrementVersion, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, normaliseImportPath, normaliseIndents, normalizeImportPath, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseVersion, parseVersionType, parseZodSchema, randomiseArray, range, removeDuplicates, stringListToArray, truncate, wait };
|
|
750
|
+
export { APIError, ArrayElement, CamelToKebabOptions, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DisallowUndefined, Env, FormDataArrayResolutionStrategy, FormDataNullableResolutionStrategy, HTTPErrorCode, IgnoreCase, IncrementVersionOptions, KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, OptionalOnCondition, ParseVersionOptions, RecordKey, StringListToArrayOptions, VERSION_NUMBER_REGEX, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, determineVersionType, fillArray, formatDateAndTime, getIndividualVersionNumbers, getRandomNumber, getRecordKeys, httpErrorCodeLookup, incrementVersion, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, normaliseImportPath, normaliseIndents, normalizeImportPath, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseVersion, parseVersionType, parseZodSchema, randomiseArray, range, removeDuplicates, stringListToArray, truncate, wait };
|
package/dist/index.d.ts
CHANGED
|
@@ -524,14 +524,19 @@ declare function deepFreeze<ObjectType extends object>(object: ObjectType): Read
|
|
|
524
524
|
declare function appendSemicolon(stringToAppendTo: string): string;
|
|
525
525
|
//#endregion
|
|
526
526
|
//#region src/functions/stringHelpers/camelToKebab.d.ts
|
|
527
|
+
interface CamelToKebabOptions {
|
|
528
|
+
/** Whether to leave consecutive capitals alone in the conversion or not (e.g. `validateAPIUser` becomes `validate-a-p-i-user` if `false`, and `validate-api-user` if `true`) */
|
|
529
|
+
preserveConsecutiveCapitals?: boolean;
|
|
530
|
+
}
|
|
527
531
|
/**
|
|
528
532
|
* Converts a string from camelCase to kebab-case
|
|
529
533
|
*
|
|
530
534
|
* @param string - The string to convert.
|
|
535
|
+
* @param options - Options to apply to the conversion.
|
|
531
536
|
*
|
|
532
537
|
* @returns The string converted to kebab-case.
|
|
533
538
|
*/
|
|
534
|
-
declare function camelToKebab(string: string): string;
|
|
539
|
+
declare function camelToKebab(string: string, options?: CamelToKebabOptions): string;
|
|
535
540
|
//#endregion
|
|
536
541
|
//#region src/functions/stringHelpers/kebabToCamel.d.ts
|
|
537
542
|
interface KebabToCamelOptions {
|
|
@@ -742,4 +747,4 @@ interface ParseVersionOptions {
|
|
|
742
747
|
*/
|
|
743
748
|
declare function parseVersion(input: string, options?: ParseVersionOptions): string;
|
|
744
749
|
//#endregion
|
|
745
|
-
export { APIError, ArrayElement, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DisallowUndefined, type Env, FormDataArrayResolutionStrategy, FormDataNullableResolutionStrategy, HTTPErrorCode, IgnoreCase, type IncrementVersionOptions, KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, OptionalOnCondition, type ParseVersionOptions, RecordKey, StringListToArrayOptions, VERSION_NUMBER_REGEX, type VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, determineVersionType, fillArray, formatDateAndTime, getIndividualVersionNumbers, getRandomNumber, getRecordKeys, httpErrorCodeLookup, incrementVersion, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, normaliseImportPath, normaliseIndents, normalizeImportPath, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseVersion, parseVersionType, parseZodSchema, randomiseArray, range, removeDuplicates, stringListToArray, truncate, wait };
|
|
750
|
+
export { APIError, ArrayElement, CamelToKebabOptions, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DisallowUndefined, type Env, FormDataArrayResolutionStrategy, FormDataNullableResolutionStrategy, HTTPErrorCode, IgnoreCase, type IncrementVersionOptions, KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, OptionalOnCondition, type ParseVersionOptions, RecordKey, StringListToArrayOptions, VERSION_NUMBER_REGEX, type VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, determineVersionType, fillArray, formatDateAndTime, getIndividualVersionNumbers, getRandomNumber, getRecordKeys, httpErrorCodeLookup, incrementVersion, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, normaliseImportPath, normaliseIndents, normalizeImportPath, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseVersion, parseVersionType, parseZodSchema, randomiseArray, range, removeDuplicates, stringListToArray, truncate, wait };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import z, { z as z$1 } from "zod";
|
|
2
|
-
import path from "path";
|
|
2
|
+
import path from "node:path";
|
|
3
3
|
|
|
4
4
|
//#region src/constants/NAMESPACE_EXPORT_REGEX.ts
|
|
5
5
|
const NAMESPACE_EXPORT_REGEX = "export\\s+\\*\\s+from";
|
|
@@ -766,11 +766,35 @@ var appendSemicolon_default = appendSemicolon;
|
|
|
766
766
|
* Converts a string from camelCase to kebab-case
|
|
767
767
|
*
|
|
768
768
|
* @param string - The string to convert.
|
|
769
|
+
* @param options - Options to apply to the conversion.
|
|
769
770
|
*
|
|
770
771
|
* @returns The string converted to kebab-case.
|
|
771
772
|
*/
|
|
772
|
-
function camelToKebab(string) {
|
|
773
|
-
|
|
773
|
+
function camelToKebab(string, options = { preserveConsecutiveCapitals: true }) {
|
|
774
|
+
let result = "";
|
|
775
|
+
let outerIndex = 0;
|
|
776
|
+
while (outerIndex < string.length) {
|
|
777
|
+
const character = string[outerIndex];
|
|
778
|
+
if (/[A-Z]/.test(character)) {
|
|
779
|
+
let innerIndex = outerIndex + 1;
|
|
780
|
+
while (innerIndex < string.length && /[A-Z]/.test(string[innerIndex]) && (options.preserveConsecutiveCapitals ? innerIndex + 1 < string.length && /[a-z]/.test(string[innerIndex + 1]) ? false : true : true)) innerIndex++;
|
|
781
|
+
const sequenceOfCapitals = string.slice(outerIndex, innerIndex);
|
|
782
|
+
if (options.preserveConsecutiveCapitals) {
|
|
783
|
+
if (result) result += "-";
|
|
784
|
+
result += sequenceOfCapitals.toLowerCase();
|
|
785
|
+
} else {
|
|
786
|
+
if (result) result += "-";
|
|
787
|
+
result += sequenceOfCapitals.split("").map((character$1) => {
|
|
788
|
+
return character$1.toLowerCase();
|
|
789
|
+
}).join("-");
|
|
790
|
+
}
|
|
791
|
+
outerIndex = innerIndex;
|
|
792
|
+
} else {
|
|
793
|
+
result += character;
|
|
794
|
+
outerIndex++;
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
return result;
|
|
774
798
|
}
|
|
775
799
|
var camelToKebab_default = camelToKebab;
|
|
776
800
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alextheman/utility",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "Helpful utility functions",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
"zod": "^4.2.1"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@alextheman/eslint-plugin": "^4.
|
|
22
|
+
"@alextheman/eslint-plugin": "^4.10.0",
|
|
23
23
|
"@types/node": "^25.0.3",
|
|
24
|
-
"alex-c-line": "^1.
|
|
24
|
+
"alex-c-line": "^1.10.0",
|
|
25
25
|
"dotenv-cli": "^11.0.0",
|
|
26
26
|
"eslint": "^9.39.2",
|
|
27
27
|
"eslint-plugin-perfectionist": "^5.0.0",
|