@alextheman/utility 4.0.0 → 4.2.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 +150 -11
- package/dist/index.d.cts +88 -15
- package/dist/index.d.ts +86 -13
- package/dist/index.js +147 -10
- package/package.json +6 -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";
|
|
@@ -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
|
+
nonNegativeTupleError = "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", this.nonNegativeTupleError);
|
|
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", this.nonNegativeTupleError);
|
|
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(
|
|
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
|
|
|
@@ -795,11 +895,35 @@ var appendSemicolon_default = appendSemicolon;
|
|
|
795
895
|
* Converts a string from camelCase to kebab-case
|
|
796
896
|
*
|
|
797
897
|
* @param string - The string to convert.
|
|
898
|
+
* @param options - Options to apply to the conversion.
|
|
798
899
|
*
|
|
799
900
|
* @returns The string converted to kebab-case.
|
|
800
901
|
*/
|
|
801
|
-
function camelToKebab(string) {
|
|
802
|
-
|
|
902
|
+
function camelToKebab(string, options = { preserveConsecutiveCapitals: true }) {
|
|
903
|
+
let result = "";
|
|
904
|
+
let outerIndex = 0;
|
|
905
|
+
while (outerIndex < string.length) {
|
|
906
|
+
const character = string[outerIndex];
|
|
907
|
+
if (/[A-Z]/.test(character)) {
|
|
908
|
+
let innerIndex = outerIndex + 1;
|
|
909
|
+
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++;
|
|
910
|
+
const sequenceOfCapitals = string.slice(outerIndex, innerIndex);
|
|
911
|
+
if (options.preserveConsecutiveCapitals) {
|
|
912
|
+
if (result) result += "-";
|
|
913
|
+
result += sequenceOfCapitals.toLowerCase();
|
|
914
|
+
} else {
|
|
915
|
+
if (result) result += "-";
|
|
916
|
+
result += sequenceOfCapitals.split("").map((character$1) => {
|
|
917
|
+
return character$1.toLowerCase();
|
|
918
|
+
}).join("-");
|
|
919
|
+
}
|
|
920
|
+
outerIndex = innerIndex;
|
|
921
|
+
} else {
|
|
922
|
+
result += character;
|
|
923
|
+
outerIndex++;
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
return result;
|
|
803
927
|
}
|
|
804
928
|
var camelToKebab_default = camelToKebab;
|
|
805
929
|
|
|
@@ -857,7 +981,7 @@ var kebabToCamel_default = kebabToCamel;
|
|
|
857
981
|
* @returns The import path normalized.
|
|
858
982
|
*/
|
|
859
983
|
function normalizeImportPath(importPath) {
|
|
860
|
-
const normalizedPath =
|
|
984
|
+
const normalizedPath = node_path.default.posix.normalize(importPath);
|
|
861
985
|
if (importPath.startsWith("./") && !normalizedPath.startsWith("./")) return `./${normalizedPath}`;
|
|
862
986
|
return normalizedPath;
|
|
863
987
|
}
|
|
@@ -1040,6 +1164,8 @@ var normaliseIndents_default = normaliseIndents;
|
|
|
1040
1164
|
*
|
|
1041
1165
|
* Valid formats: `X.Y.Z` or `vX.Y.Z`, where X, Y, and Z are non-negative integers.
|
|
1042
1166
|
*
|
|
1167
|
+
* @deprecated This function does not support the new class-based handling of VersionNumber. Please use `new VersionNumber(input)` instead.
|
|
1168
|
+
*
|
|
1043
1169
|
* @param input - The version string to parse.
|
|
1044
1170
|
* @param options - Extra options to apply.
|
|
1045
1171
|
*
|
|
@@ -1059,6 +1185,13 @@ var parseVersion_default = parseVersion;
|
|
|
1059
1185
|
/**
|
|
1060
1186
|
* Gets the individual version numbers from a given version number as a tuple of numbers.
|
|
1061
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
|
+
*
|
|
1062
1195
|
* @param version - The version number.
|
|
1063
1196
|
*
|
|
1064
1197
|
* @returns A tuple of three numbers indicating `[major, minor, patch]`.
|
|
@@ -1075,6 +1208,8 @@ var getIndividualVersionNumbers_default = getIndividualVersionNumbers;
|
|
|
1075
1208
|
/**
|
|
1076
1209
|
* Determines whether the given version is a major, minor, or patch version.
|
|
1077
1210
|
*
|
|
1211
|
+
* @deprecated This function does not support the new class-based handling of VersionNumber. Please use `new VersionNumber(version).type` instead.
|
|
1212
|
+
*
|
|
1078
1213
|
* @param version - The version number.
|
|
1079
1214
|
*
|
|
1080
1215
|
* @returns Either `"major"`, `"minor"`, or `"patch"`, depending on the version type.
|
|
@@ -1092,6 +1227,8 @@ var determineVersionType_default = determineVersionType;
|
|
|
1092
1227
|
/**
|
|
1093
1228
|
* Increments the given input version depending on the given increment type.
|
|
1094
1229
|
*
|
|
1230
|
+
* @deprecated This function does not support the new class-based handling of VersionNumber. Please use `new VersionNumber(version).increment(incrementType)` instead.
|
|
1231
|
+
*
|
|
1095
1232
|
* @param version - The version to increment
|
|
1096
1233
|
* @param incrementType - The type of increment. Can be one of the following:
|
|
1097
1234
|
* - `"major"`: Change the major version `v1.2.3` → `v2.0.0`
|
|
@@ -1117,6 +1254,8 @@ exports.APIError = APIError_default;
|
|
|
1117
1254
|
exports.DataError = DataError_default;
|
|
1118
1255
|
exports.NAMESPACE_EXPORT_REGEX = NAMESPACE_EXPORT_REGEX_default;
|
|
1119
1256
|
exports.VERSION_NUMBER_REGEX = VERSION_NUMBER_REGEX_default;
|
|
1257
|
+
exports.VersionNumber = VersionNumber_default;
|
|
1258
|
+
exports.VersionType = VersionType;
|
|
1120
1259
|
exports.addDaysToDate = addDaysToDate_default;
|
|
1121
1260
|
exports.appendSemicolon = appendSemicolon_default;
|
|
1122
1261
|
exports.camelToKebab = camelToKebab_default;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
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 readonly nonNegativeTupleError;
|
|
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
|
|
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
|
|
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
|
*
|
|
@@ -524,14 +579,19 @@ declare function deepFreeze<ObjectType extends object>(object: ObjectType): Read
|
|
|
524
579
|
declare function appendSemicolon(stringToAppendTo: string): string;
|
|
525
580
|
//#endregion
|
|
526
581
|
//#region src/functions/stringHelpers/camelToKebab.d.ts
|
|
582
|
+
interface CamelToKebabOptions {
|
|
583
|
+
/** 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`) */
|
|
584
|
+
preserveConsecutiveCapitals?: boolean;
|
|
585
|
+
}
|
|
527
586
|
/**
|
|
528
587
|
* Converts a string from camelCase to kebab-case
|
|
529
588
|
*
|
|
530
589
|
* @param string - The string to convert.
|
|
590
|
+
* @param options - Options to apply to the conversion.
|
|
531
591
|
*
|
|
532
592
|
* @returns The string converted to kebab-case.
|
|
533
593
|
*/
|
|
534
|
-
declare function camelToKebab(string: string): string;
|
|
594
|
+
declare function camelToKebab(string: string, options?: CamelToKebabOptions): string;
|
|
535
595
|
//#endregion
|
|
536
596
|
//#region src/functions/stringHelpers/kebabToCamel.d.ts
|
|
537
597
|
interface KebabToCamelOptions {
|
|
@@ -688,6 +748,8 @@ declare const normalizeIndents: typeof normaliseIndents;
|
|
|
688
748
|
/**
|
|
689
749
|
* Determines whether the given version is a major, minor, or patch version.
|
|
690
750
|
*
|
|
751
|
+
* @deprecated This function does not support the new class-based handling of VersionNumber. Please use `new VersionNumber(version).type` instead.
|
|
752
|
+
*
|
|
691
753
|
* @param version - The version number.
|
|
692
754
|
*
|
|
693
755
|
* @returns Either `"major"`, `"minor"`, or `"patch"`, depending on the version type.
|
|
@@ -698,6 +760,13 @@ declare function determineVersionType(version: string): VersionType;
|
|
|
698
760
|
/**
|
|
699
761
|
* Gets the individual version numbers from a given version number as a tuple of numbers.
|
|
700
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
|
+
*
|
|
701
770
|
* @param version - The version number.
|
|
702
771
|
*
|
|
703
772
|
* @returns A tuple of three numbers indicating `[major, minor, patch]`.
|
|
@@ -712,6 +781,8 @@ interface IncrementVersionOptions {
|
|
|
712
781
|
/**
|
|
713
782
|
* Increments the given input version depending on the given increment type.
|
|
714
783
|
*
|
|
784
|
+
* @deprecated This function does not support the new class-based handling of VersionNumber. Please use `new VersionNumber(version).increment(incrementType)` instead.
|
|
785
|
+
*
|
|
715
786
|
* @param version - The version to increment
|
|
716
787
|
* @param incrementType - The type of increment. Can be one of the following:
|
|
717
788
|
* - `"major"`: Change the major version `v1.2.3` → `v2.0.0`
|
|
@@ -733,6 +804,8 @@ interface ParseVersionOptions {
|
|
|
733
804
|
*
|
|
734
805
|
* Valid formats: `X.Y.Z` or `vX.Y.Z`, where X, Y, and Z are non-negative integers.
|
|
735
806
|
*
|
|
807
|
+
* @deprecated This function does not support the new class-based handling of VersionNumber. Please use `new VersionNumber(input)` instead.
|
|
808
|
+
*
|
|
736
809
|
* @param input - The version string to parse.
|
|
737
810
|
* @param options - Extra options to apply.
|
|
738
811
|
*
|
|
@@ -742,4 +815,4 @@ interface ParseVersionOptions {
|
|
|
742
815
|
*/
|
|
743
816
|
declare function parseVersion(input: string, options?: ParseVersionOptions): string;
|
|
744
817
|
//#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 };
|
|
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
|
|
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 readonly nonNegativeTupleError;
|
|
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
|
*
|
|
@@ -524,14 +579,19 @@ declare function deepFreeze<ObjectType extends object>(object: ObjectType): Read
|
|
|
524
579
|
declare function appendSemicolon(stringToAppendTo: string): string;
|
|
525
580
|
//#endregion
|
|
526
581
|
//#region src/functions/stringHelpers/camelToKebab.d.ts
|
|
582
|
+
interface CamelToKebabOptions {
|
|
583
|
+
/** 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`) */
|
|
584
|
+
preserveConsecutiveCapitals?: boolean;
|
|
585
|
+
}
|
|
527
586
|
/**
|
|
528
587
|
* Converts a string from camelCase to kebab-case
|
|
529
588
|
*
|
|
530
589
|
* @param string - The string to convert.
|
|
590
|
+
* @param options - Options to apply to the conversion.
|
|
531
591
|
*
|
|
532
592
|
* @returns The string converted to kebab-case.
|
|
533
593
|
*/
|
|
534
|
-
declare function camelToKebab(string: string): string;
|
|
594
|
+
declare function camelToKebab(string: string, options?: CamelToKebabOptions): string;
|
|
535
595
|
//#endregion
|
|
536
596
|
//#region src/functions/stringHelpers/kebabToCamel.d.ts
|
|
537
597
|
interface KebabToCamelOptions {
|
|
@@ -688,6 +748,8 @@ declare const normalizeIndents: typeof normaliseIndents;
|
|
|
688
748
|
/**
|
|
689
749
|
* Determines whether the given version is a major, minor, or patch version.
|
|
690
750
|
*
|
|
751
|
+
* @deprecated This function does not support the new class-based handling of VersionNumber. Please use `new VersionNumber(version).type` instead.
|
|
752
|
+
*
|
|
691
753
|
* @param version - The version number.
|
|
692
754
|
*
|
|
693
755
|
* @returns Either `"major"`, `"minor"`, or `"patch"`, depending on the version type.
|
|
@@ -698,6 +760,13 @@ declare function determineVersionType(version: string): VersionType;
|
|
|
698
760
|
/**
|
|
699
761
|
* Gets the individual version numbers from a given version number as a tuple of numbers.
|
|
700
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
|
+
*
|
|
701
770
|
* @param version - The version number.
|
|
702
771
|
*
|
|
703
772
|
* @returns A tuple of three numbers indicating `[major, minor, patch]`.
|
|
@@ -712,6 +781,8 @@ interface IncrementVersionOptions {
|
|
|
712
781
|
/**
|
|
713
782
|
* Increments the given input version depending on the given increment type.
|
|
714
783
|
*
|
|
784
|
+
* @deprecated This function does not support the new class-based handling of VersionNumber. Please use `new VersionNumber(version).increment(incrementType)` instead.
|
|
785
|
+
*
|
|
715
786
|
* @param version - The version to increment
|
|
716
787
|
* @param incrementType - The type of increment. Can be one of the following:
|
|
717
788
|
* - `"major"`: Change the major version `v1.2.3` → `v2.0.0`
|
|
@@ -733,6 +804,8 @@ interface ParseVersionOptions {
|
|
|
733
804
|
*
|
|
734
805
|
* Valid formats: `X.Y.Z` or `vX.Y.Z`, where X, Y, and Z are non-negative integers.
|
|
735
806
|
*
|
|
807
|
+
* @deprecated This function does not support the new class-based handling of VersionNumber. Please use `new VersionNumber(input)` instead.
|
|
808
|
+
*
|
|
736
809
|
* @param input - The version string to parse.
|
|
737
810
|
* @param options - Extra options to apply.
|
|
738
811
|
*
|
|
@@ -742,4 +815,4 @@ interface ParseVersionOptions {
|
|
|
742
815
|
*/
|
|
743
816
|
declare function parseVersion(input: string, options?: ParseVersionOptions): string;
|
|
744
817
|
//#endregion
|
|
745
|
-
export { APIError, ArrayElement, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DisallowUndefined, type Env, FormDataArrayResolutionStrategy, FormDataNullableResolutionStrategy, HTTPErrorCode, IgnoreCase,
|
|
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
|
@@ -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";
|
|
@@ -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
|
+
nonNegativeTupleError = "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", this.nonNegativeTupleError);
|
|
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", this.nonNegativeTupleError);
|
|
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(
|
|
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
|
|
|
@@ -766,11 +866,35 @@ var appendSemicolon_default = appendSemicolon;
|
|
|
766
866
|
* Converts a string from camelCase to kebab-case
|
|
767
867
|
*
|
|
768
868
|
* @param string - The string to convert.
|
|
869
|
+
* @param options - Options to apply to the conversion.
|
|
769
870
|
*
|
|
770
871
|
* @returns The string converted to kebab-case.
|
|
771
872
|
*/
|
|
772
|
-
function camelToKebab(string) {
|
|
773
|
-
|
|
873
|
+
function camelToKebab(string, options = { preserveConsecutiveCapitals: true }) {
|
|
874
|
+
let result = "";
|
|
875
|
+
let outerIndex = 0;
|
|
876
|
+
while (outerIndex < string.length) {
|
|
877
|
+
const character = string[outerIndex];
|
|
878
|
+
if (/[A-Z]/.test(character)) {
|
|
879
|
+
let innerIndex = outerIndex + 1;
|
|
880
|
+
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++;
|
|
881
|
+
const sequenceOfCapitals = string.slice(outerIndex, innerIndex);
|
|
882
|
+
if (options.preserveConsecutiveCapitals) {
|
|
883
|
+
if (result) result += "-";
|
|
884
|
+
result += sequenceOfCapitals.toLowerCase();
|
|
885
|
+
} else {
|
|
886
|
+
if (result) result += "-";
|
|
887
|
+
result += sequenceOfCapitals.split("").map((character$1) => {
|
|
888
|
+
return character$1.toLowerCase();
|
|
889
|
+
}).join("-");
|
|
890
|
+
}
|
|
891
|
+
outerIndex = innerIndex;
|
|
892
|
+
} else {
|
|
893
|
+
result += character;
|
|
894
|
+
outerIndex++;
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
return result;
|
|
774
898
|
}
|
|
775
899
|
var camelToKebab_default = camelToKebab;
|
|
776
900
|
|
|
@@ -1011,6 +1135,8 @@ var normaliseIndents_default = normaliseIndents;
|
|
|
1011
1135
|
*
|
|
1012
1136
|
* Valid formats: `X.Y.Z` or `vX.Y.Z`, where X, Y, and Z are non-negative integers.
|
|
1013
1137
|
*
|
|
1138
|
+
* @deprecated This function does not support the new class-based handling of VersionNumber. Please use `new VersionNumber(input)` instead.
|
|
1139
|
+
*
|
|
1014
1140
|
* @param input - The version string to parse.
|
|
1015
1141
|
* @param options - Extra options to apply.
|
|
1016
1142
|
*
|
|
@@ -1030,6 +1156,13 @@ var parseVersion_default = parseVersion;
|
|
|
1030
1156
|
/**
|
|
1031
1157
|
* Gets the individual version numbers from a given version number as a tuple of numbers.
|
|
1032
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
|
+
*
|
|
1033
1166
|
* @param version - The version number.
|
|
1034
1167
|
*
|
|
1035
1168
|
* @returns A tuple of three numbers indicating `[major, minor, patch]`.
|
|
@@ -1046,6 +1179,8 @@ var getIndividualVersionNumbers_default = getIndividualVersionNumbers;
|
|
|
1046
1179
|
/**
|
|
1047
1180
|
* Determines whether the given version is a major, minor, or patch version.
|
|
1048
1181
|
*
|
|
1182
|
+
* @deprecated This function does not support the new class-based handling of VersionNumber. Please use `new VersionNumber(version).type` instead.
|
|
1183
|
+
*
|
|
1049
1184
|
* @param version - The version number.
|
|
1050
1185
|
*
|
|
1051
1186
|
* @returns Either `"major"`, `"minor"`, or `"patch"`, depending on the version type.
|
|
@@ -1063,6 +1198,8 @@ var determineVersionType_default = determineVersionType;
|
|
|
1063
1198
|
/**
|
|
1064
1199
|
* Increments the given input version depending on the given increment type.
|
|
1065
1200
|
*
|
|
1201
|
+
* @deprecated This function does not support the new class-based handling of VersionNumber. Please use `new VersionNumber(version).increment(incrementType)` instead.
|
|
1202
|
+
*
|
|
1066
1203
|
* @param version - The version to increment
|
|
1067
1204
|
* @param incrementType - The type of increment. Can be one of the following:
|
|
1068
1205
|
* - `"major"`: Change the major version `v1.2.3` → `v2.0.0`
|
|
@@ -1084,4 +1221,4 @@ function incrementVersion(version, incrementType, options) {
|
|
|
1084
1221
|
var incrementVersion_default = incrementVersion;
|
|
1085
1222
|
|
|
1086
1223
|
//#endregion
|
|
1087
|
-
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.
|
|
3
|
+
"version": "4.2.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": "^
|
|
22
|
+
"@alextheman/eslint-plugin": "^5.0.1",
|
|
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",
|
|
@@ -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",
|