@punks/backend-entity-manager 0.0.411 → 0.0.413
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.
|
@@ -5,6 +5,7 @@ export declare const fieldTextValidator: <TSheetItem>(item: TSheetItem, selector
|
|
|
5
5
|
minLength?: number;
|
|
6
6
|
maxLength?: number;
|
|
7
7
|
regex?: RegExp;
|
|
8
|
+
regexErrorCode?: string;
|
|
8
9
|
}) => EntryValidationResult;
|
|
9
10
|
export declare const fieldEmailValidator: <TSheetItem>(item: TSheetItem, selector: (item: TSheetItem) => any, params: {
|
|
10
11
|
required?: boolean;
|
package/dist/esm/index.js
CHANGED
|
@@ -40975,9 +40975,11 @@ const fieldTextValidator = (item, selector, params) => {
|
|
|
40975
40975
|
const length = typeof value === "string" ? value.length : 0;
|
|
40976
40976
|
const isMinLengthValid = length >= (params.minLength ?? 0);
|
|
40977
40977
|
const isMaxLengthValid = length <= (params.maxLength ?? Infinity);
|
|
40978
|
-
const isRegexValid = (
|
|
40978
|
+
const isRegexValid = ((!params.required && !value) ||
|
|
40979
|
+
(typeof value === "string" && params.regex?.test(value))) ??
|
|
40980
|
+
true;
|
|
40979
40981
|
return {
|
|
40980
|
-
isValid: isMinLengthValid && isMaxLengthValid && isRegexValid,
|
|
40982
|
+
isValid: isMinLengthValid && isMaxLengthValid && isRegexValid && isRequiredValid,
|
|
40981
40983
|
validationErrors: [
|
|
40982
40984
|
...(isRequiredValid ? [] : [{ errorCode: "required" }]),
|
|
40983
40985
|
...(isMinLengthValid
|
|
@@ -40996,7 +40998,9 @@ const fieldTextValidator = (item, selector, params) => {
|
|
|
40996
40998
|
payload: { current: length, expected: params.maxLength },
|
|
40997
40999
|
},
|
|
40998
41000
|
]),
|
|
40999
|
-
...(isRegexValid
|
|
41001
|
+
...(isRegexValid
|
|
41002
|
+
? []
|
|
41003
|
+
: [{ errorCode: params.regexErrorCode ?? "regex" }]),
|
|
41000
41004
|
],
|
|
41001
41005
|
};
|
|
41002
41006
|
};
|
|
@@ -41004,6 +41008,7 @@ const fieldEmailValidator = (item, selector, params) => {
|
|
|
41004
41008
|
return fieldTextValidator(item, selector, {
|
|
41005
41009
|
...params,
|
|
41006
41010
|
regex: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,
|
|
41011
|
+
regexErrorCode: "email",
|
|
41007
41012
|
});
|
|
41008
41013
|
};
|
|
41009
41014
|
const fieldOptionValidator = (item, selector, { availableOptions, required, }) => {
|