@alextheman/utility 5.4.1 → 5.6.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 +16 -0
- package/dist/index.d.cts +24 -1
- package/dist/index.d.ts +24 -1
- package/dist/index.js +16 -1
- package/dist/internal/index.cjs +10 -8
- package/dist/internal/index.d.cts +15 -1
- package/dist/internal/index.d.ts +15 -1
- package/dist/internal/index.js +10 -8
- package/package.json +9 -7
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
|
/**
|
|
@@ -1649,6 +1664,7 @@ exports.VersionNumber = VersionNumber;
|
|
|
1649
1664
|
exports.VersionType = VersionType;
|
|
1650
1665
|
exports.addDaysToDate = addDaysToDate;
|
|
1651
1666
|
exports.appendSemicolon = appendSemicolon;
|
|
1667
|
+
exports.calculateMonthlyDifference = calculateMonthlyDifference;
|
|
1652
1668
|
exports.camelToKebab = camelToKebab;
|
|
1653
1669
|
exports.convertFileToBase64 = convertFileToBase64;
|
|
1654
1670
|
exports.createFormData = createFormData;
|
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.
|
|
@@ -455,6 +467,17 @@ type IsTypeArgumentString<Argument extends string> = Argument;
|
|
|
455
467
|
*/
|
|
456
468
|
type NonUndefined<InputType> = InputType extends undefined ? never : InputType;
|
|
457
469
|
//#endregion
|
|
470
|
+
//#region src/root/types/NullableOnCondition.d.ts
|
|
471
|
+
/**
|
|
472
|
+
* Resolves to the given type if the first type is `true`, otherwise resolves to `null`
|
|
473
|
+
*
|
|
474
|
+
* @category Types
|
|
475
|
+
*
|
|
476
|
+
* @param Condition - The condition to check.
|
|
477
|
+
* @param ResolvedTypeIfTrue - The type to resolve to if the condition may be `true`.
|
|
478
|
+
*/
|
|
479
|
+
type NullableOnCondition<Condition extends boolean, ResolvedTypeIfTrue> = Condition extends true ? ResolvedTypeIfTrue : ResolvedTypeIfTrue | null;
|
|
480
|
+
//#endregion
|
|
458
481
|
//#region src/root/types/OptionalOnCondition.d.ts
|
|
459
482
|
/**
|
|
460
483
|
* Resolves to the given type if the first type is `true`, otherwise resolves to `undefined`
|
|
@@ -1100,4 +1123,4 @@ declare function normaliseIndents(strings: TemplateStringsArray, ...interpolatio
|
|
|
1100
1123
|
*/
|
|
1101
1124
|
declare const normalizeIndents: typeof normaliseIndents;
|
|
1102
1125
|
//#endregion
|
|
1103
|
-
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, parseUUID, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, stringListToArray, stringifyDotenv, truncate, wait, zodVersionNumber };
|
|
1126
|
+
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, NullableOnCondition, 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.
|
|
@@ -455,6 +467,17 @@ type IsTypeArgumentString<Argument extends string> = Argument;
|
|
|
455
467
|
*/
|
|
456
468
|
type NonUndefined<InputType> = InputType extends undefined ? never : InputType;
|
|
457
469
|
//#endregion
|
|
470
|
+
//#region src/root/types/NullableOnCondition.d.ts
|
|
471
|
+
/**
|
|
472
|
+
* Resolves to the given type if the first type is `true`, otherwise resolves to `null`
|
|
473
|
+
*
|
|
474
|
+
* @category Types
|
|
475
|
+
*
|
|
476
|
+
* @param Condition - The condition to check.
|
|
477
|
+
* @param ResolvedTypeIfTrue - The type to resolve to if the condition may be `true`.
|
|
478
|
+
*/
|
|
479
|
+
type NullableOnCondition<Condition extends boolean, ResolvedTypeIfTrue> = Condition extends true ? ResolvedTypeIfTrue : ResolvedTypeIfTrue | null;
|
|
480
|
+
//#endregion
|
|
458
481
|
//#region src/root/types/OptionalOnCondition.d.ts
|
|
459
482
|
/**
|
|
460
483
|
* Resolves to the given type if the first type is `true`, otherwise resolves to `undefined`
|
|
@@ -1100,4 +1123,4 @@ declare function normaliseIndents(strings: TemplateStringsArray, ...interpolatio
|
|
|
1100
1123
|
*/
|
|
1101
1124
|
declare const normalizeIndents: typeof normaliseIndents;
|
|
1102
1125
|
//#endregion
|
|
1103
|
-
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, parseUUID, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, stringListToArray, stringifyDotenv, truncate, wait, zodVersionNumber };
|
|
1126
|
+
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, type NullableOnCondition, 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
|
/**
|
|
@@ -1605,4 +1620,4 @@ function truncate(stringToTruncate, maxLength = 5) {
|
|
|
1605
1620
|
}
|
|
1606
1621
|
|
|
1607
1622
|
//#endregion
|
|
1608
|
-
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, parseUUID, 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 };
|
package/dist/internal/index.cjs
CHANGED
|
@@ -701,13 +701,21 @@ function getPackageJsonPath(directory) {
|
|
|
701
701
|
return node_path.default.join(...directory.endsWith("package.json") ? [directory] : [directory, "package.json"]);
|
|
702
702
|
}
|
|
703
703
|
|
|
704
|
+
//#endregion
|
|
705
|
+
//#region src/internal/packageJsonNotFoundError.ts
|
|
706
|
+
function packageJsonNotFoundError(packagePath) {
|
|
707
|
+
return new DataError({ packagePath: getPackageJsonPath(packagePath) }, "PACKAGE_JSON_NOT_FOUND", "Could not find package.json in directory.");
|
|
708
|
+
}
|
|
709
|
+
|
|
704
710
|
//#endregion
|
|
705
711
|
//#region src/internal/getPackageJsonContents.ts
|
|
706
|
-
async function getPackageJsonContents(directory) {
|
|
712
|
+
async function getPackageJsonContents(directory, options) {
|
|
713
|
+
const { strict = true } = options ?? {};
|
|
707
714
|
try {
|
|
708
715
|
return JSON.parse(await (0, node_fs_promises.readFile)(getPackageJsonPath(directory), "utf-8"));
|
|
709
716
|
} catch (error) {
|
|
710
|
-
if (error instanceof Error && "code" in error && error.code === "ENOENT")
|
|
717
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") if (strict) throw packageJsonNotFoundError(directory);
|
|
718
|
+
else return null;
|
|
711
719
|
throw error;
|
|
712
720
|
}
|
|
713
721
|
}
|
|
@@ -720,12 +728,6 @@ const ModuleType = {
|
|
|
720
728
|
TYPESCRIPT: "typescript"
|
|
721
729
|
};
|
|
722
730
|
|
|
723
|
-
//#endregion
|
|
724
|
-
//#region src/internal/packageJsonNotFoundError.ts
|
|
725
|
-
function packageJsonNotFoundError(packagePath) {
|
|
726
|
-
return new DataError({ packagePath: getPackageJsonPath(packagePath) }, "PACKAGE_JSON_NOT_FOUND", "Could not find package.json in directory.");
|
|
727
|
-
}
|
|
728
|
-
|
|
729
731
|
//#endregion
|
|
730
732
|
//#region src/internal/PackageManager.ts
|
|
731
733
|
const PackageManager = {
|
|
@@ -77,6 +77,17 @@ type CreateEnumType<ObjectType extends Record<RecordKey, unknown>> = ObjectType[
|
|
|
77
77
|
//#region src/root/types/IsTypeArgumentString.d.ts
|
|
78
78
|
type IsTypeArgumentString<Argument extends string> = Argument;
|
|
79
79
|
//#endregion
|
|
80
|
+
//#region src/root/types/NullableOnCondition.d.ts
|
|
81
|
+
/**
|
|
82
|
+
* Resolves to the given type if the first type is `true`, otherwise resolves to `null`
|
|
83
|
+
*
|
|
84
|
+
* @category Types
|
|
85
|
+
*
|
|
86
|
+
* @param Condition - The condition to check.
|
|
87
|
+
* @param ResolvedTypeIfTrue - The type to resolve to if the condition may be `true`.
|
|
88
|
+
*/
|
|
89
|
+
type NullableOnCondition<Condition extends boolean, ResolvedTypeIfTrue> = Condition extends true ? ResolvedTypeIfTrue : ResolvedTypeIfTrue | null;
|
|
90
|
+
//#endregion
|
|
80
91
|
//#region src/root/functions/miscellaneous/sayHello.d.ts
|
|
81
92
|
/**
|
|
82
93
|
* Returns a string representing the lyrics to the package's theme song, Commit To You
|
|
@@ -111,7 +122,10 @@ declare function getDependenciesFromGroup(packageInfo: Record<string, unknown>,
|
|
|
111
122
|
declare function getExpectedTgzName(packagePath: string, packageManager: string): Promise<string>;
|
|
112
123
|
//#endregion
|
|
113
124
|
//#region src/internal/getPackageJsonContents.d.ts
|
|
114
|
-
|
|
125
|
+
interface GetPackageJsonContentsOptions<Strict extends boolean = true> {
|
|
126
|
+
strict?: Strict;
|
|
127
|
+
}
|
|
128
|
+
declare function getPackageJsonContents<Strict extends boolean = true>(directory: string, options?: GetPackageJsonContentsOptions<Strict>): Promise<NullableOnCondition<Strict, Record<string, any>>>;
|
|
115
129
|
//#endregion
|
|
116
130
|
//#region src/internal/getPackageJsonPath.d.ts
|
|
117
131
|
declare function getPackageJsonPath(directory: string): string;
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -78,6 +78,17 @@ type CreateEnumType<ObjectType extends Record<RecordKey, unknown>> = ObjectType[
|
|
|
78
78
|
//#region src/root/types/IsTypeArgumentString.d.ts
|
|
79
79
|
type IsTypeArgumentString<Argument extends string> = Argument;
|
|
80
80
|
//#endregion
|
|
81
|
+
//#region src/root/types/NullableOnCondition.d.ts
|
|
82
|
+
/**
|
|
83
|
+
* Resolves to the given type if the first type is `true`, otherwise resolves to `null`
|
|
84
|
+
*
|
|
85
|
+
* @category Types
|
|
86
|
+
*
|
|
87
|
+
* @param Condition - The condition to check.
|
|
88
|
+
* @param ResolvedTypeIfTrue - The type to resolve to if the condition may be `true`.
|
|
89
|
+
*/
|
|
90
|
+
type NullableOnCondition<Condition extends boolean, ResolvedTypeIfTrue> = Condition extends true ? ResolvedTypeIfTrue : ResolvedTypeIfTrue | null;
|
|
91
|
+
//#endregion
|
|
81
92
|
//#region src/root/functions/miscellaneous/sayHello.d.ts
|
|
82
93
|
/**
|
|
83
94
|
* Returns a string representing the lyrics to the package's theme song, Commit To You
|
|
@@ -112,7 +123,10 @@ declare function getDependenciesFromGroup(packageInfo: Record<string, unknown>,
|
|
|
112
123
|
declare function getExpectedTgzName(packagePath: string, packageManager: string): Promise<string>;
|
|
113
124
|
//#endregion
|
|
114
125
|
//#region src/internal/getPackageJsonContents.d.ts
|
|
115
|
-
|
|
126
|
+
interface GetPackageJsonContentsOptions<Strict extends boolean = true> {
|
|
127
|
+
strict?: Strict;
|
|
128
|
+
}
|
|
129
|
+
declare function getPackageJsonContents<Strict extends boolean = true>(directory: string, options?: GetPackageJsonContentsOptions<Strict>): Promise<NullableOnCondition<Strict, Record<string, any>>>;
|
|
116
130
|
//#endregion
|
|
117
131
|
//#region src/internal/getPackageJsonPath.d.ts
|
|
118
132
|
declare function getPackageJsonPath(directory: string): string;
|
package/dist/internal/index.js
CHANGED
|
@@ -671,13 +671,21 @@ function getPackageJsonPath(directory) {
|
|
|
671
671
|
return path.join(...directory.endsWith("package.json") ? [directory] : [directory, "package.json"]);
|
|
672
672
|
}
|
|
673
673
|
|
|
674
|
+
//#endregion
|
|
675
|
+
//#region src/internal/packageJsonNotFoundError.ts
|
|
676
|
+
function packageJsonNotFoundError(packagePath) {
|
|
677
|
+
return new DataError({ packagePath: getPackageJsonPath(packagePath) }, "PACKAGE_JSON_NOT_FOUND", "Could not find package.json in directory.");
|
|
678
|
+
}
|
|
679
|
+
|
|
674
680
|
//#endregion
|
|
675
681
|
//#region src/internal/getPackageJsonContents.ts
|
|
676
|
-
async function getPackageJsonContents(directory) {
|
|
682
|
+
async function getPackageJsonContents(directory, options) {
|
|
683
|
+
const { strict = true } = options ?? {};
|
|
677
684
|
try {
|
|
678
685
|
return JSON.parse(await readFile(getPackageJsonPath(directory), "utf-8"));
|
|
679
686
|
} catch (error) {
|
|
680
|
-
if (error instanceof Error && "code" in error && error.code === "ENOENT")
|
|
687
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") if (strict) throw packageJsonNotFoundError(directory);
|
|
688
|
+
else return null;
|
|
681
689
|
throw error;
|
|
682
690
|
}
|
|
683
691
|
}
|
|
@@ -690,12 +698,6 @@ const ModuleType = {
|
|
|
690
698
|
TYPESCRIPT: "typescript"
|
|
691
699
|
};
|
|
692
700
|
|
|
693
|
-
//#endregion
|
|
694
|
-
//#region src/internal/packageJsonNotFoundError.ts
|
|
695
|
-
function packageJsonNotFoundError(packagePath) {
|
|
696
|
-
return new DataError({ packagePath: getPackageJsonPath(packagePath) }, "PACKAGE_JSON_NOT_FOUND", "Could not find package.json in directory.");
|
|
697
|
-
}
|
|
698
|
-
|
|
699
701
|
//#endregion
|
|
700
702
|
//#region src/internal/PackageManager.ts
|
|
701
703
|
const PackageManager = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alextheman/utility",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.6.0",
|
|
4
4
|
"description": "Helpful utility functions.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -36,11 +36,12 @@
|
|
|
36
36
|
"zod": "^4.3.6"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@alextheman/eslint-plugin": "^5.
|
|
40
|
-
"@types/node": "^25.3.
|
|
41
|
-
"alex-c-line": "^1.
|
|
39
|
+
"@alextheman/eslint-plugin": "^5.9.1",
|
|
40
|
+
"@types/node": "^25.3.3",
|
|
41
|
+
"alex-c-line": "^1.33.3",
|
|
42
|
+
"cross-env": "^10.1.0",
|
|
42
43
|
"dotenv-cli": "^11.0.0",
|
|
43
|
-
"eslint": "^10.0.
|
|
44
|
+
"eslint": "^10.0.2",
|
|
44
45
|
"globals": "^17.3.0",
|
|
45
46
|
"husky": "^9.1.7",
|
|
46
47
|
"jsdom": "^28.1.0",
|
|
@@ -67,8 +68,9 @@
|
|
|
67
68
|
"format-prettier-javascript": "prettier --write \"./**/*.js\"",
|
|
68
69
|
"format-prettier-typescript": "prettier --write --parser typescript \"./**/*.ts\"",
|
|
69
70
|
"format-prettier-yml": "prettier --write \"./**/*.{yml,yaml}\"",
|
|
70
|
-
"lint": "pnpm run lint-tsc && pnpm run lint-eslint && pnpm run lint-prettier",
|
|
71
|
+
"lint": "pnpm run lint-tsc && pnpm run lint-eslint && pnpm run lint-prettier && pnpm run lint-pre-release",
|
|
71
72
|
"lint-eslint": "eslint \"package.json\" \"src/**/*.ts\" \"tests/**/*.ts\"",
|
|
73
|
+
"lint-pre-release": "alex-c-line package-json no-pre-release-dependencies",
|
|
72
74
|
"lint-prettier": "pnpm run lint-prettier-typescript && pnpm run lint-prettier-javascript && pnpm run lint-prettier-yml",
|
|
73
75
|
"lint-prettier-javascript": "prettier --check \"./**/*.js\"",
|
|
74
76
|
"lint-prettier-typescript": "prettier --check --parser typescript \"./**/*.ts\"",
|
|
@@ -78,7 +80,7 @@
|
|
|
78
80
|
"prepare-live-eslint-plugin": "pnpm uninstall @alextheman/eslint-plugin && pnpm install --save-dev @alextheman/eslint-plugin",
|
|
79
81
|
"prepare-local-eslint-plugin": "dotenv -e .env -- sh -c 'ESLINT_PLUGIN_PATH=${LOCAL_ESLINT_PLUGIN_PATH:-../eslint-plugin}; pnpm --prefix \"$ESLINT_PLUGIN_PATH\" run build && pnpm uninstall @alextheman/eslint-plugin && pnpm install --save-dev file:\"$ESLINT_PLUGIN_PATH\"'",
|
|
80
82
|
"test": "vitest run",
|
|
81
|
-
"test-end-to-end": "RUN_END_TO_END=true vitest run tests/end-to-end --reporter verbose",
|
|
83
|
+
"test-end-to-end": "cross-env RUN_END_TO_END=true vitest run tests/end-to-end --reporter verbose",
|
|
82
84
|
"test-watch": "vitest",
|
|
83
85
|
"update-dependencies": "pnpm update --latest && pnpm update",
|
|
84
86
|
"use-live-eslint-plugin": "pnpm run prepare-live-eslint-plugin && pnpm run lint",
|