@alextheman/utility 5.24.0 → 5.26.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 +22 -0
- package/dist/index.d.cts +19 -7
- package/dist/index.d.ts +19 -7
- package/dist/index.js +22 -1
- package/dist/internal/index.d.cts +2 -1
- package/dist/internal/index.d.ts +1 -0
- package/dist/node/index.d.cts +2 -0
- package/dist/node/index.d.ts +2 -0
- package/dist/temporal/index.cjs +35 -0
- package/dist/temporal/index.d.cts +20 -0
- package/dist/temporal/index.d.ts +20 -0
- package/dist/temporal/index.js +34 -0
- package/dist/v6/index.d.cts +2 -0
- package/dist/v6/index.d.ts +2 -0
- package/package.json +14 -9
package/dist/index.cjs
CHANGED
|
@@ -858,6 +858,27 @@ function isOrdered(array) {
|
|
|
858
858
|
return true;
|
|
859
859
|
}
|
|
860
860
|
//#endregion
|
|
861
|
+
//#region src/root/functions/miscellaneous/memoizeAsync.ts
|
|
862
|
+
/**
|
|
863
|
+
* Memoizes the Promise returned by an asynchronous callback.
|
|
864
|
+
*
|
|
865
|
+
* Note that the callback is invoked at most once. Arguments supplied to subsequent calls are ignored because the Promise from the first invocation is always returned.
|
|
866
|
+
*
|
|
867
|
+
* @template ArgsType - The type of the function arguments.
|
|
868
|
+
* @template ResolvedType - The type of the Promise when resolved.
|
|
869
|
+
*
|
|
870
|
+
* @param callback - The function to memoize.
|
|
871
|
+
*
|
|
872
|
+
* @returns A callback with the Promise memoized. Multiple calls of this function should always point to the same Promise.
|
|
873
|
+
*/
|
|
874
|
+
function memoizeAsync(callback) {
|
|
875
|
+
let promise;
|
|
876
|
+
return (...args) => {
|
|
877
|
+
promise ??= callback(...args);
|
|
878
|
+
return promise;
|
|
879
|
+
};
|
|
880
|
+
}
|
|
881
|
+
//#endregion
|
|
861
882
|
//#region src/root/functions/miscellaneous/sayHello.ts
|
|
862
883
|
/**
|
|
863
884
|
* Returns a string representing the lyrics to the package's theme song, Commit To You
|
|
@@ -2103,6 +2124,7 @@ exports.isOrdered = isOrdered;
|
|
|
2103
2124
|
exports.isSameDate = isSameDate;
|
|
2104
2125
|
exports.isTemplateStringsArray = isTemplateStringsArray;
|
|
2105
2126
|
exports.kebabToCamel = kebabToCamel;
|
|
2127
|
+
exports.memoizeAsync = memoizeAsync;
|
|
2106
2128
|
exports.normaliseIndents = normaliseIndents;
|
|
2107
2129
|
exports.normalizeIndents = normalizeIndents;
|
|
2108
2130
|
exports.objectContainsKeys = objectContainsKeys;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import z, { ZodCoercedDate, ZodCoercedNumber, ZodError, ZodType, z as z$1 } from "zod";
|
|
2
2
|
import { DotenvParseOutput } from "dotenv";
|
|
3
|
-
|
|
4
3
|
//#region src/root/constants/FILE_PATH_REGEX.d.ts
|
|
5
4
|
declare const FILE_PATH_REGEX_PATTERN: string;
|
|
6
5
|
declare const FILE_PATH_REGEX: RegExp;
|
|
@@ -438,6 +437,22 @@ declare function identity<InputType>(input: InputType): InputType;
|
|
|
438
437
|
*/
|
|
439
438
|
declare function isOrdered(array: ReadonlyArray<number>): boolean;
|
|
440
439
|
//#endregion
|
|
440
|
+
//#region src/root/functions/miscellaneous/memoizeAsync.d.ts
|
|
441
|
+
type Callback<ArgsType extends ReadonlyArray<unknown>, ResolvedType> = (...args: ArgsType) => Promise<ResolvedType>;
|
|
442
|
+
/**
|
|
443
|
+
* Memoizes the Promise returned by an asynchronous callback.
|
|
444
|
+
*
|
|
445
|
+
* Note that the callback is invoked at most once. Arguments supplied to subsequent calls are ignored because the Promise from the first invocation is always returned.
|
|
446
|
+
*
|
|
447
|
+
* @template ArgsType - The type of the function arguments.
|
|
448
|
+
* @template ResolvedType - The type of the Promise when resolved.
|
|
449
|
+
*
|
|
450
|
+
* @param callback - The function to memoize.
|
|
451
|
+
*
|
|
452
|
+
* @returns A callback with the Promise memoized. Multiple calls of this function should always point to the same Promise.
|
|
453
|
+
*/
|
|
454
|
+
declare function memoizeAsync<ArgsType extends ReadonlyArray<unknown>, ResolvedType>(callback: Callback<ArgsType, ResolvedType>): Callback<ArgsType, ResolvedType>;
|
|
455
|
+
//#endregion
|
|
441
456
|
//#region src/root/functions/miscellaneous/sayHello.d.ts
|
|
442
457
|
/**
|
|
443
458
|
* Returns a string representing the lyrics to the package's theme song, Commit To You
|
|
@@ -697,10 +712,7 @@ interface StringListToArrayOptions {
|
|
|
697
712
|
*
|
|
698
713
|
* @returns A new array with each item being an item from the given list.
|
|
699
714
|
*/
|
|
700
|
-
declare function stringListToArray(stringList: string, {
|
|
701
|
-
separator,
|
|
702
|
-
trimWhitespace
|
|
703
|
-
}?: StringListToArrayOptions): Array<string>;
|
|
715
|
+
declare function stringListToArray(stringList: string, { separator, trimWhitespace }?: StringListToArrayOptions): Array<string>;
|
|
704
716
|
//#endregion
|
|
705
717
|
//#region src/root/functions/miscellaneous/wait.d.ts
|
|
706
718
|
/**
|
|
@@ -761,7 +773,7 @@ declare function omitProperties<ObjectType extends object, KeysToOmit extends ke
|
|
|
761
773
|
declare function pickProperties<ObjectType extends object, KeysToPick extends keyof ObjectType>(object: ObjectType, keysToPick: KeysToPick | ReadonlyArray<KeysToPick>): Pick<ObjectType, KeysToPick>;
|
|
762
774
|
//#endregion
|
|
763
775
|
//#region src/root/functions/objectHelpers/removeUndefinedFromObject.d.ts
|
|
764
|
-
type RemoveUndefined<RecordType extends Record<PropertyKey, unknown>> = { [Key in keyof RecordType]: Exclude<RecordType[Key], undefined
|
|
776
|
+
type RemoveUndefined<RecordType extends Record<PropertyKey, unknown>> = { [Key in keyof RecordType]: Exclude<RecordType[Key], undefined>; };
|
|
765
777
|
/**
|
|
766
778
|
* Removes entries whose values are `undefined` from a given object (not including null etc.).
|
|
767
779
|
*
|
|
@@ -1499,4 +1511,4 @@ interface ZodParsingErrorData {
|
|
|
1499
1511
|
issues: Array<z.core.$ZodIssue>;
|
|
1500
1512
|
}
|
|
1501
1513
|
//#endregion
|
|
1502
|
-
export { APIError, type ArrayElement, type CallReturnType, type CamelToKebabOptions, type CreateEnumType, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, DataError, type DisallowUndefined, Env, FILE_PATH_PATTERN, FILE_PATH_REGEX, FILE_PATH_REGEX_PATTERN, type FormDataArrayResolutionStrategy, type FormDataNullableResolutionStrategy, type HTTPErrorCode, type IgnoreCase, type IsTypeArgumentString, type KebabToCamelOptions, type NonNull, type NonUndefined, type NormaliseIndentsFunction, type NormaliseIndentsOptions, type NormalizeIndentsFunction, type NormalizeIndentsOptions, type NullableOnCondition, ONE_DAY_IN_MILLISECONDS, type OptionalOnCondition, type ParallelTuple, type RecordKey, type RemoveUndefined, SortDirection, type StringListToArrayOptions, type ToTitleCaseOptions, UUID_PATTERN, UUID_REGEX, UUID_REGEX_PATTERN, VERSION_NUMBER_PATTERN, VERSION_NUMBER_REGEX, VERSION_NUMBER_REGEX_PATTERN, VersionNumber, type FormatOptionsBase as VersionNumberToStringOptions, VersionType, type ZodParsingErrorData, addDaysToDate, appendSemicolon, assertNotNull, assertNotNullable, assertNotUndefined, az, calculateMonthlyDifference, camelToKebab, containsKeys, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, escapeHTML, escapeRegexPattern, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, identity, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isNonNullableObject, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseIndents, normalizeIndents, objectContainsKeys, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseUUID, parseVersionType, parseZodSchema, parseZodSchemaAsync, pickProperties, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, sortBy, stringListToArray, stringifyDotenv, toTitleCase, truncate, wait, zodVersionNumber };
|
|
1514
|
+
export { APIError, type ArrayElement, type CallReturnType, type CamelToKebabOptions, type CreateEnumType, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, DataError, type DisallowUndefined, Env, FILE_PATH_PATTERN, FILE_PATH_REGEX, FILE_PATH_REGEX_PATTERN, type FormDataArrayResolutionStrategy, type FormDataNullableResolutionStrategy, type HTTPErrorCode, type IgnoreCase, type IsTypeArgumentString, type KebabToCamelOptions, type NonNull, type NonUndefined, type NormaliseIndentsFunction, type NormaliseIndentsOptions, type NormalizeIndentsFunction, type NormalizeIndentsOptions, type NullableOnCondition, ONE_DAY_IN_MILLISECONDS, type OptionalOnCondition, type ParallelTuple, type RecordKey, type RemoveUndefined, SortDirection, type StringListToArrayOptions, type ToTitleCaseOptions, UUID_PATTERN, UUID_REGEX, UUID_REGEX_PATTERN, VERSION_NUMBER_PATTERN, VERSION_NUMBER_REGEX, VERSION_NUMBER_REGEX_PATTERN, VersionNumber, type FormatOptionsBase as VersionNumberToStringOptions, VersionType, type ZodParsingErrorData, addDaysToDate, appendSemicolon, assertNotNull, assertNotNullable, assertNotUndefined, az, calculateMonthlyDifference, camelToKebab, containsKeys, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, escapeHTML, escapeRegexPattern, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, identity, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isNonNullableObject, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, memoizeAsync, normaliseIndents, normalizeIndents, objectContainsKeys, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseUUID, parseVersionType, parseZodSchema, parseZodSchemaAsync, pickProperties, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, sortBy, stringListToArray, stringifyDotenv, toTitleCase, truncate, wait, zodVersionNumber };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import z, { ZodCoercedDate, ZodCoercedNumber, ZodError, ZodType, z as z$1 } from "zod";
|
|
2
2
|
import { DotenvParseOutput } from "dotenv";
|
|
3
|
-
|
|
4
3
|
//#region src/root/constants/FILE_PATH_REGEX.d.ts
|
|
5
4
|
declare const FILE_PATH_REGEX_PATTERN: string;
|
|
6
5
|
declare const FILE_PATH_REGEX: RegExp;
|
|
@@ -438,6 +437,22 @@ declare function identity<InputType>(input: InputType): InputType;
|
|
|
438
437
|
*/
|
|
439
438
|
declare function isOrdered(array: ReadonlyArray<number>): boolean;
|
|
440
439
|
//#endregion
|
|
440
|
+
//#region src/root/functions/miscellaneous/memoizeAsync.d.ts
|
|
441
|
+
type Callback<ArgsType extends ReadonlyArray<unknown>, ResolvedType> = (...args: ArgsType) => Promise<ResolvedType>;
|
|
442
|
+
/**
|
|
443
|
+
* Memoizes the Promise returned by an asynchronous callback.
|
|
444
|
+
*
|
|
445
|
+
* Note that the callback is invoked at most once. Arguments supplied to subsequent calls are ignored because the Promise from the first invocation is always returned.
|
|
446
|
+
*
|
|
447
|
+
* @template ArgsType - The type of the function arguments.
|
|
448
|
+
* @template ResolvedType - The type of the Promise when resolved.
|
|
449
|
+
*
|
|
450
|
+
* @param callback - The function to memoize.
|
|
451
|
+
*
|
|
452
|
+
* @returns A callback with the Promise memoized. Multiple calls of this function should always point to the same Promise.
|
|
453
|
+
*/
|
|
454
|
+
declare function memoizeAsync<ArgsType extends ReadonlyArray<unknown>, ResolvedType>(callback: Callback<ArgsType, ResolvedType>): Callback<ArgsType, ResolvedType>;
|
|
455
|
+
//#endregion
|
|
441
456
|
//#region src/root/functions/miscellaneous/sayHello.d.ts
|
|
442
457
|
/**
|
|
443
458
|
* Returns a string representing the lyrics to the package's theme song, Commit To You
|
|
@@ -697,10 +712,7 @@ interface StringListToArrayOptions {
|
|
|
697
712
|
*
|
|
698
713
|
* @returns A new array with each item being an item from the given list.
|
|
699
714
|
*/
|
|
700
|
-
declare function stringListToArray(stringList: string, {
|
|
701
|
-
separator,
|
|
702
|
-
trimWhitespace
|
|
703
|
-
}?: StringListToArrayOptions): Array<string>;
|
|
715
|
+
declare function stringListToArray(stringList: string, { separator, trimWhitespace }?: StringListToArrayOptions): Array<string>;
|
|
704
716
|
//#endregion
|
|
705
717
|
//#region src/root/functions/miscellaneous/wait.d.ts
|
|
706
718
|
/**
|
|
@@ -761,7 +773,7 @@ declare function omitProperties<ObjectType extends object, KeysToOmit extends ke
|
|
|
761
773
|
declare function pickProperties<ObjectType extends object, KeysToPick extends keyof ObjectType>(object: ObjectType, keysToPick: KeysToPick | ReadonlyArray<KeysToPick>): Pick<ObjectType, KeysToPick>;
|
|
762
774
|
//#endregion
|
|
763
775
|
//#region src/root/functions/objectHelpers/removeUndefinedFromObject.d.ts
|
|
764
|
-
type RemoveUndefined<RecordType extends Record<PropertyKey, unknown>> = { [Key in keyof RecordType]: Exclude<RecordType[Key], undefined
|
|
776
|
+
type RemoveUndefined<RecordType extends Record<PropertyKey, unknown>> = { [Key in keyof RecordType]: Exclude<RecordType[Key], undefined>; };
|
|
765
777
|
/**
|
|
766
778
|
* Removes entries whose values are `undefined` from a given object (not including null etc.).
|
|
767
779
|
*
|
|
@@ -1499,4 +1511,4 @@ interface ZodParsingErrorData {
|
|
|
1499
1511
|
issues: Array<z.core.$ZodIssue>;
|
|
1500
1512
|
}
|
|
1501
1513
|
//#endregion
|
|
1502
|
-
export { APIError, type ArrayElement, type CallReturnType, type CamelToKebabOptions, type CreateEnumType, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, DataError, type DisallowUndefined, Env, FILE_PATH_PATTERN, FILE_PATH_REGEX, FILE_PATH_REGEX_PATTERN, type FormDataArrayResolutionStrategy, type FormDataNullableResolutionStrategy, type HTTPErrorCode, type IgnoreCase, type IsTypeArgumentString, type KebabToCamelOptions, type NonNull, type NonUndefined, type NormaliseIndentsFunction, type NormaliseIndentsOptions, type NormalizeIndentsFunction, type NormalizeIndentsOptions, type NullableOnCondition, ONE_DAY_IN_MILLISECONDS, type OptionalOnCondition, type ParallelTuple, type RecordKey, type RemoveUndefined, SortDirection, type StringListToArrayOptions, type ToTitleCaseOptions, UUID_PATTERN, UUID_REGEX, UUID_REGEX_PATTERN, VERSION_NUMBER_PATTERN, VERSION_NUMBER_REGEX, VERSION_NUMBER_REGEX_PATTERN, VersionNumber, type FormatOptionsBase as VersionNumberToStringOptions, VersionType, type ZodParsingErrorData, addDaysToDate, appendSemicolon, assertNotNull, assertNotNullable, assertNotUndefined, az, calculateMonthlyDifference, camelToKebab, containsKeys, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, escapeHTML, escapeRegexPattern, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, identity, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isNonNullableObject, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseIndents, normalizeIndents, objectContainsKeys, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseUUID, parseVersionType, parseZodSchema, parseZodSchemaAsync, pickProperties, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, sortBy, stringListToArray, stringifyDotenv, toTitleCase, truncate, wait, zodVersionNumber };
|
|
1514
|
+
export { APIError, type ArrayElement, type CallReturnType, type CamelToKebabOptions, type CreateEnumType, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, DataError, type DisallowUndefined, Env, FILE_PATH_PATTERN, FILE_PATH_REGEX, FILE_PATH_REGEX_PATTERN, type FormDataArrayResolutionStrategy, type FormDataNullableResolutionStrategy, type HTTPErrorCode, type IgnoreCase, type IsTypeArgumentString, type KebabToCamelOptions, type NonNull, type NonUndefined, type NormaliseIndentsFunction, type NormaliseIndentsOptions, type NormalizeIndentsFunction, type NormalizeIndentsOptions, type NullableOnCondition, ONE_DAY_IN_MILLISECONDS, type OptionalOnCondition, type ParallelTuple, type RecordKey, type RemoveUndefined, SortDirection, type StringListToArrayOptions, type ToTitleCaseOptions, UUID_PATTERN, UUID_REGEX, UUID_REGEX_PATTERN, VERSION_NUMBER_PATTERN, VERSION_NUMBER_REGEX, VERSION_NUMBER_REGEX_PATTERN, VersionNumber, type FormatOptionsBase as VersionNumberToStringOptions, VersionType, type ZodParsingErrorData, addDaysToDate, appendSemicolon, assertNotNull, assertNotNullable, assertNotUndefined, az, calculateMonthlyDifference, camelToKebab, containsKeys, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, escapeHTML, escapeRegexPattern, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, identity, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isNonNullableObject, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, memoizeAsync, normaliseIndents, normalizeIndents, objectContainsKeys, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseUUID, parseVersionType, parseZodSchema, parseZodSchemaAsync, pickProperties, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, sortBy, stringListToArray, stringifyDotenv, toTitleCase, truncate, wait, zodVersionNumber };
|
package/dist/index.js
CHANGED
|
@@ -834,6 +834,27 @@ function isOrdered(array) {
|
|
|
834
834
|
return true;
|
|
835
835
|
}
|
|
836
836
|
//#endregion
|
|
837
|
+
//#region src/root/functions/miscellaneous/memoizeAsync.ts
|
|
838
|
+
/**
|
|
839
|
+
* Memoizes the Promise returned by an asynchronous callback.
|
|
840
|
+
*
|
|
841
|
+
* Note that the callback is invoked at most once. Arguments supplied to subsequent calls are ignored because the Promise from the first invocation is always returned.
|
|
842
|
+
*
|
|
843
|
+
* @template ArgsType - The type of the function arguments.
|
|
844
|
+
* @template ResolvedType - The type of the Promise when resolved.
|
|
845
|
+
*
|
|
846
|
+
* @param callback - The function to memoize.
|
|
847
|
+
*
|
|
848
|
+
* @returns A callback with the Promise memoized. Multiple calls of this function should always point to the same Promise.
|
|
849
|
+
*/
|
|
850
|
+
function memoizeAsync(callback) {
|
|
851
|
+
let promise;
|
|
852
|
+
return (...args) => {
|
|
853
|
+
promise ??= callback(...args);
|
|
854
|
+
return promise;
|
|
855
|
+
};
|
|
856
|
+
}
|
|
857
|
+
//#endregion
|
|
837
858
|
//#region src/root/functions/miscellaneous/sayHello.ts
|
|
838
859
|
/**
|
|
839
860
|
* Returns a string representing the lyrics to the package's theme song, Commit To You
|
|
@@ -2030,4 +2051,4 @@ const UUID_PATTERN = UUID_REGEX_PATTERN;
|
|
|
2030
2051
|
/** @deprecated This has been renamed to `VERSION_NUMBER_REGEX_PATTERN`. */
|
|
2031
2052
|
const VERSION_NUMBER_PATTERN = String.raw`^(?:v)?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$`;
|
|
2032
2053
|
//#endregion
|
|
2033
|
-
export { APIError, DataError, Env, FILE_PATH_PATTERN, FILE_PATH_REGEX, FILE_PATH_REGEX_PATTERN, ONE_DAY_IN_MILLISECONDS, SortDirection, UUID_PATTERN, UUID_REGEX, UUID_REGEX_PATTERN, VERSION_NUMBER_PATTERN, VERSION_NUMBER_REGEX, VERSION_NUMBER_REGEX_PATTERN, VersionNumber, VersionType, addDaysToDate, appendSemicolon, assertNotNull, assertNotNullable, assertNotUndefined, az, calculateMonthlyDifference, camelToKebab, containsKeys, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, escapeHTML, escapeRegexPattern, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, identity, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isNonNullableObject, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseIndents, normalizeIndents, objectContainsKeys, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseUUID, parseVersionType, parseZodSchema, parseZodSchemaAsync, pickProperties, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, sortBy, stringListToArray, stringifyDotenv, toTitleCase, truncate, wait, zodVersionNumber };
|
|
2054
|
+
export { APIError, DataError, Env, FILE_PATH_PATTERN, FILE_PATH_REGEX, FILE_PATH_REGEX_PATTERN, ONE_DAY_IN_MILLISECONDS, SortDirection, UUID_PATTERN, UUID_REGEX, UUID_REGEX_PATTERN, VERSION_NUMBER_PATTERN, VERSION_NUMBER_REGEX, VERSION_NUMBER_REGEX_PATTERN, VersionNumber, VersionType, addDaysToDate, appendSemicolon, assertNotNull, assertNotNullable, assertNotUndefined, az, calculateMonthlyDifference, camelToKebab, containsKeys, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, escapeHTML, escapeRegexPattern, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, identity, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isNonNullableObject, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, memoizeAsync, normaliseIndents, normalizeIndents, objectContainsKeys, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseUUID, parseVersionType, parseZodSchema, parseZodSchemaAsync, pickProperties, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, sortBy, stringListToArray, stringifyDotenv, toTitleCase, truncate, wait, zodVersionNumber };
|
package/dist/internal/index.d.ts
CHANGED
package/dist/node/index.d.cts
CHANGED
package/dist/node/index.d.ts
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/temporal/formatRelativeDateAndTime.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a human-readable string describing the input date relative to the reference date.
|
|
5
|
+
*
|
|
6
|
+
* If no reference date is provided, the current local date and time is used as the reference.
|
|
7
|
+
*
|
|
8
|
+
* @category Temporal
|
|
9
|
+
*
|
|
10
|
+
* @param input - The date and time to format.
|
|
11
|
+
* @param reference - The date and time to compare the input against.
|
|
12
|
+
*
|
|
13
|
+
* @returns A human-readable string describing the input date relative to the reference date.
|
|
14
|
+
*
|
|
15
|
+
* - If the date given is today, the output will be something like `Today at HH:MM`
|
|
16
|
+
* - If the date given happened yesterday, the output will be something like `Yesterday at HH:MM`
|
|
17
|
+
* - For any other date, the output will be something like `DD/MM/YYYY, HH:MM`
|
|
18
|
+
*/
|
|
19
|
+
function formatRelativeDateAndTime(input, reference = Temporal.Now.plainDateTimeISO()) {
|
|
20
|
+
const inputPlainDate = input.toPlainDate();
|
|
21
|
+
const referencePlainDate = reference.toPlainDate();
|
|
22
|
+
const formattedTime = input.toLocaleString("en-GB", {
|
|
23
|
+
hour: "2-digit",
|
|
24
|
+
minute: "2-digit"
|
|
25
|
+
});
|
|
26
|
+
if (inputPlainDate.equals(referencePlainDate.subtract({ days: 1 }))) return `Yesterday at ${formattedTime}`;
|
|
27
|
+
if (inputPlainDate.equals(referencePlainDate)) return `Today at ${formattedTime}`;
|
|
28
|
+
return `${input.toLocaleString("en-GB", {
|
|
29
|
+
day: "2-digit",
|
|
30
|
+
month: "2-digit",
|
|
31
|
+
year: "numeric"
|
|
32
|
+
})}, ${formattedTime}`;
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
exports.formatRelativeDateAndTime = formatRelativeDateAndTime;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/temporal/formatRelativeDateAndTime.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a human-readable string describing the input date relative to the reference date.
|
|
4
|
+
*
|
|
5
|
+
* If no reference date is provided, the current local date and time is used as the reference.
|
|
6
|
+
*
|
|
7
|
+
* @category Temporal
|
|
8
|
+
*
|
|
9
|
+
* @param input - The date and time to format.
|
|
10
|
+
* @param reference - The date and time to compare the input against.
|
|
11
|
+
*
|
|
12
|
+
* @returns A human-readable string describing the input date relative to the reference date.
|
|
13
|
+
*
|
|
14
|
+
* - If the date given is today, the output will be something like `Today at HH:MM`
|
|
15
|
+
* - If the date given happened yesterday, the output will be something like `Yesterday at HH:MM`
|
|
16
|
+
* - For any other date, the output will be something like `DD/MM/YYYY, HH:MM`
|
|
17
|
+
*/
|
|
18
|
+
declare function formatRelativeDateAndTime(input: Temporal.PlainDateTime | Temporal.ZonedDateTime, reference?: Temporal.PlainDateTime | Temporal.ZonedDateTime): string;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { formatRelativeDateAndTime };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/temporal/formatRelativeDateAndTime.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a human-readable string describing the input date relative to the reference date.
|
|
4
|
+
*
|
|
5
|
+
* If no reference date is provided, the current local date and time is used as the reference.
|
|
6
|
+
*
|
|
7
|
+
* @category Temporal
|
|
8
|
+
*
|
|
9
|
+
* @param input - The date and time to format.
|
|
10
|
+
* @param reference - The date and time to compare the input against.
|
|
11
|
+
*
|
|
12
|
+
* @returns A human-readable string describing the input date relative to the reference date.
|
|
13
|
+
*
|
|
14
|
+
* - If the date given is today, the output will be something like `Today at HH:MM`
|
|
15
|
+
* - If the date given happened yesterday, the output will be something like `Yesterday at HH:MM`
|
|
16
|
+
* - For any other date, the output will be something like `DD/MM/YYYY, HH:MM`
|
|
17
|
+
*/
|
|
18
|
+
declare function formatRelativeDateAndTime(input: Temporal.PlainDateTime | Temporal.ZonedDateTime, reference?: Temporal.PlainDateTime | Temporal.ZonedDateTime): string;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { formatRelativeDateAndTime };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//#region src/temporal/formatRelativeDateAndTime.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a human-readable string describing the input date relative to the reference date.
|
|
4
|
+
*
|
|
5
|
+
* If no reference date is provided, the current local date and time is used as the reference.
|
|
6
|
+
*
|
|
7
|
+
* @category Temporal
|
|
8
|
+
*
|
|
9
|
+
* @param input - The date and time to format.
|
|
10
|
+
* @param reference - The date and time to compare the input against.
|
|
11
|
+
*
|
|
12
|
+
* @returns A human-readable string describing the input date relative to the reference date.
|
|
13
|
+
*
|
|
14
|
+
* - If the date given is today, the output will be something like `Today at HH:MM`
|
|
15
|
+
* - If the date given happened yesterday, the output will be something like `Yesterday at HH:MM`
|
|
16
|
+
* - For any other date, the output will be something like `DD/MM/YYYY, HH:MM`
|
|
17
|
+
*/
|
|
18
|
+
function formatRelativeDateAndTime(input, reference = Temporal.Now.plainDateTimeISO()) {
|
|
19
|
+
const inputPlainDate = input.toPlainDate();
|
|
20
|
+
const referencePlainDate = reference.toPlainDate();
|
|
21
|
+
const formattedTime = input.toLocaleString("en-GB", {
|
|
22
|
+
hour: "2-digit",
|
|
23
|
+
minute: "2-digit"
|
|
24
|
+
});
|
|
25
|
+
if (inputPlainDate.equals(referencePlainDate.subtract({ days: 1 }))) return `Yesterday at ${formattedTime}`;
|
|
26
|
+
if (inputPlainDate.equals(referencePlainDate)) return `Today at ${formattedTime}`;
|
|
27
|
+
return `${input.toLocaleString("en-GB", {
|
|
28
|
+
day: "2-digit",
|
|
29
|
+
month: "2-digit",
|
|
30
|
+
year: "numeric"
|
|
31
|
+
})}, ${formattedTime}`;
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
export { formatRelativeDateAndTime };
|
package/dist/v6/index.d.cts
CHANGED
package/dist/v6/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alextheman/utility",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.26.0",
|
|
4
4
|
"description": "Helpful utility functions.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,6 +26,11 @@
|
|
|
26
26
|
"import": "./dist/node/index.js",
|
|
27
27
|
"require": "./dist/node/index.cjs"
|
|
28
28
|
},
|
|
29
|
+
"./temporal": {
|
|
30
|
+
"types": "./dist/temporal/index.d.ts",
|
|
31
|
+
"import": "./dist/temporal/index.js",
|
|
32
|
+
"require": "./dist/temporal/index.cjs"
|
|
33
|
+
},
|
|
29
34
|
"./v6": {
|
|
30
35
|
"types": "./dist/v6/index.d.ts",
|
|
31
36
|
"import": "./dist/v6/index.js",
|
|
@@ -41,8 +46,8 @@
|
|
|
41
46
|
},
|
|
42
47
|
"devDependencies": {
|
|
43
48
|
"@alextheman/eslint-plugin": "5.18.0",
|
|
44
|
-
"@types/node": "26.1.
|
|
45
|
-
"alex-c-line": "2.
|
|
49
|
+
"@types/node": "26.1.1",
|
|
50
|
+
"alex-c-line": "2.12.4",
|
|
46
51
|
"cross-env": "10.1.0",
|
|
47
52
|
"dotenv-cli": "11.0.0",
|
|
48
53
|
"eslint": "10.6.0",
|
|
@@ -50,17 +55,17 @@
|
|
|
50
55
|
"husky": "9.1.7",
|
|
51
56
|
"jsdom": "29.1.1",
|
|
52
57
|
"markdownlint-cli2": "0.23.0",
|
|
53
|
-
"prettier": "3.9.
|
|
58
|
+
"prettier": "3.9.5",
|
|
54
59
|
"tempy": "3.2.0",
|
|
55
|
-
"tsdown": "0.22.
|
|
60
|
+
"tsdown": "0.22.4",
|
|
56
61
|
"tsx": "4.23.0",
|
|
57
|
-
"typedoc": "0.28.
|
|
62
|
+
"typedoc": "0.28.20",
|
|
58
63
|
"typedoc-plugin-markdown": "4.12.0",
|
|
59
64
|
"typedoc-rhineai-theme": "1.2.0",
|
|
60
65
|
"typescript": "6.0.3",
|
|
61
|
-
"typescript-eslint": "8.
|
|
62
|
-
"vite": "8.1.
|
|
63
|
-
"vitest": "4.1.
|
|
66
|
+
"typescript-eslint": "8.63.0",
|
|
67
|
+
"vite": "8.1.4",
|
|
68
|
+
"vitest": "4.1.10",
|
|
64
69
|
"zod": "4.4.3"
|
|
65
70
|
},
|
|
66
71
|
"engines": {
|