index.d.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import {
  2. MetadataJson,
  3. Examples,
  4. PhoneNumber,
  5. E164Number,
  6. CountryCallingCode,
  7. CountryCode,
  8. CarrierCode,
  9. NationalNumber,
  10. Extension,
  11. ParseError,
  12. NumberFoundLegacy,
  13. NumberFound,
  14. NumberType,
  15. NumberFormat,
  16. NumberingPlan,
  17. ValidatePhoneNumberLengthResult
  18. } from '../types.d.js';
  19. // They say this re-export is required.
  20. // https://github.com/catamphetamine/libphonenumber-js/pull/290#issuecomment-453281180
  21. export {
  22. MetadataJson,
  23. Examples,
  24. PhoneNumber,
  25. E164Number,
  26. CountryCallingCode,
  27. CountryCode,
  28. CarrierCode,
  29. NationalNumber,
  30. Extension,
  31. ParseError,
  32. NumberFoundLegacy,
  33. NumberFound,
  34. NumberType,
  35. NumberFormat,
  36. NumberingPlan,
  37. ValidatePhoneNumberLengthResult
  38. };
  39. // `parsePhoneNumber()` named export has been renamed to `parsePhoneNumberWithError()`.
  40. export function parsePhoneNumber(text: string, defaultCountry?: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string, extract?: boolean }): PhoneNumber;
  41. export function parsePhoneNumberWithError(text: string, defaultCountry?: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string, extract?: boolean }): PhoneNumber;
  42. // `parsePhoneNumberFromString()` named export is now considered legacy:
  43. // it has been promoted to a default export due to being too verbose.
  44. export function parsePhoneNumberFromString(text: string, defaultCountry?: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string, extract?: boolean }): PhoneNumber | undefined;
  45. export default parsePhoneNumberFromString;
  46. export function isValidPhoneNumber(text: string, defaultCountry?: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string }): boolean;
  47. export function isPossiblePhoneNumber(text: string, defaultCountry?: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string }): boolean;
  48. export function validatePhoneNumberLength(text: string, defaultCountry?: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string }): ValidatePhoneNumberLengthResult | undefined;
  49. export function findNumbers(text: string, options?: CountryCode): NumberFoundLegacy[];
  50. export function searchNumbers(text: string, options?: CountryCode): IterableIterator<NumberFoundLegacy>;
  51. export function findNumbers(text: string, options?: { defaultCountry?: CountryCode, v2: true }): NumberFound[];
  52. export function searchNumbers(text: string, options?: { defaultCountry?: CountryCode, v2: true }): IterableIterator<NumberFound>;
  53. export function findPhoneNumbersInText(text: string, options?: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string, extended?: boolean }): NumberFound[];
  54. export function searchPhoneNumbersInText(text: string, options?: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string, extended?: boolean }): IterableIterator<NumberFound>;
  55. export class PhoneNumberMatcher {
  56. constructor(text: string, options?: { defaultCountry?: CountryCode, v2: true });
  57. hasNext(): boolean;
  58. next(): NumberFound | undefined;
  59. }
  60. export function isSupportedCountry(countryCode: string): countryCode is CountryCode;
  61. export function getCountries(): CountryCode[];
  62. export function getCountryCallingCode(countryCode: CountryCode): CountryCallingCode;
  63. export function getExtPrefix(countryCode: CountryCode): string;
  64. export function getExampleNumber(country: CountryCode, examples: Examples): PhoneNumber | undefined;
  65. export function formatIncompletePhoneNumber(number: string, defaultCountryCode?: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string }): string;
  66. export function parseIncompletePhoneNumber(text: string): string;
  67. export function parsePhoneNumberCharacter(character: string): string;
  68. export function parseDigits(character: string): string;
  69. export class AsYouType {
  70. constructor(defaultCountryCode?: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string });
  71. input(text: string): string;
  72. reset(): void;
  73. getNumber(): PhoneNumber | undefined;
  74. getNumberValue(): E164Number | undefined;
  75. getChars(): string;
  76. getTemplate(): string;
  77. getCallingCode(): string | undefined;
  78. getCountry(): CountryCode | undefined;
  79. isInternational(): boolean;
  80. isPossible(): boolean;
  81. isValid(): boolean;
  82. }
  83. export class Metadata {
  84. constructor();
  85. selectNumberingPlan(country: CountryCode): void;
  86. numberingPlan?: NumberingPlan;
  87. }