@alextheman/utility 5.4.0 → 5.5.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 +36 -0
- package/dist/index.d.cts +27 -1
- package/dist/index.d.ts +27 -1
- package/dist/index.js +35 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -549,6 +549,21 @@ function addDaysToDate(currentDate = /* @__PURE__ */ new Date(), dayIncrement =
|
|
|
549
549
|
return newDate;
|
|
550
550
|
}
|
|
551
551
|
|
|
552
|
+
//#endregion
|
|
553
|
+
//#region src/root/functions/date/calculateMonthlyDifference.ts
|
|
554
|
+
/**
|
|
555
|
+
* Calculates the monthly difference between two given dates, subtracting the first from
|
|
556
|
+
* the second and gives a negative result if the first date occurs earlier than the second.
|
|
557
|
+
*
|
|
558
|
+
* @param firstDate - The first date
|
|
559
|
+
* @param secondDate - The second date
|
|
560
|
+
*
|
|
561
|
+
* @returns The calculated difference as a number
|
|
562
|
+
*/
|
|
563
|
+
function calculateMonthlyDifference(firstDate, secondDate) {
|
|
564
|
+
return firstDate.getMonth() - secondDate.getMonth();
|
|
565
|
+
}
|
|
566
|
+
|
|
552
567
|
//#endregion
|
|
553
568
|
//#region src/root/functions/date/isSameDate.ts
|
|
554
569
|
/**
|
|
@@ -1402,6 +1417,25 @@ function parseFormData(formData, dataParser) {
|
|
|
1402
1417
|
return object;
|
|
1403
1418
|
}
|
|
1404
1419
|
|
|
1420
|
+
//#endregion
|
|
1421
|
+
//#region src/root/functions/parsers/parseUUID.ts
|
|
1422
|
+
/**
|
|
1423
|
+
* Parses the input and verifies it is a valid UUID.
|
|
1424
|
+
*
|
|
1425
|
+
* @category Parsers
|
|
1426
|
+
*
|
|
1427
|
+
* @param input - The data to parse.
|
|
1428
|
+
*
|
|
1429
|
+
* @throws {DataError} If the data does not match the general UUID pattern.
|
|
1430
|
+
*
|
|
1431
|
+
* @returns The UUID again if successful.
|
|
1432
|
+
*/
|
|
1433
|
+
function parseUUID(input) {
|
|
1434
|
+
if (!(typeof input === "string")) throw new DataError({ input }, "INVALID_TYPE", "Invalid type - expected string.");
|
|
1435
|
+
if (!UUID_REGEX.test(input)) throw new DataError({ input }, "INVALID_UUID", "The provided input does not match the expected shape for a UUID.");
|
|
1436
|
+
return input;
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1405
1439
|
//#endregion
|
|
1406
1440
|
//#region src/root/functions/parsers/parseVersionType.ts
|
|
1407
1441
|
/**
|
|
@@ -1630,6 +1664,7 @@ exports.VersionNumber = VersionNumber;
|
|
|
1630
1664
|
exports.VersionType = VersionType;
|
|
1631
1665
|
exports.addDaysToDate = addDaysToDate;
|
|
1632
1666
|
exports.appendSemicolon = appendSemicolon;
|
|
1667
|
+
exports.calculateMonthlyDifference = calculateMonthlyDifference;
|
|
1633
1668
|
exports.camelToKebab = camelToKebab;
|
|
1634
1669
|
exports.convertFileToBase64 = convertFileToBase64;
|
|
1635
1670
|
exports.createFormData = createFormData;
|
|
@@ -1660,6 +1695,7 @@ exports.parseBoolean = parseBoolean;
|
|
|
1660
1695
|
exports.parseEnv = parseEnv;
|
|
1661
1696
|
exports.parseFormData = parseFormData;
|
|
1662
1697
|
exports.parseIntStrict = parseIntStrict;
|
|
1698
|
+
exports.parseUUID = parseUUID;
|
|
1663
1699
|
exports.parseVersionType = parseVersionType;
|
|
1664
1700
|
exports.parseZodSchema = parseZodSchema;
|
|
1665
1701
|
exports.parseZodSchemaAsync = parseZodSchemaAsync;
|
package/dist/index.d.cts
CHANGED
|
@@ -127,6 +127,18 @@ declare function removeDuplicates<ItemType>(array: ItemType[] | readonly ItemTyp
|
|
|
127
127
|
*/
|
|
128
128
|
declare function addDaysToDate(currentDate?: Date, dayIncrement?: number): Date;
|
|
129
129
|
//#endregion
|
|
130
|
+
//#region src/root/functions/date/calculateMonthlyDifference.d.ts
|
|
131
|
+
/**
|
|
132
|
+
* Calculates the monthly difference between two given dates, subtracting the first from
|
|
133
|
+
* the second and gives a negative result if the first date occurs earlier than the second.
|
|
134
|
+
*
|
|
135
|
+
* @param firstDate - The first date
|
|
136
|
+
* @param secondDate - The second date
|
|
137
|
+
*
|
|
138
|
+
* @returns The calculated difference as a number
|
|
139
|
+
*/
|
|
140
|
+
declare function calculateMonthlyDifference(firstDate: Date, secondDate: Date): number;
|
|
141
|
+
//#endregion
|
|
130
142
|
//#region src/root/functions/date/formatDateAndTime.d.ts
|
|
131
143
|
/**
|
|
132
144
|
* Creates a human-readable string with information about the input date.
|
|
@@ -740,6 +752,20 @@ declare function parseFormData(formData: FormData): Record<string, string | Blob
|
|
|
740
752
|
*/
|
|
741
753
|
declare function parseIntStrict(string: string, radix?: number): number;
|
|
742
754
|
//#endregion
|
|
755
|
+
//#region src/root/functions/parsers/parseUUID.d.ts
|
|
756
|
+
/**
|
|
757
|
+
* Parses the input and verifies it is a valid UUID.
|
|
758
|
+
*
|
|
759
|
+
* @category Parsers
|
|
760
|
+
*
|
|
761
|
+
* @param input - The data to parse.
|
|
762
|
+
*
|
|
763
|
+
* @throws {DataError} If the data does not match the general UUID pattern.
|
|
764
|
+
*
|
|
765
|
+
* @returns The UUID again if successful.
|
|
766
|
+
*/
|
|
767
|
+
declare function parseUUID(input: unknown): string;
|
|
768
|
+
//#endregion
|
|
743
769
|
//#region src/root/functions/parsers/parseVersionType.d.ts
|
|
744
770
|
/**
|
|
745
771
|
* Represents the three common software version types.
|
|
@@ -1086,4 +1112,4 @@ declare function normaliseIndents(strings: TemplateStringsArray, ...interpolatio
|
|
|
1086
1112
|
*/
|
|
1087
1113
|
declare const normalizeIndents: typeof normaliseIndents;
|
|
1088
1114
|
//#endregion
|
|
1089
|
-
export { APIError, ArrayElement, CallReturnType, CamelToKebabOptions, CreateEnumType, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DisallowUndefined, Env, FILE_PATH_PATTERN, FILE_PATH_REGEX, FormDataArrayResolutionStrategy, FormDataNullableResolutionStrategy, HTTPErrorCode, IgnoreCase, IsTypeArgumentString, KebabToCamelOptions, NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, ONE_DAY_IN_MILLISECONDS, OptionalOnCondition, ParallelTuple, RecordKey, RemoveUndefined, StringListToArrayOptions, UUID_PATTERN, UUID_REGEX, VERSION_NUMBER_PATTERN, VERSION_NUMBER_REGEX, VersionNumber, FormatOptionsBase as VersionNumberToStringOptions, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, encryptWithKey, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseIndents, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, stringListToArray, stringifyDotenv, truncate, wait, zodVersionNumber };
|
|
1115
|
+
export { APIError, ArrayElement, CallReturnType, CamelToKebabOptions, CreateEnumType, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DisallowUndefined, Env, FILE_PATH_PATTERN, FILE_PATH_REGEX, FormDataArrayResolutionStrategy, FormDataNullableResolutionStrategy, HTTPErrorCode, IgnoreCase, IsTypeArgumentString, KebabToCamelOptions, NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, ONE_DAY_IN_MILLISECONDS, OptionalOnCondition, ParallelTuple, RecordKey, RemoveUndefined, StringListToArrayOptions, UUID_PATTERN, UUID_REGEX, VERSION_NUMBER_PATTERN, VERSION_NUMBER_REGEX, VersionNumber, FormatOptionsBase as VersionNumberToStringOptions, VersionType, addDaysToDate, appendSemicolon, calculateMonthlyDifference, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, encryptWithKey, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseIndents, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseUUID, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, stringListToArray, stringifyDotenv, truncate, wait, zodVersionNumber };
|
package/dist/index.d.ts
CHANGED
|
@@ -127,6 +127,18 @@ declare function removeDuplicates<ItemType>(array: ItemType[] | readonly ItemTyp
|
|
|
127
127
|
*/
|
|
128
128
|
declare function addDaysToDate(currentDate?: Date, dayIncrement?: number): Date;
|
|
129
129
|
//#endregion
|
|
130
|
+
//#region src/root/functions/date/calculateMonthlyDifference.d.ts
|
|
131
|
+
/**
|
|
132
|
+
* Calculates the monthly difference between two given dates, subtracting the first from
|
|
133
|
+
* the second and gives a negative result if the first date occurs earlier than the second.
|
|
134
|
+
*
|
|
135
|
+
* @param firstDate - The first date
|
|
136
|
+
* @param secondDate - The second date
|
|
137
|
+
*
|
|
138
|
+
* @returns The calculated difference as a number
|
|
139
|
+
*/
|
|
140
|
+
declare function calculateMonthlyDifference(firstDate: Date, secondDate: Date): number;
|
|
141
|
+
//#endregion
|
|
130
142
|
//#region src/root/functions/date/formatDateAndTime.d.ts
|
|
131
143
|
/**
|
|
132
144
|
* Creates a human-readable string with information about the input date.
|
|
@@ -740,6 +752,20 @@ declare function parseFormData(formData: FormData): Record<string, string | Blob
|
|
|
740
752
|
*/
|
|
741
753
|
declare function parseIntStrict(string: string, radix?: number): number;
|
|
742
754
|
//#endregion
|
|
755
|
+
//#region src/root/functions/parsers/parseUUID.d.ts
|
|
756
|
+
/**
|
|
757
|
+
* Parses the input and verifies it is a valid UUID.
|
|
758
|
+
*
|
|
759
|
+
* @category Parsers
|
|
760
|
+
*
|
|
761
|
+
* @param input - The data to parse.
|
|
762
|
+
*
|
|
763
|
+
* @throws {DataError} If the data does not match the general UUID pattern.
|
|
764
|
+
*
|
|
765
|
+
* @returns The UUID again if successful.
|
|
766
|
+
*/
|
|
767
|
+
declare function parseUUID(input: unknown): string;
|
|
768
|
+
//#endregion
|
|
743
769
|
//#region src/root/functions/parsers/parseVersionType.d.ts
|
|
744
770
|
/**
|
|
745
771
|
* Represents the three common software version types.
|
|
@@ -1086,4 +1112,4 @@ declare function normaliseIndents(strings: TemplateStringsArray, ...interpolatio
|
|
|
1086
1112
|
*/
|
|
1087
1113
|
declare const normalizeIndents: typeof normaliseIndents;
|
|
1088
1114
|
//#endregion
|
|
1089
|
-
export { APIError, type ArrayElement, type CallReturnType, CamelToKebabOptions, type CreateEnumType, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, DataError, type DisallowUndefined, Env, FILE_PATH_PATTERN, FILE_PATH_REGEX, type FormDataArrayResolutionStrategy, type FormDataNullableResolutionStrategy, type HTTPErrorCode, type IgnoreCase, type IsTypeArgumentString, KebabToCamelOptions, type NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, ONE_DAY_IN_MILLISECONDS, type OptionalOnCondition, ParallelTuple, type RecordKey, type RemoveUndefined, type StringListToArrayOptions, UUID_PATTERN, UUID_REGEX, VERSION_NUMBER_PATTERN, VERSION_NUMBER_REGEX, VersionNumber, type FormatOptionsBase as VersionNumberToStringOptions, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, encryptWithKey, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseIndents, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, stringListToArray, stringifyDotenv, truncate, wait, zodVersionNumber };
|
|
1115
|
+
export { APIError, type ArrayElement, type CallReturnType, CamelToKebabOptions, type CreateEnumType, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, DataError, type DisallowUndefined, Env, FILE_PATH_PATTERN, FILE_PATH_REGEX, type FormDataArrayResolutionStrategy, type FormDataNullableResolutionStrategy, type HTTPErrorCode, type IgnoreCase, type IsTypeArgumentString, KebabToCamelOptions, type NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, ONE_DAY_IN_MILLISECONDS, type OptionalOnCondition, ParallelTuple, type RecordKey, type RemoveUndefined, type StringListToArrayOptions, UUID_PATTERN, UUID_REGEX, VERSION_NUMBER_PATTERN, VERSION_NUMBER_REGEX, VersionNumber, type FormatOptionsBase as VersionNumberToStringOptions, VersionType, addDaysToDate, appendSemicolon, calculateMonthlyDifference, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, encryptWithKey, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseIndents, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseUUID, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, stringListToArray, stringifyDotenv, truncate, wait, zodVersionNumber };
|
package/dist/index.js
CHANGED
|
@@ -519,6 +519,21 @@ function addDaysToDate(currentDate = /* @__PURE__ */ new Date(), dayIncrement =
|
|
|
519
519
|
return newDate;
|
|
520
520
|
}
|
|
521
521
|
|
|
522
|
+
//#endregion
|
|
523
|
+
//#region src/root/functions/date/calculateMonthlyDifference.ts
|
|
524
|
+
/**
|
|
525
|
+
* Calculates the monthly difference between two given dates, subtracting the first from
|
|
526
|
+
* the second and gives a negative result if the first date occurs earlier than the second.
|
|
527
|
+
*
|
|
528
|
+
* @param firstDate - The first date
|
|
529
|
+
* @param secondDate - The second date
|
|
530
|
+
*
|
|
531
|
+
* @returns The calculated difference as a number
|
|
532
|
+
*/
|
|
533
|
+
function calculateMonthlyDifference(firstDate, secondDate) {
|
|
534
|
+
return firstDate.getMonth() - secondDate.getMonth();
|
|
535
|
+
}
|
|
536
|
+
|
|
522
537
|
//#endregion
|
|
523
538
|
//#region src/root/functions/date/isSameDate.ts
|
|
524
539
|
/**
|
|
@@ -1372,6 +1387,25 @@ function parseFormData(formData, dataParser) {
|
|
|
1372
1387
|
return object;
|
|
1373
1388
|
}
|
|
1374
1389
|
|
|
1390
|
+
//#endregion
|
|
1391
|
+
//#region src/root/functions/parsers/parseUUID.ts
|
|
1392
|
+
/**
|
|
1393
|
+
* Parses the input and verifies it is a valid UUID.
|
|
1394
|
+
*
|
|
1395
|
+
* @category Parsers
|
|
1396
|
+
*
|
|
1397
|
+
* @param input - The data to parse.
|
|
1398
|
+
*
|
|
1399
|
+
* @throws {DataError} If the data does not match the general UUID pattern.
|
|
1400
|
+
*
|
|
1401
|
+
* @returns The UUID again if successful.
|
|
1402
|
+
*/
|
|
1403
|
+
function parseUUID(input) {
|
|
1404
|
+
if (!(typeof input === "string")) throw new DataError({ input }, "INVALID_TYPE", "Invalid type - expected string.");
|
|
1405
|
+
if (!UUID_REGEX.test(input)) throw new DataError({ input }, "INVALID_UUID", "The provided input does not match the expected shape for a UUID.");
|
|
1406
|
+
return input;
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1375
1409
|
//#endregion
|
|
1376
1410
|
//#region src/root/functions/parsers/parseVersionType.ts
|
|
1377
1411
|
/**
|
|
@@ -1586,4 +1620,4 @@ function truncate(stringToTruncate, maxLength = 5) {
|
|
|
1586
1620
|
}
|
|
1587
1621
|
|
|
1588
1622
|
//#endregion
|
|
1589
|
-
export { APIError, DataError, Env, FILE_PATH_PATTERN, FILE_PATH_REGEX, ONE_DAY_IN_MILLISECONDS, UUID_PATTERN, UUID_REGEX, VERSION_NUMBER_PATTERN, VERSION_NUMBER_REGEX, VersionNumber, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, encryptWithKey, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseIndents, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, stringListToArray, stringifyDotenv, truncate, wait, zodVersionNumber };
|
|
1623
|
+
export { APIError, DataError, Env, FILE_PATH_PATTERN, FILE_PATH_REGEX, ONE_DAY_IN_MILLISECONDS, UUID_PATTERN, UUID_REGEX, VERSION_NUMBER_PATTERN, VERSION_NUMBER_REGEX, VersionNumber, VersionType, addDaysToDate, appendSemicolon, calculateMonthlyDifference, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, encryptWithKey, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseIndents, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseUUID, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, stringListToArray, stringifyDotenv, truncate, wait, zodVersionNumber };
|