@alextheman/utility 3.8.0 → 3.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/README.md CHANGED
@@ -24,122 +24,3 @@ import { formatDateAndTime } from "@alextheman/utility";
24
24
  const myVariable: NonUndefined<string> = formatDateAndTime(new Date());
25
25
  // ...
26
26
  ```
27
-
28
- ## Contributing
29
-
30
- ### Creating a function
31
- #### Setup
32
- To create a new function in the package, you must first checkout a new branch. Do **not** commit directly on main.
33
-
34
- From there, create the skeleton of the function. This is just the function declaration itself, along with the arguments and their types, along with the return type.
35
-
36
- ```typescript
37
- function myFunction(firstArg: ArgType): ReturnType {
38
- // Implementation goes here
39
- }
40
-
41
- export default myFunction
42
- ```
43
-
44
- Note that every function that gets exported from this package **must** have a type annotation. This is also enforced by ESLint. This helps to make the return types extra explicit and more intentional.
45
-
46
- Once you have this, export the function from `src/functions/index.ts` so that consumers can import your function. Also export any types you may want to export near the bottom of the file:
47
-
48
- ```typescript
49
- export { default as addDaysToDate } from "src/functions/addDaysToDate";
50
- export { default as appendSemicolon } from "src/functions/appendSemicolon";
51
- export { default as camelToKebab } from "src/functions/camelToKebab";
52
- export { default as convertFileToBase64 } from "src/functions/convertFileToBase64";
53
- export { default as createFormData } from "src/functions/createFormData";
54
- export { default as fillArray } from "src/functions/fillArray";
55
- export { default as formatDateAndTime } from "src/functions/formatDateAndTime";
56
- // ...
57
- export { default as myFunction } from "src/functions/myFunction";
58
- // ...
59
-
60
- export type { MyFunctionOptions } from "src/functions/myFunction";
61
- ```
62
-
63
- #### Testing
64
-
65
- Every function must also be tested. Tests are located in the `tests` folder and follows roughly the same structure as `src`. We use Vitest for our tests, and instead of relying on the global test functions like you might do with Jest, we instead import each test function directly.
66
-
67
- Tests are generally structured in the following way:
68
-
69
- ```typescript
70
- import { describe, expect, test } from "vitest";
71
-
72
- import myFunction from "src/functions/myFunction";
73
-
74
- describe("myFunction", () => {
75
- test("Does a thing", () => {
76
- expect(myFunction("hello")).toBe("world");
77
- });
78
- test("Does another thing", () => {
79
- expect(myFunction("one")).toBe("two");
80
- });
81
- // ...
82
- });
83
- ```
84
-
85
- That is, we wrap all tests around a describe block grouping all related tests to that function together, then each test block tests a specific behaviour.
86
-
87
- Every function must at least have one test for the core behaviour of it. Of course, the more tests, the better, but at the very least, test the core behaviour of the function. From there, if you feel like there may be a few edge cases you want to verify the behaviour of, please add tests in for that as well.
88
-
89
- Some functions that we create may often end up taking in an array or object. Due to the nature of how JavaScript passes these, we must have non-mutation tests in place to prevent unintended mutation of the input array/object. The best way to do this is to use `Object.freeze()`, as that will ensure that we get an error if the function ever even tries to mutate the input.
90
-
91
- ```typescript
92
- describe("removeDuplicates", () => {
93
- describe("Mutation checks", () => {
94
- test("Does not mutate the original array", () => {
95
- const inputArray = Object.freeze([1, 1, 2, 3, 4]);
96
- // since the array has been frozen, this will give a TypeError if it tries to mutate the inputArray.
97
- removeDuplicates(inputArray);
98
- expect(inputArray).toEqual([1, 1, 2, 3, 4]);
99
- });
100
- });
101
- });
102
- ```
103
-
104
- Also, if the return type of the function is the same as one or more of the inputs, it's also often helpful to have a test that ensures the output returns a new reference in memory:
105
-
106
- ```typescript
107
- describe("removeDuplicates", () => {
108
- describe("Mutation checks", () => {
109
- test("Returns an array with a new reference in memory", () => {
110
- const inputArray = [1, 1, 2, 3, 4];
111
- const outputArray = removeDuplicates(inputArray);
112
- expect(outputArray).not.toBe(inputArray);
113
- });
114
- });
115
- });
116
- ```
117
-
118
- Note the use of `.toBe()` over `.toEqual()` here. This is because in this case, we are comparing the variable's memory reference to the output's memory reference rather than the actual contents of the array.
119
-
120
- ### Creating a type
121
-
122
- Creating a type works in a similar way to creating a function, in the sense that you create a new file for it, add it to `src/types/index.ts`, and test it. Yes, test it. It is possible to test type declarations using `expectTypeOf`. As an example:
123
-
124
- ```typescript
125
- import type { OptionalOnCondition } from "src/types";
126
-
127
- import { describe, expectTypeOf, test } from "vitest";
128
-
129
- describe("OptionalOnCondition", () => {
130
- test("Resolves to the type of the second type argument if first type argument is true", () => {
131
- expectTypeOf<OptionalOnCondition<true, string>>().toEqualTypeOf<string>();
132
- });
133
- test("Resolves to a union of the second type and undefined if first type argument is false", () => {
134
- expectTypeOf<OptionalOnCondition<false, string>>().toEqualTypeOf<string | undefined>();
135
- });
136
- });
137
- ```
138
-
139
- Note that when you actually run the tests using `npm test`, the tests will always pass even if the logic is incorrect. This is because type tests run with the TypeScript compiler so it will error in your editor and in linting, but it will never fail in runtime. As such, just remember to be extra careful with these type tests and remember that the actual test results for these show in the editor and not in runtime.
140
-
141
- ### Publishing
142
-
143
- Once you are happy with your changes, commit the changes to your branch, then change the version number. You can do this by running one of `npm run change-major`, `npm run change-minor`, or `npm run change-patch`. Major changes generally correspond to breaking changes (e.g. removing features, changing the build process substantially), minor changes correspond to non-breaking additions/deprecations, and patch changes are for the small things that aren't as noticeable. Note that your change will fail CI if you change the source code but forget to change the version number. From there, after your changes have been approved and merged, the publish script will automatically run, and if you remembered to change the version number, it will pass the publishing action.
144
-
145
- Version number changes must also **not** be part of your main commit(s) - they must be their own standalone commit. This helps to make it easier to revert changes if needed - if the version change is part of the main commit, that means that if we need to revert it for whatever reason, the version change also gets reverted, which is not really ideal as it makes re-publishing a bit harder.
package/dist/index.cjs CHANGED
@@ -94,7 +94,7 @@ const IntegerParsingError = /* @__PURE__ */ new TypeError("INTEGER_PARSING_ERROR
94
94
  /**
95
95
  * Converts a string to an integer and throws an error if it cannot be converted.
96
96
  *
97
- * @param string A string to convert into a number.
97
+ * @param string - A string to convert into a number.
98
98
  * @param radix - A value between 2 and 36 that specifies the base of the number in string. If this argument is not supplied, strings with a prefix of '0x' are considered hexadecimal. All other strings are considered decimal.
99
99
  *
100
100
  * @throws {TypeError} If the provided string cannot safely be converted to an integer.
@@ -711,6 +711,27 @@ function parseZodSchema(schema, data) {
711
711
  }
712
712
  var parseZodSchema_default = parseZodSchema;
713
713
 
714
+ //#endregion
715
+ //#region src/functions/parsers/parseVersionType.ts
716
+ const versionTypeSchema = zod.default.enum([
717
+ "major",
718
+ "minor",
719
+ "patch"
720
+ ]);
721
+ /**
722
+ * Parses the input and verifies it is a valid software version type (i.e. `"major" | "minor" | "patch"`)
723
+ *
724
+ * @param data - The data to parse.
725
+ *
726
+ * @throws {DataError} If the data does not match one of the allowed version types (`"major" | "minor" | "patch"`).
727
+ *
728
+ * @returns The given version type if allowed.
729
+ */
730
+ function parseVersionType(data) {
731
+ return parseZodSchema_default(versionTypeSchema, data);
732
+ }
733
+ var parseVersionType_default = parseVersionType;
734
+
714
735
  //#endregion
715
736
  //#region src/functions/recursive/deepCopy.ts
716
737
  function callDeepCopy(input) {
@@ -1117,6 +1138,31 @@ function determineVersionType(version) {
1117
1138
  }
1118
1139
  var determineVersionType_default = determineVersionType;
1119
1140
 
1141
+ //#endregion
1142
+ //#region src/functions/versioning/incrementVersion.ts
1143
+ /**
1144
+ * Increments the given input version depending on the given increment type.
1145
+ *
1146
+ * @param version - The version to increment
1147
+ * @param incrementType - The type of increment. Can be one of the following:
1148
+ * - `"major"`: Change the major version `v1.2.3` → `v2.0.0`
1149
+ * - `"minor"`: Change the minor version `v1.2.3` → `v1.3.0`
1150
+ * - `"patch"`: Change the patch version `v1.2.3` → `v1.2.4`
1151
+ * @param options - Extra options to apply.
1152
+ *
1153
+ * @returns A new string representing the version with the increment applied.
1154
+ */
1155
+ function incrementVersion(version, incrementType, options) {
1156
+ const [major, minor, patch] = getIndividualVersionNumbers_default(version);
1157
+ const newVersion = {
1158
+ major: `${major + 1}.0.0`,
1159
+ minor: `${major}.${minor + 1}.0`,
1160
+ patch: `${major}.${minor}.${patch + 1}`
1161
+ }[incrementType];
1162
+ return parseVersion_default(newVersion, { omitPrefix: options?.omitPrefix });
1163
+ }
1164
+ var incrementVersion_default = incrementVersion;
1165
+
1120
1166
  //#endregion
1121
1167
  exports.APIError = APIError_default;
1122
1168
  exports.DataError = DataError_default;
@@ -1137,6 +1183,7 @@ exports.getIndividualVersionNumbers = getIndividualVersionNumbers_default;
1137
1183
  exports.getRandomNumber = getRandomNumber_default;
1138
1184
  exports.getRecordKeys = getRecordKeys_default;
1139
1185
  exports.httpErrorCodeLookup = httpErrorCodeLookup;
1186
+ exports.incrementVersion = incrementVersion_default;
1140
1187
  exports.interpolate = interpolate_default;
1141
1188
  exports.interpolateObjects = interpolateObjects_default;
1142
1189
  exports.isAnniversary = isAnniversary_default;
@@ -1158,6 +1205,7 @@ exports.parseFormData = parseFormData_default;
1158
1205
  exports.parseIntStrict = parseIntStrict_default;
1159
1206
  exports.parseUUID = UUID_default;
1160
1207
  exports.parseVersion = parseVersion_default;
1208
+ exports.parseVersionType = parseVersionType_default;
1161
1209
  exports.parseZodSchema = parseZodSchema_default;
1162
1210
  exports.randomiseArray = randomiseArray_default;
1163
1211
  exports.range = range_default;
package/dist/index.d.cts CHANGED
@@ -458,7 +458,7 @@ declare function parseFormData(formData: FormData): Record<string, string | Blob
458
458
  /**
459
459
  * Converts a string to an integer and throws an error if it cannot be converted.
460
460
  *
461
- * @param string A string to convert into a number.
461
+ * @param string - A string to convert into a number.
462
462
  * @param radix - A value between 2 and 36 that specifies the base of the number in string. If this argument is not supplied, strings with a prefix of '0x' are considered hexadecimal. All other strings are considered decimal.
463
463
  *
464
464
  * @throws {TypeError} If the provided string cannot safely be converted to an integer.
@@ -467,6 +467,24 @@ declare function parseFormData(formData: FormData): Record<string, string | Blob
467
467
  */
468
468
  declare function parseIntStrict(string: string, radix?: number): number;
469
469
  //#endregion
470
+ //#region src/functions/parsers/parseVersionType.d.ts
471
+ declare const versionTypeSchema: z.ZodEnum<{
472
+ major: "major";
473
+ minor: "minor";
474
+ patch: "patch";
475
+ }>;
476
+ type VersionType = z.infer<typeof versionTypeSchema>;
477
+ /**
478
+ * Parses the input and verifies it is a valid software version type (i.e. `"major" | "minor" | "patch"`)
479
+ *
480
+ * @param data - The data to parse.
481
+ *
482
+ * @throws {DataError} If the data does not match one of the allowed version types (`"major" | "minor" | "patch"`).
483
+ *
484
+ * @returns The given version type if allowed.
485
+ */
486
+ declare function parseVersionType(data: unknown): VersionType;
487
+ //#endregion
470
488
  //#region src/functions/parsers/parseZodSchema.d.ts
471
489
  /**
472
490
  * An alternative function to zodSchema.parse() that can be used to strictly parse Zod schemas.
@@ -702,7 +720,6 @@ declare function removeIndents(options: RemoveIndentsOptions): RemoveIndentsFunc
702
720
  declare function removeIndents(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
703
721
  //#endregion
704
722
  //#region src/functions/versioning/determineVersionType.d.ts
705
- type VersionType = "major" | "minor" | "patch";
706
723
  /**
707
724
  * Determines whether the given version is a major, minor, or patch version.
708
725
  *
@@ -722,8 +739,28 @@ declare function determineVersionType(version: string): VersionType;
722
739
  */
723
740
  declare function getIndividualVersionNumbers(version: string): [number, number, number];
724
741
  //#endregion
742
+ //#region src/functions/versioning/incrementVersion.d.ts
743
+ interface IncrementVersionOptions {
744
+ /** Whether to omit the `v` prefix from the output version or not. */
745
+ omitPrefix?: boolean;
746
+ }
747
+ /**
748
+ * Increments the given input version depending on the given increment type.
749
+ *
750
+ * @param version - The version to increment
751
+ * @param incrementType - The type of increment. Can be one of the following:
752
+ * - `"major"`: Change the major version `v1.2.3` → `v2.0.0`
753
+ * - `"minor"`: Change the minor version `v1.2.3` → `v1.3.0`
754
+ * - `"patch"`: Change the patch version `v1.2.3` → `v1.2.4`
755
+ * @param options - Extra options to apply.
756
+ *
757
+ * @returns A new string representing the version with the increment applied.
758
+ */
759
+ declare function incrementVersion(version: string, incrementType: VersionType, options?: IncrementVersionOptions): string;
760
+ //#endregion
725
761
  //#region src/functions/versioning/parseVersion.d.ts
726
762
  interface ParseVersionOptions {
763
+ /** Whether to omit the `v` prefix from the output version or not. */
727
764
  omitPrefix?: boolean;
728
765
  }
729
766
  /**
@@ -740,4 +777,4 @@ interface ParseVersionOptions {
740
777
  */
741
778
  declare function parseVersion(input: string, options?: ParseVersionOptions): string;
742
779
  //#endregion
743
- export { APIError, ArrayElement, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DeepReadonly, DisallowUndefined, Email, Env, FormDataArrayResolutionStrategy, FormDataNullableResolutionStrategy, HTTPErrorCode, IgnoreCase, KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, OptionalOnCondition, RecordKey, RemoveIndentsFunction, RemoveIndentsOptions, StringListToArrayOptions, UUID, VERSION_NUMBER_REGEX, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, determineVersionType, fillArray, formatDateAndTime, getIndividualVersionNumbers, getRandomNumber, getRecordKeys, httpErrorCodeLookup, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, normaliseImportPath, normaliseIndents, normalizeImportPath, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEmail, parseEnv, parseFormData, parseIntStrict, parseUUID, parseVersion, parseZodSchema, randomiseArray, range, removeDuplicates, removeIndents, stringListToArray, stringToBoolean, truncate, wait };
780
+ export { APIError, ArrayElement, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DeepReadonly, DisallowUndefined, Email, Env, FormDataArrayResolutionStrategy, FormDataNullableResolutionStrategy, HTTPErrorCode, IgnoreCase, IncrementVersionOptions, KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, OptionalOnCondition, ParseVersionOptions, RecordKey, RemoveIndentsFunction, RemoveIndentsOptions, StringListToArrayOptions, UUID, 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, parseEmail, parseEnv, parseFormData, parseIntStrict, parseUUID, parseVersion, parseVersionType, parseZodSchema, randomiseArray, range, removeDuplicates, removeIndents, stringListToArray, stringToBoolean, truncate, wait };
package/dist/index.d.ts CHANGED
@@ -458,7 +458,7 @@ declare function parseFormData(formData: FormData): Record<string, string | Blob
458
458
  /**
459
459
  * Converts a string to an integer and throws an error if it cannot be converted.
460
460
  *
461
- * @param string A string to convert into a number.
461
+ * @param string - A string to convert into a number.
462
462
  * @param radix - A value between 2 and 36 that specifies the base of the number in string. If this argument is not supplied, strings with a prefix of '0x' are considered hexadecimal. All other strings are considered decimal.
463
463
  *
464
464
  * @throws {TypeError} If the provided string cannot safely be converted to an integer.
@@ -467,6 +467,24 @@ declare function parseFormData(formData: FormData): Record<string, string | Blob
467
467
  */
468
468
  declare function parseIntStrict(string: string, radix?: number): number;
469
469
  //#endregion
470
+ //#region src/functions/parsers/parseVersionType.d.ts
471
+ declare const versionTypeSchema: z.ZodEnum<{
472
+ major: "major";
473
+ minor: "minor";
474
+ patch: "patch";
475
+ }>;
476
+ type VersionType = z.infer<typeof versionTypeSchema>;
477
+ /**
478
+ * Parses the input and verifies it is a valid software version type (i.e. `"major" | "minor" | "patch"`)
479
+ *
480
+ * @param data - The data to parse.
481
+ *
482
+ * @throws {DataError} If the data does not match one of the allowed version types (`"major" | "minor" | "patch"`).
483
+ *
484
+ * @returns The given version type if allowed.
485
+ */
486
+ declare function parseVersionType(data: unknown): VersionType;
487
+ //#endregion
470
488
  //#region src/functions/parsers/parseZodSchema.d.ts
471
489
  /**
472
490
  * An alternative function to zodSchema.parse() that can be used to strictly parse Zod schemas.
@@ -702,7 +720,6 @@ declare function removeIndents(options: RemoveIndentsOptions): RemoveIndentsFunc
702
720
  declare function removeIndents(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
703
721
  //#endregion
704
722
  //#region src/functions/versioning/determineVersionType.d.ts
705
- type VersionType = "major" | "minor" | "patch";
706
723
  /**
707
724
  * Determines whether the given version is a major, minor, or patch version.
708
725
  *
@@ -722,8 +739,28 @@ declare function determineVersionType(version: string): VersionType;
722
739
  */
723
740
  declare function getIndividualVersionNumbers(version: string): [number, number, number];
724
741
  //#endregion
742
+ //#region src/functions/versioning/incrementVersion.d.ts
743
+ interface IncrementVersionOptions {
744
+ /** Whether to omit the `v` prefix from the output version or not. */
745
+ omitPrefix?: boolean;
746
+ }
747
+ /**
748
+ * Increments the given input version depending on the given increment type.
749
+ *
750
+ * @param version - The version to increment
751
+ * @param incrementType - The type of increment. Can be one of the following:
752
+ * - `"major"`: Change the major version `v1.2.3` → `v2.0.0`
753
+ * - `"minor"`: Change the minor version `v1.2.3` → `v1.3.0`
754
+ * - `"patch"`: Change the patch version `v1.2.3` → `v1.2.4`
755
+ * @param options - Extra options to apply.
756
+ *
757
+ * @returns A new string representing the version with the increment applied.
758
+ */
759
+ declare function incrementVersion(version: string, incrementType: VersionType, options?: IncrementVersionOptions): string;
760
+ //#endregion
725
761
  //#region src/functions/versioning/parseVersion.d.ts
726
762
  interface ParseVersionOptions {
763
+ /** Whether to omit the `v` prefix from the output version or not. */
727
764
  omitPrefix?: boolean;
728
765
  }
729
766
  /**
@@ -740,4 +777,4 @@ interface ParseVersionOptions {
740
777
  */
741
778
  declare function parseVersion(input: string, options?: ParseVersionOptions): string;
742
779
  //#endregion
743
- export { APIError, type ArrayElement, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, DataError, type DeepReadonly, type DisallowUndefined, type Email, type Env, type FormDataArrayResolutionStrategy, type FormDataNullableResolutionStrategy, type HTTPErrorCode, type IgnoreCase, KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, type NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, type OptionalOnCondition, type RecordKey, RemoveIndentsFunction, RemoveIndentsOptions, type StringListToArrayOptions, type UUID, VERSION_NUMBER_REGEX, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, determineVersionType, fillArray, formatDateAndTime, getIndividualVersionNumbers, getRandomNumber, getRecordKeys, httpErrorCodeLookup, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, normaliseImportPath, normaliseIndents, normalizeImportPath, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEmail, parseEnv, parseFormData, parseIntStrict, parseUUID, parseVersion, parseZodSchema, randomiseArray, range, removeDuplicates, removeIndents, stringListToArray, stringToBoolean, truncate, wait };
780
+ export { APIError, type ArrayElement, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, DataError, type DeepReadonly, type DisallowUndefined, type Email, type Env, type FormDataArrayResolutionStrategy, type FormDataNullableResolutionStrategy, type HTTPErrorCode, type IgnoreCase, type IncrementVersionOptions, KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, type NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, type OptionalOnCondition, type ParseVersionOptions, type RecordKey, RemoveIndentsFunction, RemoveIndentsOptions, type StringListToArrayOptions, type UUID, 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, parseEmail, parseEnv, parseFormData, parseIntStrict, parseUUID, parseVersion, parseVersionType, parseZodSchema, randomiseArray, range, removeDuplicates, removeIndents, stringListToArray, stringToBoolean, truncate, wait };
package/dist/index.js CHANGED
@@ -65,7 +65,7 @@ const IntegerParsingError = /* @__PURE__ */ new TypeError("INTEGER_PARSING_ERROR
65
65
  /**
66
66
  * Converts a string to an integer and throws an error if it cannot be converted.
67
67
  *
68
- * @param string A string to convert into a number.
68
+ * @param string - A string to convert into a number.
69
69
  * @param radix - A value between 2 and 36 that specifies the base of the number in string. If this argument is not supplied, strings with a prefix of '0x' are considered hexadecimal. All other strings are considered decimal.
70
70
  *
71
71
  * @throws {TypeError} If the provided string cannot safely be converted to an integer.
@@ -682,6 +682,27 @@ function parseZodSchema(schema, data) {
682
682
  }
683
683
  var parseZodSchema_default = parseZodSchema;
684
684
 
685
+ //#endregion
686
+ //#region src/functions/parsers/parseVersionType.ts
687
+ const versionTypeSchema = z.enum([
688
+ "major",
689
+ "minor",
690
+ "patch"
691
+ ]);
692
+ /**
693
+ * Parses the input and verifies it is a valid software version type (i.e. `"major" | "minor" | "patch"`)
694
+ *
695
+ * @param data - The data to parse.
696
+ *
697
+ * @throws {DataError} If the data does not match one of the allowed version types (`"major" | "minor" | "patch"`).
698
+ *
699
+ * @returns The given version type if allowed.
700
+ */
701
+ function parseVersionType(data) {
702
+ return parseZodSchema_default(versionTypeSchema, data);
703
+ }
704
+ var parseVersionType_default = parseVersionType;
705
+
685
706
  //#endregion
686
707
  //#region src/functions/recursive/deepCopy.ts
687
708
  function callDeepCopy(input) {
@@ -1089,4 +1110,29 @@ function determineVersionType(version) {
1089
1110
  var determineVersionType_default = determineVersionType;
1090
1111
 
1091
1112
  //#endregion
1092
- export { APIError_default as APIError, DataError_default as DataError, NAMESPACE_EXPORT_REGEX_default as NAMESPACE_EXPORT_REGEX, VERSION_NUMBER_REGEX_default as VERSION_NUMBER_REGEX, addDaysToDate_default as addDaysToDate, appendSemicolon_default as appendSemicolon, camelToKebab_default as camelToKebab, convertFileToBase64_default as convertFileToBase64, createFormData_default as createFormData, createTemplateStringsArray_default as createTemplateStringsArray, deepCopy_default as deepCopy, deepFreeze_default as deepFreeze, determineVersionType_default as determineVersionType, fillArray_default as fillArray, formatDateAndTime_default as formatDateAndTime, getIndividualVersionNumbers_default as getIndividualVersionNumbers, getRandomNumber_default as getRandomNumber, getRecordKeys_default as getRecordKeys, httpErrorCodeLookup, interpolate_default as interpolate, interpolateObjects_default as interpolateObjects, isAnniversary_default as isAnniversary, isLeapYear_default as isLeapYear, isMonthlyMultiple_default as isMonthlyMultiple, isOrdered_default as isOrdered, isSameDate_default as isSameDate, kebabToCamel_default as kebabToCamel, normaliseImportPath, normaliseIndents_default as normaliseIndents, normalizeImportPath_default as normalizeImportPath, normalizeIndents, omitProperties_default as omitProperties, paralleliseArrays_default as paralleliseArrays, parseBoolean_default as parseBoolean, Email_default as parseEmail, parseEnv_default as parseEnv, parseFormData_default as parseFormData, parseIntStrict_default as parseIntStrict, UUID_default as parseUUID, parseVersion_default as parseVersion, parseZodSchema_default as parseZodSchema, randomiseArray_default as randomiseArray, range_default as range, removeDuplicates_default as removeDuplicates, removeIndents_default as removeIndents, stringListToArray_default as stringListToArray, stringToBoolean, truncate_default as truncate, wait_default as wait };
1113
+ //#region src/functions/versioning/incrementVersion.ts
1114
+ /**
1115
+ * Increments the given input version depending on the given increment type.
1116
+ *
1117
+ * @param version - The version to increment
1118
+ * @param incrementType - The type of increment. Can be one of the following:
1119
+ * - `"major"`: Change the major version `v1.2.3` → `v2.0.0`
1120
+ * - `"minor"`: Change the minor version `v1.2.3` → `v1.3.0`
1121
+ * - `"patch"`: Change the patch version `v1.2.3` → `v1.2.4`
1122
+ * @param options - Extra options to apply.
1123
+ *
1124
+ * @returns A new string representing the version with the increment applied.
1125
+ */
1126
+ function incrementVersion(version, incrementType, options) {
1127
+ const [major, minor, patch] = getIndividualVersionNumbers_default(version);
1128
+ const newVersion = {
1129
+ major: `${major + 1}.0.0`,
1130
+ minor: `${major}.${minor + 1}.0`,
1131
+ patch: `${major}.${minor}.${patch + 1}`
1132
+ }[incrementType];
1133
+ return parseVersion_default(newVersion, { omitPrefix: options?.omitPrefix });
1134
+ }
1135
+ var incrementVersion_default = incrementVersion;
1136
+
1137
+ //#endregion
1138
+ export { APIError_default as APIError, DataError_default as DataError, NAMESPACE_EXPORT_REGEX_default as NAMESPACE_EXPORT_REGEX, VERSION_NUMBER_REGEX_default as VERSION_NUMBER_REGEX, addDaysToDate_default as addDaysToDate, appendSemicolon_default as appendSemicolon, camelToKebab_default as camelToKebab, convertFileToBase64_default as convertFileToBase64, createFormData_default as createFormData, createTemplateStringsArray_default as createTemplateStringsArray, deepCopy_default as deepCopy, deepFreeze_default as deepFreeze, determineVersionType_default as determineVersionType, fillArray_default as fillArray, formatDateAndTime_default as formatDateAndTime, getIndividualVersionNumbers_default as getIndividualVersionNumbers, getRandomNumber_default as getRandomNumber, getRecordKeys_default as getRecordKeys, httpErrorCodeLookup, incrementVersion_default as incrementVersion, interpolate_default as interpolate, interpolateObjects_default as interpolateObjects, isAnniversary_default as isAnniversary, isLeapYear_default as isLeapYear, isMonthlyMultiple_default as isMonthlyMultiple, isOrdered_default as isOrdered, isSameDate_default as isSameDate, kebabToCamel_default as kebabToCamel, normaliseImportPath, normaliseIndents_default as normaliseIndents, normalizeImportPath_default as normalizeImportPath, normalizeIndents, omitProperties_default as omitProperties, paralleliseArrays_default as paralleliseArrays, parseBoolean_default as parseBoolean, Email_default as parseEmail, parseEnv_default as parseEnv, parseFormData_default as parseFormData, parseIntStrict_default as parseIntStrict, UUID_default as parseUUID, parseVersion_default as parseVersion, parseVersionType_default as parseVersionType, parseZodSchema_default as parseZodSchema, randomiseArray_default as randomiseArray, range_default as range, removeDuplicates_default as removeDuplicates, removeIndents_default as removeIndents, stringListToArray_default as stringListToArray, stringToBoolean, truncate_default as truncate, wait_default as wait };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alextheman/utility",
3
- "version": "3.8.0",
3
+ "version": "3.10.0",
4
4
  "description": "Helpful utility functions",
5
5
  "repository": {
6
6
  "type": "git",