0
0

index.d.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import {
  2. ValidationRuleWithoutParams,
  3. ValidationRuleWithParams,
  4. ValidationRule,
  5. ValidationArgs
  6. } from '@vuelidate/core';
  7. import { Ref } from 'vue-demi';
  8. // Rules
  9. export const alpha: ValidationRuleWithoutParams;
  10. export const alphaNum: ValidationRuleWithoutParams;
  11. export const and: <T = unknown>(
  12. ...validators: ValidationRule<T>[]
  13. ) => ValidationRuleWithoutParams;
  14. export const between: (
  15. min: number | Ref<number>,
  16. max: number | Ref<number>
  17. ) => ValidationRuleWithParams<{ min: number, max: number }>;
  18. export const decimal: ValidationRuleWithoutParams;
  19. export const email: ValidationRuleWithoutParams;
  20. export const integer: ValidationRuleWithoutParams;
  21. export const ipAddress: ValidationRuleWithoutParams;
  22. export const macAddress: (separator: string | Ref<string>) => ValidationRuleWithoutParams;
  23. export const maxLength: (
  24. max: number | Ref<number>
  25. ) => ValidationRuleWithParams<{ max: number }>;
  26. export const maxValue: (
  27. max: number | Ref<number> | string | Ref<string>
  28. ) => ValidationRuleWithParams<{ max: number }>;
  29. export const minLength: (
  30. min: number | Ref<number>
  31. ) => ValidationRuleWithParams<{ min: number }>;
  32. export const minValue: (
  33. min: number | Ref<number> | string | Ref<string>
  34. ) => ValidationRuleWithParams<{ min: number }>;
  35. export const not: <T = unknown>(validator: ValidationRule<T>) => ValidationRuleWithoutParams;
  36. export const numeric: ValidationRuleWithoutParams;
  37. export const or: <T = unknown>(
  38. ...validators: ValidationRule<T>[]
  39. ) => ValidationRuleWithoutParams;
  40. export const required: ValidationRuleWithoutParams;
  41. export const requiredIf: (prop: boolean | Ref<boolean> | string | (() => boolean | Promise<boolean>)) => ValidationRuleWithoutParams;
  42. export const requiredUnless: (prop: boolean | Ref<boolean> | string | (() => boolean | Promise<boolean>)) => ValidationRuleWithoutParams;
  43. export const sameAs: <E = unknown>(
  44. equalTo: E | Ref<E>,
  45. otherName?: string
  46. ) => ValidationRuleWithParams<{ equalTo: E, otherName: string }>;
  47. export const url: ValidationRuleWithoutParams;
  48. export const helpers: {
  49. withParams: <T = unknown>(params: object, validator: ValidationRule<T>) => ValidationRuleWithParams
  50. withMessage: <T = unknown>(message: string | ((params: MessageProps) => string), validator: ValidationRule<T>) => ValidationRuleWithParams
  51. req: Function
  52. len: Function
  53. regex: Function
  54. unwrap: Function
  55. withAsync: Function,
  56. forEach: (validators: ValidationArgs) => { $validator: ValidationRule, $message: () => string }
  57. }
  58. export function TranslationFunction(path: string, params: { model: string, property: string, [key: string]: any }): string
  59. export function messagePathFactory(params: MessageProps): string;
  60. export function messageParamsFactory(params: {
  61. model: unknown,
  62. property: string,
  63. invalid: boolean,
  64. pending: boolean,
  65. propertyPath: string,
  66. response: unknown,
  67. validator: string,
  68. [key: string]: any
  69. }): string;
  70. export interface MessageProps {
  71. $model: string;
  72. $property: string;
  73. $params: { [attr: string] : any };
  74. $validator: string;
  75. $pending: boolean;
  76. $invalid: boolean;
  77. $response: unknown;
  78. $propertyPath: string;
  79. }
  80. export type ValidatorWrapper = (...args: any[]) => ValidationRule ;
  81. declare function withI18nMessage <T extends (ValidationRule | ValidatorWrapper)>(
  82. validator: T,
  83. options?: {
  84. withArguments?: boolean,
  85. messagePath?: typeof messagePathFactory,
  86. messageParams?: typeof messageParamsFactory,
  87. }): T
  88. export function createI18nMessage({ t, messagePath, messageParams }: {
  89. t: typeof TranslationFunction;
  90. messagePath?: typeof messagePathFactory;
  91. messageParams?: typeof messageParamsFactory;
  92. }): typeof withI18nMessage