@alextheman/utility 4.1.0 → 4.2.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
@@ -163,6 +163,111 @@ var DataError = class extends Error {
163
163
  };
164
164
  var DataError_default = DataError;
165
165
 
166
+ //#endregion
167
+ //#region src/types/VersionType.ts
168
+ const VersionType = {
169
+ MAJOR: "major",
170
+ MINOR: "minor",
171
+ PATCH: "patch"
172
+ };
173
+
174
+ //#endregion
175
+ //#region src/types/VersionNumber.ts
176
+ /** Represents a software version number, considered to be made up of a major, minor, and patch part. */
177
+ var VersionNumber = class VersionNumber {
178
+ /** The major number. Increments when a feature is removed or changed in a way that is not backwards-compatible with the previous release. */
179
+ major = 0;
180
+ /** The minor number. Increments when a new feature is added/deprecated and is expected to be backwards-compatible with the previous release. */
181
+ minor = 0;
182
+ /** The patch number. Increments when the next release is fixing a bug or doing a small refactor that should not be noticeable in practice. */
183
+ patch = 0;
184
+ static NON_NEGATIVE_TUPLE_ERROR = "Input array must be a tuple of three non-negative integers.";
185
+ /**
186
+ * @param input - The input to create a new instance of `VersionNumber` from.
187
+ */
188
+ constructor(input) {
189
+ if (input instanceof VersionNumber) {
190
+ this.major = input.major;
191
+ this.minor = input.minor;
192
+ this.patch = input.patch;
193
+ } else if (typeof input === "string") {
194
+ if (!RegExp(VERSION_NUMBER_REGEX_default).test(input)) throw new DataError_default(input, "INVALID_VERSION", `"${input}" is not a valid version number. Version numbers must be of the format "X.Y.Z" or "vX.Y.Z", where X, Y, and Z are non-negative integers.`);
195
+ const [major, minor, patch] = VersionNumber.formatString(input, { omitPrefix: true }).split(".").map((number) => {
196
+ return parseIntStrict_default(number);
197
+ });
198
+ this.major = major;
199
+ this.minor = minor;
200
+ this.patch = patch;
201
+ } else if (Array.isArray(input)) {
202
+ if (input.length !== 3) throw new DataError_default(input, "INVALID_LENGTH", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
203
+ const [major, minor, patch] = input.map((number) => {
204
+ const parsedInteger = parseIntStrict_default(number?.toString());
205
+ if (parsedInteger < 0) throw new DataError_default(input, "NON_POSITIVE_INPUTS", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
206
+ return parsedInteger;
207
+ });
208
+ this.major = major;
209
+ this.minor = minor;
210
+ this.patch = patch;
211
+ }
212
+ }
213
+ static formatString(input, options) {
214
+ if (options?.omitPrefix) return input.startsWith("v") ? input.slice(1) : input;
215
+ return input.startsWith("v") ? input : `v${input}`;
216
+ }
217
+ /**
218
+ * Get a string representation of the current version number.
219
+ *
220
+ * @param options - Extra additional options to apply.
221
+ *
222
+ * @returns A stringified representation of the current version number, leaving out the prefix if `omitPrefix` option was set to true.
223
+ */
224
+ toString(options) {
225
+ const rawString = `${this.major}.${this.minor}.${this.patch}`;
226
+ return VersionNumber.formatString(rawString, options);
227
+ }
228
+ /**
229
+ * Gets the current version type of the current instance of `VersionNumber`.
230
+ *
231
+ * @returns Either `"major"`, `"minor"`, or `"patch"`, depending on the version type.
232
+ */
233
+ get type() {
234
+ if (this.minor === 0 && this.patch === 0) return VersionType.MAJOR;
235
+ if (this.patch === 0) return VersionType.MINOR;
236
+ return VersionType.PATCH;
237
+ }
238
+ /**
239
+ * Determines whether the current instance of `VersionNumber` is a major, minor, or patch version.
240
+ *
241
+ * @param incrementType - The type of increment. Can be one of the following:
242
+ * - `"major"`: Change the major version `v1.2.3` → `v2.0.0`
243
+ * - `"minor"`: Change the minor version `v1.2.3` → `v1.3.0`
244
+ * - `"patch"`: Change the patch version `v1.2.3` → `v1.2.4`
245
+ *
246
+ * @returns A new instance of `VersionNumber` with the increment applied.
247
+ */
248
+ increment(incrementType) {
249
+ const newVersion = {
250
+ major: [
251
+ this.major + 1,
252
+ 0,
253
+ 0
254
+ ],
255
+ minor: [
256
+ this.major,
257
+ this.minor + 1,
258
+ 0
259
+ ],
260
+ patch: [
261
+ this.major,
262
+ this.minor,
263
+ this.patch + 1
264
+ ]
265
+ }[incrementType];
266
+ return new VersionNumber(newVersion);
267
+ }
268
+ };
269
+ var VersionNumber_default = VersionNumber;
270
+
166
271
  //#endregion
167
272
  //#region src/functions/parsers/parseIntStrict.ts
168
273
  /**
@@ -701,11 +806,6 @@ var parseFormData_default = parseFormData;
701
806
 
702
807
  //#endregion
703
808
  //#region src/functions/parsers/parseVersionType.ts
704
- const versionTypeSchema = zod.default.enum([
705
- "major",
706
- "minor",
707
- "patch"
708
- ]);
709
809
  /**
710
810
  * Parses the input and verifies it is a valid software version type (i.e. `"major" | "minor" | "patch"`)
711
811
  *
@@ -716,7 +816,7 @@ const versionTypeSchema = zod.default.enum([
716
816
  * @returns The given version type if allowed.
717
817
  */
718
818
  function parseVersionType(data) {
719
- return parseZodSchema_default(versionTypeSchema, data, new DataError_default(data, "INVALID_VERSION_TYPE", "The provided version type must be one of `major | minor | patch`"));
819
+ return parseZodSchema_default(zod.default.enum(VersionType), data, new DataError_default(data, "INVALID_VERSION_TYPE", "The provided version type must be one of `major | minor | patch`"));
720
820
  }
721
821
  var parseVersionType_default = parseVersionType;
722
822
 
@@ -1064,6 +1164,8 @@ var normaliseIndents_default = normaliseIndents;
1064
1164
  *
1065
1165
  * Valid formats: `X.Y.Z` or `vX.Y.Z`, where X, Y, and Z are non-negative integers.
1066
1166
  *
1167
+ * @deprecated This function does not support the new class-based handling of VersionNumber. Please use `new VersionNumber(input)` instead.
1168
+ *
1067
1169
  * @param input - The version string to parse.
1068
1170
  * @param options - Extra options to apply.
1069
1171
  *
@@ -1083,6 +1185,13 @@ var parseVersion_default = parseVersion;
1083
1185
  /**
1084
1186
  * Gets the individual version numbers from a given version number as a tuple of numbers.
1085
1187
  *
1188
+ * @deprecated This function does not support the new class-based handling of VersionNumber. Please use one of the following instead:
1189
+ * ```typescript
1190
+ * new VersionNumber(version).major
1191
+ * new VersionNumber(version).minor
1192
+ * new VersionNumber(version).patch
1193
+ * ```
1194
+ *
1086
1195
  * @param version - The version number.
1087
1196
  *
1088
1197
  * @returns A tuple of three numbers indicating `[major, minor, patch]`.
@@ -1099,6 +1208,8 @@ var getIndividualVersionNumbers_default = getIndividualVersionNumbers;
1099
1208
  /**
1100
1209
  * Determines whether the given version is a major, minor, or patch version.
1101
1210
  *
1211
+ * @deprecated This function does not support the new class-based handling of VersionNumber. Please use `new VersionNumber(version).type` instead.
1212
+ *
1102
1213
  * @param version - The version number.
1103
1214
  *
1104
1215
  * @returns Either `"major"`, `"minor"`, or `"patch"`, depending on the version type.
@@ -1116,6 +1227,8 @@ var determineVersionType_default = determineVersionType;
1116
1227
  /**
1117
1228
  * Increments the given input version depending on the given increment type.
1118
1229
  *
1230
+ * @deprecated This function does not support the new class-based handling of VersionNumber. Please use `new VersionNumber(version).increment(incrementType)` instead.
1231
+ *
1119
1232
  * @param version - The version to increment
1120
1233
  * @param incrementType - The type of increment. Can be one of the following:
1121
1234
  * - `"major"`: Change the major version `v1.2.3` → `v2.0.0`
@@ -1141,6 +1254,8 @@ exports.APIError = APIError_default;
1141
1254
  exports.DataError = DataError_default;
1142
1255
  exports.NAMESPACE_EXPORT_REGEX = NAMESPACE_EXPORT_REGEX_default;
1143
1256
  exports.VERSION_NUMBER_REGEX = VERSION_NUMBER_REGEX_default;
1257
+ exports.VersionNumber = VersionNumber_default;
1258
+ exports.VersionType = VersionType;
1144
1259
  exports.addDaysToDate = addDaysToDate_default;
1145
1260
  exports.appendSemicolon = appendSemicolon_default;
1146
1261
  exports.camelToKebab = camelToKebab_default;
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import z, { ZodType, core, z as z$1 } from "zod";
1
+ import { ZodType, core, z } from "zod";
2
2
 
3
3
  //#region src/constants/NAMESPACE_EXPORT_REGEX.d.ts
4
4
  declare const NAMESPACE_EXPORT_REGEX = "export\\s+\\*\\s+from";
@@ -222,6 +222,71 @@ declare class DataError extends Error {
222
222
  static check(input: unknown): input is DataError;
223
223
  }
224
224
  //#endregion
225
+ //#region src/types/RecordKey.d.ts
226
+ /** Represents the native Record's possible key type. */
227
+ type RecordKey = string | number | symbol;
228
+ //#endregion
229
+ //#region src/types/CreateEnumType.d.ts
230
+ /**
231
+ * Get the value types from a const object so the object can behave similarly to an enum.
232
+ *
233
+ * @template ObjectType - The type of the object to get the value types for.
234
+ */
235
+ type CreateEnumType<ObjectType extends Record<RecordKey, unknown>> = ObjectType[keyof ObjectType];
236
+ //#endregion
237
+ //#region src/types/VersionType.d.ts
238
+ declare const VersionType: {
239
+ readonly MAJOR: "major";
240
+ readonly MINOR: "minor";
241
+ readonly PATCH: "patch";
242
+ };
243
+ type VersionType = CreateEnumType<typeof VersionType>;
244
+ //#endregion
245
+ //#region src/types/VersionNumber.d.ts
246
+ interface ToStringOptions {
247
+ omitPrefix?: boolean;
248
+ }
249
+ /** Represents a software version number, considered to be made up of a major, minor, and patch part. */
250
+ declare class VersionNumber {
251
+ /** The major number. Increments when a feature is removed or changed in a way that is not backwards-compatible with the previous release. */
252
+ readonly major: number;
253
+ /** The minor number. Increments when a new feature is added/deprecated and is expected to be backwards-compatible with the previous release. */
254
+ readonly minor: number;
255
+ /** The patch number. Increments when the next release is fixing a bug or doing a small refactor that should not be noticeable in practice. */
256
+ readonly patch: number;
257
+ private static readonly NON_NEGATIVE_TUPLE_ERROR;
258
+ /**
259
+ * @param input - The input to create a new instance of `VersionNumber` from.
260
+ */
261
+ constructor(input: string | [number, number, number] | VersionNumber);
262
+ private static formatString;
263
+ /**
264
+ * Get a string representation of the current version number.
265
+ *
266
+ * @param options - Extra additional options to apply.
267
+ *
268
+ * @returns A stringified representation of the current version number, leaving out the prefix if `omitPrefix` option was set to true.
269
+ */
270
+ toString(options?: ToStringOptions): string;
271
+ /**
272
+ * Gets the current version type of the current instance of `VersionNumber`.
273
+ *
274
+ * @returns Either `"major"`, `"minor"`, or `"patch"`, depending on the version type.
275
+ */
276
+ get type(): VersionType;
277
+ /**
278
+ * Determines whether the current instance of `VersionNumber` is a major, minor, or patch version.
279
+ *
280
+ * @param incrementType - The type of increment. Can be one of the following:
281
+ * - `"major"`: Change the major version `v1.2.3` → `v2.0.0`
282
+ * - `"minor"`: Change the minor version `v1.2.3` → `v1.3.0`
283
+ * - `"patch"`: Change the patch version `v1.2.3` → `v1.2.4`
284
+ *
285
+ * @returns A new instance of `VersionNumber` with the increment applied.
286
+ */
287
+ increment(incrementType: VersionType): VersionNumber;
288
+ }
289
+ //#endregion
225
290
  //#region src/types/ArrayElement.d.ts
226
291
  /**
227
292
  * Gets the individual element types from an array type.
@@ -263,10 +328,6 @@ type NonUndefined<InputType> = InputType extends undefined ? never : InputType;
263
328
  */
264
329
  type OptionalOnCondition<Condition extends boolean, ResolvedTypeIfTrue> = Condition extends true ? ResolvedTypeIfTrue : ResolvedTypeIfTrue | undefined;
265
330
  //#endregion
266
- //#region src/types/RecordKey.d.ts
267
- /** Represents the native Record's possible key type. */
268
- type RecordKey = string | number | symbol;
269
- //#endregion
270
331
  //#region src/functions/miscellaneous/createFormData.d.ts
271
332
  type FormDataNullableResolutionStrategy = "stringify" | "empty" | "omit";
272
333
  type FormDataArrayResolutionStrategy = "stringify" | "multiple";
@@ -395,13 +456,13 @@ declare function omitProperties<ObjectType extends Record<string, unknown> | Rea
395
456
  declare function parseBoolean(inputString: string): boolean;
396
457
  //#endregion
397
458
  //#region src/functions/parsers/parseEnv.d.ts
398
- declare const envSchema: z$1.ZodEnum<{
459
+ declare const envSchema: z.ZodEnum<{
399
460
  test: "test";
400
461
  development: "development";
401
462
  production: "production";
402
463
  }>;
403
464
  /** Represents the most common development environments */
404
- type Env = z$1.infer<typeof envSchema>;
465
+ type Env = z.infer<typeof envSchema>;
405
466
  /**
406
467
  * Parses the input and verifies it matches one of the environments allowed by the Env types ("test" | "development" | "production").
407
468
  *
@@ -448,12 +509,6 @@ declare function parseFormData(formData: FormData): Record<string, string | Blob
448
509
  declare function parseIntStrict(string: string, radix?: number): number;
449
510
  //#endregion
450
511
  //#region src/functions/parsers/parseVersionType.d.ts
451
- declare const versionTypeSchema: z.ZodEnum<{
452
- major: "major";
453
- minor: "minor";
454
- patch: "patch";
455
- }>;
456
- type VersionType = z.infer<typeof versionTypeSchema>;
457
512
  /**
458
513
  * Parses the input and verifies it is a valid software version type (i.e. `"major" | "minor" | "patch"`)
459
514
  *
@@ -693,6 +748,8 @@ declare const normalizeIndents: typeof normaliseIndents;
693
748
  /**
694
749
  * Determines whether the given version is a major, minor, or patch version.
695
750
  *
751
+ * @deprecated This function does not support the new class-based handling of VersionNumber. Please use `new VersionNumber(version).type` instead.
752
+ *
696
753
  * @param version - The version number.
697
754
  *
698
755
  * @returns Either `"major"`, `"minor"`, or `"patch"`, depending on the version type.
@@ -703,6 +760,13 @@ declare function determineVersionType(version: string): VersionType;
703
760
  /**
704
761
  * Gets the individual version numbers from a given version number as a tuple of numbers.
705
762
  *
763
+ * @deprecated This function does not support the new class-based handling of VersionNumber. Please use one of the following instead:
764
+ * ```typescript
765
+ * new VersionNumber(version).major
766
+ * new VersionNumber(version).minor
767
+ * new VersionNumber(version).patch
768
+ * ```
769
+ *
706
770
  * @param version - The version number.
707
771
  *
708
772
  * @returns A tuple of three numbers indicating `[major, minor, patch]`.
@@ -717,6 +781,8 @@ interface IncrementVersionOptions {
717
781
  /**
718
782
  * Increments the given input version depending on the given increment type.
719
783
  *
784
+ * @deprecated This function does not support the new class-based handling of VersionNumber. Please use `new VersionNumber(version).increment(incrementType)` instead.
785
+ *
720
786
  * @param version - The version to increment
721
787
  * @param incrementType - The type of increment. Can be one of the following:
722
788
  * - `"major"`: Change the major version `v1.2.3` → `v2.0.0`
@@ -738,6 +804,8 @@ interface ParseVersionOptions {
738
804
  *
739
805
  * Valid formats: `X.Y.Z` or `vX.Y.Z`, where X, Y, and Z are non-negative integers.
740
806
  *
807
+ * @deprecated This function does not support the new class-based handling of VersionNumber. Please use `new VersionNumber(input)` instead.
808
+ *
741
809
  * @param input - The version string to parse.
742
810
  * @param options - Extra options to apply.
743
811
  *
@@ -747,4 +815,4 @@ interface ParseVersionOptions {
747
815
  */
748
816
  declare function parseVersion(input: string, options?: ParseVersionOptions): string;
749
817
  //#endregion
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 };
818
+ export { APIError, ArrayElement, CamelToKebabOptions, CreateEnumType, 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, VersionNumber, 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
@@ -1,4 +1,4 @@
1
- import z, { ZodType, core, z as z$1 } from "zod";
1
+ import { ZodType, core, z as z$1 } from "zod";
2
2
 
3
3
  //#region src/constants/NAMESPACE_EXPORT_REGEX.d.ts
4
4
  declare const NAMESPACE_EXPORT_REGEX = "export\\s+\\*\\s+from";
@@ -222,6 +222,71 @@ declare class DataError extends Error {
222
222
  static check(input: unknown): input is DataError;
223
223
  }
224
224
  //#endregion
225
+ //#region src/types/RecordKey.d.ts
226
+ /** Represents the native Record's possible key type. */
227
+ type RecordKey = string | number | symbol;
228
+ //#endregion
229
+ //#region src/types/CreateEnumType.d.ts
230
+ /**
231
+ * Get the value types from a const object so the object can behave similarly to an enum.
232
+ *
233
+ * @template ObjectType - The type of the object to get the value types for.
234
+ */
235
+ type CreateEnumType<ObjectType extends Record<RecordKey, unknown>> = ObjectType[keyof ObjectType];
236
+ //#endregion
237
+ //#region src/types/VersionType.d.ts
238
+ declare const VersionType: {
239
+ readonly MAJOR: "major";
240
+ readonly MINOR: "minor";
241
+ readonly PATCH: "patch";
242
+ };
243
+ type VersionType = CreateEnumType<typeof VersionType>;
244
+ //#endregion
245
+ //#region src/types/VersionNumber.d.ts
246
+ interface ToStringOptions {
247
+ omitPrefix?: boolean;
248
+ }
249
+ /** Represents a software version number, considered to be made up of a major, minor, and patch part. */
250
+ declare class VersionNumber {
251
+ /** The major number. Increments when a feature is removed or changed in a way that is not backwards-compatible with the previous release. */
252
+ readonly major: number;
253
+ /** The minor number. Increments when a new feature is added/deprecated and is expected to be backwards-compatible with the previous release. */
254
+ readonly minor: number;
255
+ /** The patch number. Increments when the next release is fixing a bug or doing a small refactor that should not be noticeable in practice. */
256
+ readonly patch: number;
257
+ private static readonly NON_NEGATIVE_TUPLE_ERROR;
258
+ /**
259
+ * @param input - The input to create a new instance of `VersionNumber` from.
260
+ */
261
+ constructor(input: string | [number, number, number] | VersionNumber);
262
+ private static formatString;
263
+ /**
264
+ * Get a string representation of the current version number.
265
+ *
266
+ * @param options - Extra additional options to apply.
267
+ *
268
+ * @returns A stringified representation of the current version number, leaving out the prefix if `omitPrefix` option was set to true.
269
+ */
270
+ toString(options?: ToStringOptions): string;
271
+ /**
272
+ * Gets the current version type of the current instance of `VersionNumber`.
273
+ *
274
+ * @returns Either `"major"`, `"minor"`, or `"patch"`, depending on the version type.
275
+ */
276
+ get type(): VersionType;
277
+ /**
278
+ * Determines whether the current instance of `VersionNumber` is a major, minor, or patch version.
279
+ *
280
+ * @param incrementType - The type of increment. Can be one of the following:
281
+ * - `"major"`: Change the major version `v1.2.3` → `v2.0.0`
282
+ * - `"minor"`: Change the minor version `v1.2.3` → `v1.3.0`
283
+ * - `"patch"`: Change the patch version `v1.2.3` → `v1.2.4`
284
+ *
285
+ * @returns A new instance of `VersionNumber` with the increment applied.
286
+ */
287
+ increment(incrementType: VersionType): VersionNumber;
288
+ }
289
+ //#endregion
225
290
  //#region src/types/ArrayElement.d.ts
226
291
  /**
227
292
  * Gets the individual element types from an array type.
@@ -263,10 +328,6 @@ type NonUndefined<InputType> = InputType extends undefined ? never : InputType;
263
328
  */
264
329
  type OptionalOnCondition<Condition extends boolean, ResolvedTypeIfTrue> = Condition extends true ? ResolvedTypeIfTrue : ResolvedTypeIfTrue | undefined;
265
330
  //#endregion
266
- //#region src/types/RecordKey.d.ts
267
- /** Represents the native Record's possible key type. */
268
- type RecordKey = string | number | symbol;
269
- //#endregion
270
331
  //#region src/functions/miscellaneous/createFormData.d.ts
271
332
  type FormDataNullableResolutionStrategy = "stringify" | "empty" | "omit";
272
333
  type FormDataArrayResolutionStrategy = "stringify" | "multiple";
@@ -448,12 +509,6 @@ declare function parseFormData(formData: FormData): Record<string, string | Blob
448
509
  declare function parseIntStrict(string: string, radix?: number): number;
449
510
  //#endregion
450
511
  //#region src/functions/parsers/parseVersionType.d.ts
451
- declare const versionTypeSchema: z.ZodEnum<{
452
- major: "major";
453
- minor: "minor";
454
- patch: "patch";
455
- }>;
456
- type VersionType = z.infer<typeof versionTypeSchema>;
457
512
  /**
458
513
  * Parses the input and verifies it is a valid software version type (i.e. `"major" | "minor" | "patch"`)
459
514
  *
@@ -693,6 +748,8 @@ declare const normalizeIndents: typeof normaliseIndents;
693
748
  /**
694
749
  * Determines whether the given version is a major, minor, or patch version.
695
750
  *
751
+ * @deprecated This function does not support the new class-based handling of VersionNumber. Please use `new VersionNumber(version).type` instead.
752
+ *
696
753
  * @param version - The version number.
697
754
  *
698
755
  * @returns Either `"major"`, `"minor"`, or `"patch"`, depending on the version type.
@@ -703,6 +760,13 @@ declare function determineVersionType(version: string): VersionType;
703
760
  /**
704
761
  * Gets the individual version numbers from a given version number as a tuple of numbers.
705
762
  *
763
+ * @deprecated This function does not support the new class-based handling of VersionNumber. Please use one of the following instead:
764
+ * ```typescript
765
+ * new VersionNumber(version).major
766
+ * new VersionNumber(version).minor
767
+ * new VersionNumber(version).patch
768
+ * ```
769
+ *
706
770
  * @param version - The version number.
707
771
  *
708
772
  * @returns A tuple of three numbers indicating `[major, minor, patch]`.
@@ -717,6 +781,8 @@ interface IncrementVersionOptions {
717
781
  /**
718
782
  * Increments the given input version depending on the given increment type.
719
783
  *
784
+ * @deprecated This function does not support the new class-based handling of VersionNumber. Please use `new VersionNumber(version).increment(incrementType)` instead.
785
+ *
720
786
  * @param version - The version to increment
721
787
  * @param incrementType - The type of increment. Can be one of the following:
722
788
  * - `"major"`: Change the major version `v1.2.3` → `v2.0.0`
@@ -738,6 +804,8 @@ interface ParseVersionOptions {
738
804
  *
739
805
  * Valid formats: `X.Y.Z` or `vX.Y.Z`, where X, Y, and Z are non-negative integers.
740
806
  *
807
+ * @deprecated This function does not support the new class-based handling of VersionNumber. Please use `new VersionNumber(input)` instead.
808
+ *
741
809
  * @param input - The version string to parse.
742
810
  * @param options - Extra options to apply.
743
811
  *
@@ -747,4 +815,4 @@ interface ParseVersionOptions {
747
815
  */
748
816
  declare function parseVersion(input: string, options?: ParseVersionOptions): string;
749
817
  //#endregion
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 };
818
+ export { APIError, ArrayElement, CamelToKebabOptions, CreateEnumType, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DisallowUndefined, type Env, FormDataArrayResolutionStrategy, FormDataNullableResolutionStrategy, HTTPErrorCode, IgnoreCase, IncrementVersionOptions, KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, OptionalOnCondition, ParseVersionOptions, RecordKey, StringListToArrayOptions, VERSION_NUMBER_REGEX, VersionNumber, 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
@@ -134,6 +134,111 @@ var DataError = class extends Error {
134
134
  };
135
135
  var DataError_default = DataError;
136
136
 
137
+ //#endregion
138
+ //#region src/types/VersionType.ts
139
+ const VersionType = {
140
+ MAJOR: "major",
141
+ MINOR: "minor",
142
+ PATCH: "patch"
143
+ };
144
+
145
+ //#endregion
146
+ //#region src/types/VersionNumber.ts
147
+ /** Represents a software version number, considered to be made up of a major, minor, and patch part. */
148
+ var VersionNumber = class VersionNumber {
149
+ /** The major number. Increments when a feature is removed or changed in a way that is not backwards-compatible with the previous release. */
150
+ major = 0;
151
+ /** The minor number. Increments when a new feature is added/deprecated and is expected to be backwards-compatible with the previous release. */
152
+ minor = 0;
153
+ /** The patch number. Increments when the next release is fixing a bug or doing a small refactor that should not be noticeable in practice. */
154
+ patch = 0;
155
+ static NON_NEGATIVE_TUPLE_ERROR = "Input array must be a tuple of three non-negative integers.";
156
+ /**
157
+ * @param input - The input to create a new instance of `VersionNumber` from.
158
+ */
159
+ constructor(input) {
160
+ if (input instanceof VersionNumber) {
161
+ this.major = input.major;
162
+ this.minor = input.minor;
163
+ this.patch = input.patch;
164
+ } else if (typeof input === "string") {
165
+ if (!RegExp(VERSION_NUMBER_REGEX_default).test(input)) throw new DataError_default(input, "INVALID_VERSION", `"${input}" is not a valid version number. Version numbers must be of the format "X.Y.Z" or "vX.Y.Z", where X, Y, and Z are non-negative integers.`);
166
+ const [major, minor, patch] = VersionNumber.formatString(input, { omitPrefix: true }).split(".").map((number) => {
167
+ return parseIntStrict_default(number);
168
+ });
169
+ this.major = major;
170
+ this.minor = minor;
171
+ this.patch = patch;
172
+ } else if (Array.isArray(input)) {
173
+ if (input.length !== 3) throw new DataError_default(input, "INVALID_LENGTH", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
174
+ const [major, minor, patch] = input.map((number) => {
175
+ const parsedInteger = parseIntStrict_default(number?.toString());
176
+ if (parsedInteger < 0) throw new DataError_default(input, "NON_POSITIVE_INPUTS", VersionNumber.NON_NEGATIVE_TUPLE_ERROR);
177
+ return parsedInteger;
178
+ });
179
+ this.major = major;
180
+ this.minor = minor;
181
+ this.patch = patch;
182
+ }
183
+ }
184
+ static formatString(input, options) {
185
+ if (options?.omitPrefix) return input.startsWith("v") ? input.slice(1) : input;
186
+ return input.startsWith("v") ? input : `v${input}`;
187
+ }
188
+ /**
189
+ * Get a string representation of the current version number.
190
+ *
191
+ * @param options - Extra additional options to apply.
192
+ *
193
+ * @returns A stringified representation of the current version number, leaving out the prefix if `omitPrefix` option was set to true.
194
+ */
195
+ toString(options) {
196
+ const rawString = `${this.major}.${this.minor}.${this.patch}`;
197
+ return VersionNumber.formatString(rawString, options);
198
+ }
199
+ /**
200
+ * Gets the current version type of the current instance of `VersionNumber`.
201
+ *
202
+ * @returns Either `"major"`, `"minor"`, or `"patch"`, depending on the version type.
203
+ */
204
+ get type() {
205
+ if (this.minor === 0 && this.patch === 0) return VersionType.MAJOR;
206
+ if (this.patch === 0) return VersionType.MINOR;
207
+ return VersionType.PATCH;
208
+ }
209
+ /**
210
+ * Determines whether the current instance of `VersionNumber` is a major, minor, or patch version.
211
+ *
212
+ * @param incrementType - The type of increment. Can be one of the following:
213
+ * - `"major"`: Change the major version `v1.2.3` → `v2.0.0`
214
+ * - `"minor"`: Change the minor version `v1.2.3` → `v1.3.0`
215
+ * - `"patch"`: Change the patch version `v1.2.3` → `v1.2.4`
216
+ *
217
+ * @returns A new instance of `VersionNumber` with the increment applied.
218
+ */
219
+ increment(incrementType) {
220
+ const newVersion = {
221
+ major: [
222
+ this.major + 1,
223
+ 0,
224
+ 0
225
+ ],
226
+ minor: [
227
+ this.major,
228
+ this.minor + 1,
229
+ 0
230
+ ],
231
+ patch: [
232
+ this.major,
233
+ this.minor,
234
+ this.patch + 1
235
+ ]
236
+ }[incrementType];
237
+ return new VersionNumber(newVersion);
238
+ }
239
+ };
240
+ var VersionNumber_default = VersionNumber;
241
+
137
242
  //#endregion
138
243
  //#region src/functions/parsers/parseIntStrict.ts
139
244
  /**
@@ -672,11 +777,6 @@ var parseFormData_default = parseFormData;
672
777
 
673
778
  //#endregion
674
779
  //#region src/functions/parsers/parseVersionType.ts
675
- const versionTypeSchema = z.enum([
676
- "major",
677
- "minor",
678
- "patch"
679
- ]);
680
780
  /**
681
781
  * Parses the input and verifies it is a valid software version type (i.e. `"major" | "minor" | "patch"`)
682
782
  *
@@ -687,7 +787,7 @@ const versionTypeSchema = z.enum([
687
787
  * @returns The given version type if allowed.
688
788
  */
689
789
  function parseVersionType(data) {
690
- return parseZodSchema_default(versionTypeSchema, data, new DataError_default(data, "INVALID_VERSION_TYPE", "The provided version type must be one of `major | minor | patch`"));
790
+ return parseZodSchema_default(z.enum(VersionType), data, new DataError_default(data, "INVALID_VERSION_TYPE", "The provided version type must be one of `major | minor | patch`"));
691
791
  }
692
792
  var parseVersionType_default = parseVersionType;
693
793
 
@@ -1035,6 +1135,8 @@ var normaliseIndents_default = normaliseIndents;
1035
1135
  *
1036
1136
  * Valid formats: `X.Y.Z` or `vX.Y.Z`, where X, Y, and Z are non-negative integers.
1037
1137
  *
1138
+ * @deprecated This function does not support the new class-based handling of VersionNumber. Please use `new VersionNumber(input)` instead.
1139
+ *
1038
1140
  * @param input - The version string to parse.
1039
1141
  * @param options - Extra options to apply.
1040
1142
  *
@@ -1054,6 +1156,13 @@ var parseVersion_default = parseVersion;
1054
1156
  /**
1055
1157
  * Gets the individual version numbers from a given version number as a tuple of numbers.
1056
1158
  *
1159
+ * @deprecated This function does not support the new class-based handling of VersionNumber. Please use one of the following instead:
1160
+ * ```typescript
1161
+ * new VersionNumber(version).major
1162
+ * new VersionNumber(version).minor
1163
+ * new VersionNumber(version).patch
1164
+ * ```
1165
+ *
1057
1166
  * @param version - The version number.
1058
1167
  *
1059
1168
  * @returns A tuple of three numbers indicating `[major, minor, patch]`.
@@ -1070,6 +1179,8 @@ var getIndividualVersionNumbers_default = getIndividualVersionNumbers;
1070
1179
  /**
1071
1180
  * Determines whether the given version is a major, minor, or patch version.
1072
1181
  *
1182
+ * @deprecated This function does not support the new class-based handling of VersionNumber. Please use `new VersionNumber(version).type` instead.
1183
+ *
1073
1184
  * @param version - The version number.
1074
1185
  *
1075
1186
  * @returns Either `"major"`, `"minor"`, or `"patch"`, depending on the version type.
@@ -1087,6 +1198,8 @@ var determineVersionType_default = determineVersionType;
1087
1198
  /**
1088
1199
  * Increments the given input version depending on the given increment type.
1089
1200
  *
1201
+ * @deprecated This function does not support the new class-based handling of VersionNumber. Please use `new VersionNumber(version).increment(incrementType)` instead.
1202
+ *
1090
1203
  * @param version - The version to increment
1091
1204
  * @param incrementType - The type of increment. Can be one of the following:
1092
1205
  * - `"major"`: Change the major version `v1.2.3` → `v2.0.0`
@@ -1108,4 +1221,4 @@ function incrementVersion(version, incrementType, options) {
1108
1221
  var incrementVersion_default = incrementVersion;
1109
1222
 
1110
1223
  //#endregion
1111
- 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, parseEnv_default as parseEnv, parseFormData_default as parseFormData, parseIntStrict_default as parseIntStrict, parseVersion_default as parseVersion, parseVersionType_default as parseVersionType, parseZodSchema_default as parseZodSchema, randomiseArray_default as randomiseArray, range_default as range, removeDuplicates_default as removeDuplicates, stringListToArray_default as stringListToArray, truncate_default as truncate, wait_default as wait };
1224
+ 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, VersionNumber_default as VersionNumber, VersionType, 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, parseEnv_default as parseEnv, parseFormData_default as parseFormData, parseIntStrict_default as parseIntStrict, parseVersion_default as parseVersion, parseVersionType_default as parseVersionType, parseZodSchema_default as parseZodSchema, randomiseArray_default as randomiseArray, range_default as range, removeDuplicates_default as removeDuplicates, stringListToArray_default as stringListToArray, 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": "4.1.0",
3
+ "version": "4.2.1",
4
4
  "description": "Helpful utility functions",
5
5
  "repository": {
6
6
  "type": "git",
@@ -19,7 +19,7 @@
19
19
  "zod": "^4.2.1"
20
20
  },
21
21
  "devDependencies": {
22
- "@alextheman/eslint-plugin": "^4.10.0",
22
+ "@alextheman/eslint-plugin": "^5.0.1",
23
23
  "@types/node": "^25.0.3",
24
24
  "alex-c-line": "^1.10.0",
25
25
  "dotenv-cli": "^11.0.0",
@@ -34,6 +34,9 @@
34
34
  "vite-tsconfig-paths": "^6.0.3",
35
35
  "vitest": "^4.0.16"
36
36
  },
37
+ "engines": {
38
+ "node": ">=22.0.0"
39
+ },
37
40
  "scripts": {
38
41
  "build": "tsdown",
39
42
  "create-local-package": "pnpm run build && rm -f alextheman-utility-*.tgz && pnpm pack",