index.d.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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, metadata: MetadataJson): PhoneNumber;
  41. export function parsePhoneNumber(text: string, defaultCountry: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string, extract?: boolean }, metadata: MetadataJson): PhoneNumber;
  42. export function parsePhoneNumberWithError(text: string, metadata: MetadataJson): PhoneNumber;
  43. export function parsePhoneNumberWithError(text: string, defaultCountry: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string, extract?: boolean }, metadata: MetadataJson): PhoneNumber;
  44. // `parsePhoneNumberFromString()` named export is now considered legacy:
  45. // it has been promoted to a default export due to being too verbose.
  46. export function parsePhoneNumberFromString(text: string, metadata: MetadataJson): PhoneNumber | undefined;
  47. export function parsePhoneNumberFromString(text: string, defaultCountry: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string, extract?: boolean }, metadata: MetadataJson): PhoneNumber | undefined;
  48. export default parsePhoneNumberFromString;
  49. export function isValidPhoneNumber(text: string, metadata: MetadataJson): boolean;
  50. export function isValidPhoneNumber(text: string, defaultCountry: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string }, metadata: MetadataJson): boolean;
  51. export function isPossiblePhoneNumber(text: string, metadata: MetadataJson): boolean;
  52. export function isPossiblePhoneNumber(text: string, defaultCountry: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string }, metadata: MetadataJson): boolean;
  53. export function validatePhoneNumberLength(text: string, metadata: MetadataJson): ValidatePhoneNumberLengthResult | undefined;
  54. export function validatePhoneNumberLength(text: string, defaultCountry: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string }, metadata: MetadataJson): ValidatePhoneNumberLengthResult | undefined;
  55. export function findNumbers(text: string, metadata: MetadataJson): NumberFoundLegacy[];
  56. export function findNumbers(text: string, options: CountryCode | { defaultCountry?: CountryCode, v2: true }, metadata: MetadataJson): NumberFound[];
  57. export function searchNumbers(text: string, metadata: MetadataJson): IterableIterator<NumberFoundLegacy>;
  58. export function searchNumbers(text: string, options: CountryCode | { defaultCountry?: CountryCode, v2: true }, metadata: MetadataJson): IterableIterator<NumberFound>;
  59. export function findPhoneNumbersInText(text: string, options: CountryCode | { defaultCountry?: CountryCode, extended?: boolean }, metadata: MetadataJson): NumberFound[];
  60. export function findPhoneNumbersInText(text: string, metadata: MetadataJson): NumberFound[];
  61. export function searchPhoneNumbersInText(text: string, options: CountryCode | { defaultCountry?: CountryCode, extended?: boolean }, metadata: MetadataJson): IterableIterator<NumberFound>;
  62. export function searchPhoneNumbersInText(text: string, metadata: MetadataJson): IterableIterator<NumberFound>;
  63. export class PhoneNumberMatcher {
  64. constructor(text: string, metadata: MetadataJson);
  65. constructor(text: string, options: { defaultCountry?: CountryCode, v2: true }, metadata: MetadataJson);
  66. hasNext(): boolean;
  67. next(): NumberFound | undefined;
  68. }
  69. export function isSupportedCountry(countryCode: CountryCode, metadata: MetadataJson): boolean;
  70. export function getCountries(metadata: MetadataJson): CountryCode[];
  71. export function getCountryCallingCode(countryCode: CountryCode, metadata: MetadataJson): CountryCallingCode;
  72. export function getExtPrefix(countryCode: CountryCode, metadata: MetadataJson): string;
  73. export function getExampleNumber(country: CountryCode, examples: Examples, metadata: MetadataJson): PhoneNumber | undefined;
  74. export function formatIncompletePhoneNumber(number: string, metadata: MetadataJson): string;
  75. export function formatIncompletePhoneNumber(number: string, defaultCountryCode: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string } | undefined, metadata: MetadataJson): string;
  76. export function parseIncompletePhoneNumber(text: string): string;
  77. export function parsePhoneNumberCharacter(character: string): string;
  78. export function parseDigits(character: string): string;
  79. export class AsYouType {
  80. constructor(defaultCountryCode: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string } | undefined, metadata: MetadataJson);
  81. input(text: string): string;
  82. reset(): void;
  83. getNumber(): PhoneNumber | undefined;
  84. getNumberValue(): E164Number | undefined;
  85. getChars(): string;
  86. getTemplate(): string;
  87. getCallingCode(): string | undefined;
  88. getCountry(): CountryCode | undefined;
  89. isInternational(): boolean;
  90. isPossible(): boolean;
  91. isValid(): boolean;
  92. }
  93. export class Metadata {
  94. constructor(metadata: MetadataJson);
  95. selectNumberingPlan(country: CountryCode): void;
  96. numberingPlan?: NumberingPlan;
  97. }