@alextheman/utility 5.5.0 → 5.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -467,6 +467,17 @@ type IsTypeArgumentString<Argument extends string> = Argument;
467
467
  */
468
468
  type NonUndefined<InputType> = InputType extends undefined ? never : InputType;
469
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
470
481
  //#region src/root/types/OptionalOnCondition.d.ts
471
482
  /**
472
483
  * Resolves to the given type if the first type is `true`, otherwise resolves to `undefined`
@@ -1112,4 +1123,4 @@ declare function normaliseIndents(strings: TemplateStringsArray, ...interpolatio
1112
1123
  */
1113
1124
  declare const normalizeIndents: typeof normaliseIndents;
1114
1125
  //#endregion
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 };
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
@@ -467,6 +467,17 @@ type IsTypeArgumentString<Argument extends string> = Argument;
467
467
  */
468
468
  type NonUndefined<InputType> = InputType extends undefined ? never : InputType;
469
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
470
481
  //#region src/root/types/OptionalOnCondition.d.ts
471
482
  /**
472
483
  * Resolves to the given type if the first type is `true`, otherwise resolves to `undefined`
@@ -1112,4 +1123,4 @@ declare function normaliseIndents(strings: TemplateStringsArray, ...interpolatio
1112
1123
  */
1113
1124
  declare const normalizeIndents: typeof normaliseIndents;
1114
1125
  //#endregion
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 };
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 };
@@ -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") return null;
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
- declare function getPackageJsonContents(directory: string): Promise<Record<string, any> | null>;
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;
@@ -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
- declare function getPackageJsonContents(directory: string): Promise<Record<string, any> | null>;
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;
@@ -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") return null;
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.5.0",
3
+ "version": "5.6.1",
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.8.2",
40
- "@types/node": "^25.3.0",
41
- "alex-c-line": "^1.28.0",
39
+ "@alextheman/eslint-plugin": "^5.9.1",
40
+ "@types/node": "^25.3.3",
41
+ "alex-c-line": "^2.0.0",
42
+ "cross-env": "^10.1.0",
42
43
  "dotenv-cli": "^11.0.0",
43
- "eslint": "^10.0.1",
44
+ "eslint": "^10.0.2",
44
45
  "globals": "^17.3.0",
45
46
  "husky": "^9.1.7",
46
47
  "jsdom": "^28.1.0",
@@ -60,25 +61,26 @@
60
61
  "build": "tsdown",
61
62
  "create-feature-docs": "typedoc",
62
63
  "create-local-package": "pnpm run build && rm -f alextheman-utility-*.tgz && pnpm pack",
63
- "create-release-note": "bash -c 'git pull origin main && alex-c-line create-release-note-2 $@' --",
64
+ "create-release-note": "bash -c 'git pull origin main && alex-c-line template release-note create $@' --",
64
65
  "format": "pnpm run format-prettier && pnpm run format-eslint",
65
66
  "format-eslint": "eslint --fix --suppress-all \"package.json\" \"src/**/*.ts\" \"tests/**/*.ts\" && rm -f eslint-suppressions.json",
66
67
  "format-prettier": "pnpm run format-prettier-typescript && pnpm run format-prettier-javascript && pnpm run format-prettier-yml",
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 check --rules 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\"",
75
77
  "lint-prettier-yml": "prettier --check \"./**/*.{yml,yaml}\"",
76
78
  "lint-tsc": "tsc --noEmit",
77
- "pre-commit": "alex-c-line pre-commit-2",
79
+ "pre-commit": "alex-c-line pre-commit",
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",