index.d.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Code shows a string is valid,
  2. // but docs require string array or object.
  3. type TLDList = string | string[] | { [topLevelDomain: string]: any };
  4. type BaseOptions = {
  5. tldWhitelist?: TLDList;
  6. tldBlacklist?: TLDList;
  7. minDomainAtoms?: number;
  8. allowUnicode?: boolean;
  9. };
  10. type OptionsWithBool = BaseOptions & {
  11. errorLevel?: false;
  12. };
  13. type OptionsWithNumThreshold = BaseOptions & {
  14. errorLevel?: true | number;
  15. };
  16. interface Validator {
  17. /**
  18. * Check that an email address conforms to RFCs 5321, 5322, 6530 and others.
  19. *
  20. * ```
  21. * import * as IsEmail from "isemail";
  22. *
  23. * IsEmail.validate("test@e.com");
  24. * // => true
  25. * ```
  26. */
  27. validate(email: string): boolean;
  28. /**
  29. * Check that an email address conforms to RFCs 5321, 5322, 6530 and others.
  30. *
  31. * ```
  32. * import * as IsEmail from "isemail";
  33. *
  34. * IsEmail.validate("test@iana.org", { errorLevel: false });
  35. * // => true
  36. * ```
  37. */
  38. validate(email: string, options: OptionsWithBool): boolean;
  39. /**
  40. * Check that an email address conforms to RFCs 5321, 5322, 6530 and others.
  41. *
  42. * ```
  43. * import * as IsEmail from "isemail";
  44. *
  45. * IsEmail.validate("test@iana.org", { errorLevel: true });
  46. * // => 0
  47. * IsEmail.validate("test @e.com", { errorLevel: 50 });
  48. * // => 0
  49. * IsEmail.validate('test @e.com', { errorLevel: true })
  50. * // => 49
  51. * ```
  52. */
  53. validate(email: string, options: OptionsWithNumThreshold): number;
  54. }
  55. declare const IsEmail: Validator;
  56. export = IsEmail;