@alextheman/utility 4.5.1 → 4.7.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 +48 -9
- package/dist/index.d.cts +22 -7
- package/dist/index.d.ts +22 -7
- package/dist/index.js +48 -10
- package/package.json +9 -8
package/dist/index.cjs
CHANGED
|
@@ -708,6 +708,43 @@ function isOrdered(array) {
|
|
|
708
708
|
}
|
|
709
709
|
var isOrdered_default = isOrdered;
|
|
710
710
|
|
|
711
|
+
//#endregion
|
|
712
|
+
//#region src/functions/miscellaneous/stringifyDotenv.ts
|
|
713
|
+
/**
|
|
714
|
+
* Converts an object into a string in .env file format.
|
|
715
|
+
*
|
|
716
|
+
* @param contents - The object to convert. Must be a record whose values are strings.
|
|
717
|
+
* @param options - Extra options to apply.
|
|
718
|
+
*
|
|
719
|
+
* @returns A string representation of the object in .env file format.
|
|
720
|
+
*/
|
|
721
|
+
function stringifyDotenv(contents, options) {
|
|
722
|
+
const { ...contentsCopy } = contents;
|
|
723
|
+
const { quoteStyle = "double" } = options ?? {};
|
|
724
|
+
let result = "";
|
|
725
|
+
for (const key in contentsCopy) {
|
|
726
|
+
if (/[ \t\r\n]/.test(key)) throw new DataError_default({ [key]: contentsCopy[key] }, "INVALID_KEY", "Environment variables are not allowed to have whitespace.");
|
|
727
|
+
if (quoteStyle === "none") if (/[ \t\r\n]/.test(contentsCopy[key]) || contentsCopy[key].includes("#")) throw new DataError_default({ [key]: contentsCopy[key] }, "INCOMPATIBLE_QUOTE_STYLE", "Cannot use `{ quoteStyle: \"none\" }` when value has whitespace or #");
|
|
728
|
+
else {
|
|
729
|
+
result += `${key}=${contentsCopy[key]}\n`;
|
|
730
|
+
continue;
|
|
731
|
+
}
|
|
732
|
+
const rawValue = contentsCopy[key].replace(/\r?\n/g, String.raw`\n`);
|
|
733
|
+
const chosenQuoteCharacter = {
|
|
734
|
+
double: "\"",
|
|
735
|
+
single: "'"
|
|
736
|
+
}[quoteStyle];
|
|
737
|
+
const otherQuoteCharacter = {
|
|
738
|
+
double: "'",
|
|
739
|
+
single: "\""
|
|
740
|
+
}[quoteStyle];
|
|
741
|
+
const finalQuoteCharacter = /[\r\n]/.test(contentsCopy[key]) ? `"` : rawValue.includes(chosenQuoteCharacter) ? otherQuoteCharacter : chosenQuoteCharacter;
|
|
742
|
+
result += `${key}=${finalQuoteCharacter}${rawValue}${finalQuoteCharacter}\n`;
|
|
743
|
+
}
|
|
744
|
+
return result;
|
|
745
|
+
}
|
|
746
|
+
var stringifyDotenv_default = stringifyDotenv;
|
|
747
|
+
|
|
711
748
|
//#endregion
|
|
712
749
|
//#region src/functions/miscellaneous/stringListToArray.ts
|
|
713
750
|
/**
|
|
@@ -820,27 +857,28 @@ var parseBoolean_default = parseBoolean;
|
|
|
820
857
|
*
|
|
821
858
|
* @category Parsers
|
|
822
859
|
*
|
|
823
|
-
* @template
|
|
824
|
-
* @template Input - The Zod input type.
|
|
825
|
-
* @template Internals - The Zod internal types based on the output and input types.
|
|
860
|
+
* @template SchemaType - The Zod schema type.
|
|
826
861
|
* @template ErrorType - The type of error to throw on invalid data.
|
|
827
862
|
*
|
|
828
863
|
* @param schema - The Zod schema to use in parsing.
|
|
829
864
|
* @param data - The data to parse.
|
|
830
|
-
* @param
|
|
865
|
+
* @param onError - A custom error to throw on invalid data (defaults to `DataError`). May either be the error itself, or a function that returns the error or nothing. If nothing is returned, the default error is thrown instead.
|
|
831
866
|
*
|
|
832
867
|
* @throws {DataError} If the given data cannot be parsed according to the schema.
|
|
833
868
|
*
|
|
834
869
|
* @returns The parsed data from the Zod schema.
|
|
835
870
|
*/
|
|
836
|
-
function parseZodSchema(schema, data,
|
|
871
|
+
function parseZodSchema(schema, data, onError) {
|
|
837
872
|
const parsedResult = schema.safeParse(data);
|
|
838
873
|
if (!parsedResult.success) {
|
|
839
|
-
if (
|
|
840
|
-
if (
|
|
841
|
-
else if (typeof
|
|
874
|
+
if (onError) {
|
|
875
|
+
if (onError instanceof Error) throw onError;
|
|
876
|
+
else if (typeof onError === "function") {
|
|
877
|
+
const evaluatedError = onError(parsedResult.error);
|
|
878
|
+
if (evaluatedError instanceof Error) throw evaluatedError;
|
|
879
|
+
}
|
|
842
880
|
}
|
|
843
|
-
throw new DataError_default(data, parsedResult.error.issues[0]?.code
|
|
881
|
+
throw new DataError_default(data, parsedResult.error.issues[0]?.code?.toUpperCase(), parsedResult.error.issues[0]?.message);
|
|
844
882
|
}
|
|
845
883
|
return parsedResult.data;
|
|
846
884
|
}
|
|
@@ -1484,5 +1522,6 @@ exports.randomiseArray = randomiseArray_default;
|
|
|
1484
1522
|
exports.range = range_default;
|
|
1485
1523
|
exports.removeDuplicates = removeDuplicates_default;
|
|
1486
1524
|
exports.stringListToArray = stringListToArray_default;
|
|
1525
|
+
exports.stringifyDotenv = stringifyDotenv_default;
|
|
1487
1526
|
exports.truncate = truncate_default;
|
|
1488
1527
|
exports.wait = wait_default;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DotenvParseOutput } from "dotenv";
|
|
2
|
+
import { ZodError, ZodType, z } from "zod";
|
|
2
3
|
|
|
3
4
|
//#region src/constants/NAMESPACE_EXPORT_REGEX.d.ts
|
|
4
5
|
declare const NAMESPACE_EXPORT_REGEX = "export\\s+\\*\\s+from";
|
|
@@ -490,6 +491,22 @@ declare function getRandomNumber(lowerBound: number, upperBound: number): number
|
|
|
490
491
|
*/
|
|
491
492
|
declare function isOrdered(array: readonly number[]): boolean;
|
|
492
493
|
//#endregion
|
|
494
|
+
//#region src/functions/miscellaneous/stringifyDotenv.d.ts
|
|
495
|
+
type QuoteStyle = "double" | "single" | "none";
|
|
496
|
+
interface StringifyDotenvOptions {
|
|
497
|
+
/** The quote style to use for the values (defaults to `"double"`) */
|
|
498
|
+
quoteStyle: QuoteStyle;
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Converts an object into a string in .env file format.
|
|
502
|
+
*
|
|
503
|
+
* @param contents - The object to convert. Must be a record whose values are strings.
|
|
504
|
+
* @param options - Extra options to apply.
|
|
505
|
+
*
|
|
506
|
+
* @returns A string representation of the object in .env file format.
|
|
507
|
+
*/
|
|
508
|
+
declare function stringifyDotenv(contents: Record<RecordKey, string> | DotenvParseOutput, options?: StringifyDotenvOptions): string;
|
|
509
|
+
//#endregion
|
|
493
510
|
//#region src/functions/miscellaneous/stringListToArray.d.ts
|
|
494
511
|
/**
|
|
495
512
|
* Options to apply to the conversion of a string list to an array.
|
|
@@ -667,20 +684,18 @@ declare function parseVersionType(data: unknown): VersionType;
|
|
|
667
684
|
*
|
|
668
685
|
* @category Parsers
|
|
669
686
|
*
|
|
670
|
-
* @template
|
|
671
|
-
* @template Input - The Zod input type.
|
|
672
|
-
* @template Internals - The Zod internal types based on the output and input types.
|
|
687
|
+
* @template SchemaType - The Zod schema type.
|
|
673
688
|
* @template ErrorType - The type of error to throw on invalid data.
|
|
674
689
|
*
|
|
675
690
|
* @param schema - The Zod schema to use in parsing.
|
|
676
691
|
* @param data - The data to parse.
|
|
677
|
-
* @param
|
|
692
|
+
* @param onError - A custom error to throw on invalid data (defaults to `DataError`). May either be the error itself, or a function that returns the error or nothing. If nothing is returned, the default error is thrown instead.
|
|
678
693
|
*
|
|
679
694
|
* @throws {DataError} If the given data cannot be parsed according to the schema.
|
|
680
695
|
*
|
|
681
696
|
* @returns The parsed data from the Zod schema.
|
|
682
697
|
*/
|
|
683
|
-
declare function parseZodSchema<
|
|
698
|
+
declare function parseZodSchema<SchemaType extends ZodType, ErrorType extends Error>(schema: SchemaType, data: unknown, onError?: ErrorType | ((zodError: ZodError) => ErrorType | void)): z.infer<SchemaType>;
|
|
684
699
|
//#endregion
|
|
685
700
|
//#region src/functions/recursive/deepCopy.d.ts
|
|
686
701
|
/**
|
|
@@ -1036,4 +1051,4 @@ interface ParseVersionOptions {
|
|
|
1036
1051
|
*/
|
|
1037
1052
|
declare function parseVersion(input: string, options?: ParseVersionOptions): string;
|
|
1038
1053
|
//#endregion
|
|
1039
|
-
export { APIError, ArrayElement, CamelToKebabOptions, CreateEnumType, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DisallowUndefined, Env, FormDataArrayResolutionStrategy, FormDataNullableResolutionStrategy, HTTPErrorCode, IgnoreCase, IncrementVersionOptions, KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, OptionalOnCondition, ParallelTuple, ParseVersionOptions, RecordKey, StringListToArrayOptions, VERSION_NUMBER_REGEX, VersionNumber, VersionNumberToStringOptions, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, determineVersionType, encryptWithKey, fillArray, formatDateAndTime, getIndividualVersionNumbers, getInterpolations, getRandomNumber, getRecordKeys, httpErrorCodeLookup, incrementVersion, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, normaliseImportPath, normaliseIndents, normalizeImportPath, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseVersion, parseVersionType, parseZodSchema, randomiseArray, range, removeDuplicates, stringListToArray, truncate, wait };
|
|
1054
|
+
export { APIError, ArrayElement, CamelToKebabOptions, CreateEnumType, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DisallowUndefined, Env, FormDataArrayResolutionStrategy, FormDataNullableResolutionStrategy, HTTPErrorCode, IgnoreCase, IncrementVersionOptions, KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, OptionalOnCondition, ParallelTuple, ParseVersionOptions, RecordKey, StringListToArrayOptions, VERSION_NUMBER_REGEX, VersionNumber, VersionNumberToStringOptions, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, determineVersionType, encryptWithKey, fillArray, formatDateAndTime, getIndividualVersionNumbers, getInterpolations, getRandomNumber, getRecordKeys, httpErrorCodeLookup, incrementVersion, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, normaliseImportPath, normaliseIndents, normalizeImportPath, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseVersion, parseVersionType, parseZodSchema, randomiseArray, range, removeDuplicates, stringListToArray, stringifyDotenv, truncate, wait };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ZodError, ZodType,
|
|
1
|
+
import { ZodError, ZodType, z as z$1 } from "zod";
|
|
2
|
+
import { DotenvParseOutput } from "dotenv";
|
|
2
3
|
|
|
3
4
|
//#region src/constants/NAMESPACE_EXPORT_REGEX.d.ts
|
|
4
5
|
declare const NAMESPACE_EXPORT_REGEX = "export\\s+\\*\\s+from";
|
|
@@ -490,6 +491,22 @@ declare function getRandomNumber(lowerBound: number, upperBound: number): number
|
|
|
490
491
|
*/
|
|
491
492
|
declare function isOrdered(array: readonly number[]): boolean;
|
|
492
493
|
//#endregion
|
|
494
|
+
//#region src/functions/miscellaneous/stringifyDotenv.d.ts
|
|
495
|
+
type QuoteStyle = "double" | "single" | "none";
|
|
496
|
+
interface StringifyDotenvOptions {
|
|
497
|
+
/** The quote style to use for the values (defaults to `"double"`) */
|
|
498
|
+
quoteStyle: QuoteStyle;
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Converts an object into a string in .env file format.
|
|
502
|
+
*
|
|
503
|
+
* @param contents - The object to convert. Must be a record whose values are strings.
|
|
504
|
+
* @param options - Extra options to apply.
|
|
505
|
+
*
|
|
506
|
+
* @returns A string representation of the object in .env file format.
|
|
507
|
+
*/
|
|
508
|
+
declare function stringifyDotenv(contents: Record<RecordKey, string> | DotenvParseOutput, options?: StringifyDotenvOptions): string;
|
|
509
|
+
//#endregion
|
|
493
510
|
//#region src/functions/miscellaneous/stringListToArray.d.ts
|
|
494
511
|
/**
|
|
495
512
|
* Options to apply to the conversion of a string list to an array.
|
|
@@ -667,20 +684,18 @@ declare function parseVersionType(data: unknown): VersionType;
|
|
|
667
684
|
*
|
|
668
685
|
* @category Parsers
|
|
669
686
|
*
|
|
670
|
-
* @template
|
|
671
|
-
* @template Input - The Zod input type.
|
|
672
|
-
* @template Internals - The Zod internal types based on the output and input types.
|
|
687
|
+
* @template SchemaType - The Zod schema type.
|
|
673
688
|
* @template ErrorType - The type of error to throw on invalid data.
|
|
674
689
|
*
|
|
675
690
|
* @param schema - The Zod schema to use in parsing.
|
|
676
691
|
* @param data - The data to parse.
|
|
677
|
-
* @param
|
|
692
|
+
* @param onError - A custom error to throw on invalid data (defaults to `DataError`). May either be the error itself, or a function that returns the error or nothing. If nothing is returned, the default error is thrown instead.
|
|
678
693
|
*
|
|
679
694
|
* @throws {DataError} If the given data cannot be parsed according to the schema.
|
|
680
695
|
*
|
|
681
696
|
* @returns The parsed data from the Zod schema.
|
|
682
697
|
*/
|
|
683
|
-
declare function parseZodSchema<
|
|
698
|
+
declare function parseZodSchema<SchemaType extends ZodType, ErrorType extends Error>(schema: SchemaType, data: unknown, onError?: ErrorType | ((zodError: ZodError) => ErrorType | void)): z$1.infer<SchemaType>;
|
|
684
699
|
//#endregion
|
|
685
700
|
//#region src/functions/recursive/deepCopy.d.ts
|
|
686
701
|
/**
|
|
@@ -1036,4 +1051,4 @@ interface ParseVersionOptions {
|
|
|
1036
1051
|
*/
|
|
1037
1052
|
declare function parseVersion(input: string, options?: ParseVersionOptions): string;
|
|
1038
1053
|
//#endregion
|
|
1039
|
-
export { APIError, ArrayElement, CamelToKebabOptions, CreateEnumType, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DisallowUndefined, Env, FormDataArrayResolutionStrategy, FormDataNullableResolutionStrategy, HTTPErrorCode, IgnoreCase, type IncrementVersionOptions, KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, OptionalOnCondition, ParallelTuple, type ParseVersionOptions, RecordKey, StringListToArrayOptions, VERSION_NUMBER_REGEX, VersionNumber, VersionNumberToStringOptions, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, determineVersionType, encryptWithKey, fillArray, formatDateAndTime, getIndividualVersionNumbers, getInterpolations, getRandomNumber, getRecordKeys, httpErrorCodeLookup, incrementVersion, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, normaliseImportPath, normaliseIndents, normalizeImportPath, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseVersion, parseVersionType, parseZodSchema, randomiseArray, range, removeDuplicates, stringListToArray, truncate, wait };
|
|
1054
|
+
export { APIError, ArrayElement, CamelToKebabOptions, CreateEnumType, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DisallowUndefined, Env, FormDataArrayResolutionStrategy, FormDataNullableResolutionStrategy, HTTPErrorCode, IgnoreCase, type IncrementVersionOptions, KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, OptionalOnCondition, ParallelTuple, type ParseVersionOptions, RecordKey, StringListToArrayOptions, VERSION_NUMBER_REGEX, VersionNumber, VersionNumberToStringOptions, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, determineVersionType, encryptWithKey, fillArray, formatDateAndTime, getIndividualVersionNumbers, getInterpolations, getRandomNumber, getRecordKeys, httpErrorCodeLookup, incrementVersion, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, normaliseImportPath, normaliseIndents, normalizeImportPath, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseVersion, parseVersionType, parseZodSchema, randomiseArray, range, removeDuplicates, stringListToArray, stringifyDotenv, truncate, wait };
|
package/dist/index.js
CHANGED
|
@@ -678,6 +678,43 @@ function isOrdered(array) {
|
|
|
678
678
|
}
|
|
679
679
|
var isOrdered_default = isOrdered;
|
|
680
680
|
|
|
681
|
+
//#endregion
|
|
682
|
+
//#region src/functions/miscellaneous/stringifyDotenv.ts
|
|
683
|
+
/**
|
|
684
|
+
* Converts an object into a string in .env file format.
|
|
685
|
+
*
|
|
686
|
+
* @param contents - The object to convert. Must be a record whose values are strings.
|
|
687
|
+
* @param options - Extra options to apply.
|
|
688
|
+
*
|
|
689
|
+
* @returns A string representation of the object in .env file format.
|
|
690
|
+
*/
|
|
691
|
+
function stringifyDotenv(contents, options) {
|
|
692
|
+
const { ...contentsCopy } = contents;
|
|
693
|
+
const { quoteStyle = "double" } = options ?? {};
|
|
694
|
+
let result = "";
|
|
695
|
+
for (const key in contentsCopy) {
|
|
696
|
+
if (/[ \t\r\n]/.test(key)) throw new DataError_default({ [key]: contentsCopy[key] }, "INVALID_KEY", "Environment variables are not allowed to have whitespace.");
|
|
697
|
+
if (quoteStyle === "none") if (/[ \t\r\n]/.test(contentsCopy[key]) || contentsCopy[key].includes("#")) throw new DataError_default({ [key]: contentsCopy[key] }, "INCOMPATIBLE_QUOTE_STYLE", "Cannot use `{ quoteStyle: \"none\" }` when value has whitespace or #");
|
|
698
|
+
else {
|
|
699
|
+
result += `${key}=${contentsCopy[key]}\n`;
|
|
700
|
+
continue;
|
|
701
|
+
}
|
|
702
|
+
const rawValue = contentsCopy[key].replace(/\r?\n/g, String.raw`\n`);
|
|
703
|
+
const chosenQuoteCharacter = {
|
|
704
|
+
double: "\"",
|
|
705
|
+
single: "'"
|
|
706
|
+
}[quoteStyle];
|
|
707
|
+
const otherQuoteCharacter = {
|
|
708
|
+
double: "'",
|
|
709
|
+
single: "\""
|
|
710
|
+
}[quoteStyle];
|
|
711
|
+
const finalQuoteCharacter = /[\r\n]/.test(contentsCopy[key]) ? `"` : rawValue.includes(chosenQuoteCharacter) ? otherQuoteCharacter : chosenQuoteCharacter;
|
|
712
|
+
result += `${key}=${finalQuoteCharacter}${rawValue}${finalQuoteCharacter}\n`;
|
|
713
|
+
}
|
|
714
|
+
return result;
|
|
715
|
+
}
|
|
716
|
+
var stringifyDotenv_default = stringifyDotenv;
|
|
717
|
+
|
|
681
718
|
//#endregion
|
|
682
719
|
//#region src/functions/miscellaneous/stringListToArray.ts
|
|
683
720
|
/**
|
|
@@ -790,27 +827,28 @@ var parseBoolean_default = parseBoolean;
|
|
|
790
827
|
*
|
|
791
828
|
* @category Parsers
|
|
792
829
|
*
|
|
793
|
-
* @template
|
|
794
|
-
* @template Input - The Zod input type.
|
|
795
|
-
* @template Internals - The Zod internal types based on the output and input types.
|
|
830
|
+
* @template SchemaType - The Zod schema type.
|
|
796
831
|
* @template ErrorType - The type of error to throw on invalid data.
|
|
797
832
|
*
|
|
798
833
|
* @param schema - The Zod schema to use in parsing.
|
|
799
834
|
* @param data - The data to parse.
|
|
800
|
-
* @param
|
|
835
|
+
* @param onError - A custom error to throw on invalid data (defaults to `DataError`). May either be the error itself, or a function that returns the error or nothing. If nothing is returned, the default error is thrown instead.
|
|
801
836
|
*
|
|
802
837
|
* @throws {DataError} If the given data cannot be parsed according to the schema.
|
|
803
838
|
*
|
|
804
839
|
* @returns The parsed data from the Zod schema.
|
|
805
840
|
*/
|
|
806
|
-
function parseZodSchema(schema, data,
|
|
841
|
+
function parseZodSchema(schema, data, onError) {
|
|
807
842
|
const parsedResult = schema.safeParse(data);
|
|
808
843
|
if (!parsedResult.success) {
|
|
809
|
-
if (
|
|
810
|
-
if (
|
|
811
|
-
else if (typeof
|
|
844
|
+
if (onError) {
|
|
845
|
+
if (onError instanceof Error) throw onError;
|
|
846
|
+
else if (typeof onError === "function") {
|
|
847
|
+
const evaluatedError = onError(parsedResult.error);
|
|
848
|
+
if (evaluatedError instanceof Error) throw evaluatedError;
|
|
849
|
+
}
|
|
812
850
|
}
|
|
813
|
-
throw new DataError_default(data, parsedResult.error.issues[0]?.code
|
|
851
|
+
throw new DataError_default(data, parsedResult.error.issues[0]?.code?.toUpperCase(), parsedResult.error.issues[0]?.message);
|
|
814
852
|
}
|
|
815
853
|
return parsedResult.data;
|
|
816
854
|
}
|
|
@@ -1404,4 +1442,4 @@ function incrementVersion(version, incrementType, options) {
|
|
|
1404
1442
|
var incrementVersion_default = incrementVersion;
|
|
1405
1443
|
|
|
1406
1444
|
//#endregion
|
|
1407
|
-
export { APIError_default as APIError, DataError_default as DataError, Env, NAMESPACE_EXPORT_REGEX_default as NAMESPACE_EXPORT_REGEX, VERSION_NUMBER_REGEX_default as VERSION_NUMBER_REGEX, VersionNumber_default as VersionNumber, VersionType, addDaysToDate_default as addDaysToDate, appendSemicolon_default as appendSemicolon, camelToKebab_default as camelToKebab, convertFileToBase64_default as convertFileToBase64, createFormData_default as createFormData, createTemplateStringsArray_default as createTemplateStringsArray, deepCopy_default as deepCopy, deepFreeze_default as deepFreeze, determineVersionType_default as determineVersionType, encryptWithKey_default as encryptWithKey, fillArray_default as fillArray, formatDateAndTime_default as formatDateAndTime, getIndividualVersionNumbers_default as getIndividualVersionNumbers, getInterpolations_default as getInterpolations, getRandomNumber_default as getRandomNumber, getRecordKeys_default as getRecordKeys, httpErrorCodeLookup, incrementVersion_default as incrementVersion, interpolate_default as interpolate, interpolateObjects_default as interpolateObjects, isAnniversary_default as isAnniversary, isLeapYear_default as isLeapYear, isMonthlyMultiple_default as isMonthlyMultiple, isOrdered_default as isOrdered, isSameDate_default as isSameDate, kebabToCamel_default as kebabToCamel, normaliseImportPath, normaliseIndents_default as normaliseIndents, normalizeImportPath_default as normalizeImportPath, normalizeIndents, omitProperties_default as omitProperties, paralleliseArrays_default as paralleliseArrays, parseBoolean_default as parseBoolean, parseEnv_default as parseEnv, parseFormData_default as parseFormData, parseIntStrict_default as parseIntStrict, parseVersion_default as parseVersion, parseVersionType_default as parseVersionType, parseZodSchema_default as parseZodSchema, randomiseArray_default as randomiseArray, range_default as range, removeDuplicates_default as removeDuplicates, stringListToArray_default as stringListToArray, truncate_default as truncate, wait_default as wait };
|
|
1445
|
+
export { APIError_default as APIError, DataError_default as DataError, Env, NAMESPACE_EXPORT_REGEX_default as NAMESPACE_EXPORT_REGEX, VERSION_NUMBER_REGEX_default as VERSION_NUMBER_REGEX, VersionNumber_default as VersionNumber, VersionType, addDaysToDate_default as addDaysToDate, appendSemicolon_default as appendSemicolon, camelToKebab_default as camelToKebab, convertFileToBase64_default as convertFileToBase64, createFormData_default as createFormData, createTemplateStringsArray_default as createTemplateStringsArray, deepCopy_default as deepCopy, deepFreeze_default as deepFreeze, determineVersionType_default as determineVersionType, encryptWithKey_default as encryptWithKey, fillArray_default as fillArray, formatDateAndTime_default as formatDateAndTime, getIndividualVersionNumbers_default as getIndividualVersionNumbers, getInterpolations_default as getInterpolations, getRandomNumber_default as getRandomNumber, getRecordKeys_default as getRecordKeys, httpErrorCodeLookup, incrementVersion_default as incrementVersion, interpolate_default as interpolate, interpolateObjects_default as interpolateObjects, isAnniversary_default as isAnniversary, isLeapYear_default as isLeapYear, isMonthlyMultiple_default as isMonthlyMultiple, isOrdered_default as isOrdered, isSameDate_default as isSameDate, kebabToCamel_default as kebabToCamel, normaliseImportPath, normaliseIndents_default as normaliseIndents, normalizeImportPath_default as normalizeImportPath, normalizeIndents, omitProperties_default as omitProperties, paralleliseArrays_default as paralleliseArrays, parseBoolean_default as parseBoolean, parseEnv_default as parseEnv, parseFormData_default as parseFormData, parseIntStrict_default as parseIntStrict, parseVersion_default as parseVersion, parseVersionType_default as parseVersionType, parseZodSchema_default as parseZodSchema, randomiseArray_default as randomiseArray, range_default as range, removeDuplicates_default as removeDuplicates, stringListToArray_default as stringListToArray, stringifyDotenv_default as stringifyDotenv, truncate_default as truncate, wait_default as wait };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alextheman/utility",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.7.0",
|
|
4
4
|
"description": "Helpful utility functions.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,26 +16,27 @@
|
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
+
"dotenv": "^17.2.3",
|
|
19
20
|
"libsodium-wrappers": "^0.8.0",
|
|
20
21
|
"zod": "^4.3.5"
|
|
21
22
|
},
|
|
22
23
|
"devDependencies": {
|
|
23
24
|
"@alextheman/eslint-plugin": "^5.4.2",
|
|
24
25
|
"@types/libsodium-wrappers": "^0.7.14",
|
|
25
|
-
"@types/node": "^25.0.
|
|
26
|
-
"@typescript-eslint/types": "^8.
|
|
27
|
-
"alex-c-line": "^1.17.
|
|
26
|
+
"@types/node": "^25.0.9",
|
|
27
|
+
"@typescript-eslint/types": "^8.53.0",
|
|
28
|
+
"alex-c-line": "^1.17.3",
|
|
28
29
|
"dotenv-cli": "^11.0.0",
|
|
29
30
|
"eslint": "^9.39.2",
|
|
30
31
|
"globals": "^17.0.0",
|
|
31
32
|
"husky": "^9.1.7",
|
|
32
33
|
"jsdom": "^27.4.0",
|
|
33
|
-
"prettier": "^3.
|
|
34
|
-
"tsdown": "^0.
|
|
35
|
-
"typedoc": "^0.28.
|
|
34
|
+
"prettier": "^3.8.0",
|
|
35
|
+
"tsdown": "^0.19.0",
|
|
36
|
+
"typedoc": "^0.28.16",
|
|
36
37
|
"typescript": "^5.9.3",
|
|
37
38
|
"vite-tsconfig-paths": "^6.0.4",
|
|
38
|
-
"vitest": "^4.0.
|
|
39
|
+
"vitest": "^4.0.17"
|
|
39
40
|
},
|
|
40
41
|
"engines": {
|
|
41
42
|
"node": ">=22.0.0"
|