Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | 106x 106x 106x 106x 106x 106x 106x 106x 20x 106x 106x 20x | import { ValidationRule } from "react-hook-form";
export const INPUT_VALIDATION_RULES = {
max: "max",
min: "min",
maxLength: "maxLength",
minLength: "minLength",
pattern: "pattern",
required: "required",
validate: "validate",
} as const;
export type InputValidationRules = typeof INPUT_VALIDATION_RULES;
export type ERROR = Record<string, string>;
export type MaxType = InputValidationRules["max"] | InputValidationRules["maxLength"];
export type MinType = InputValidationRules["min"] | InputValidationRules["minLength"];
export const isFunction = (value: unknown): value is typeof Function => typeof value === "function";
export const isNullOrUndefined = (value: unknown): value is null | undefined => value == null;
export const isUndefined = (val: unknown): val is undefined => val === undefined;
export const isDateObject = (value: unknown): value is Date => value instanceof Date;
export const isObjectType = (value: unknown) => typeof value === "object";
export const isString = (value: unknown): value is string => typeof value === "string";
export const isObject = <T extends object>(value: unknown): value is T =>
!isNullOrUndefined(value) && !Array.isArray(value) && isObjectType(value) && !isDateObject(value);
export const isRegex = (value: unknown): value is RegExp => value instanceof RegExp;
export const getValueAndMessage = (validationData?: ValidationRule) =>
isObject(validationData) && !isRegex(validationData)
? validationData
: {
value: validationData,
message: "",
};
|