custom.d.ts 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. // `/custom` export is deprecated.
  2. // Use `/core` sub-package instead.
  3. import {
  4. MetadataJson,
  5. Examples,
  6. PhoneNumber,
  7. E164Number,
  8. CountryCallingCode,
  9. CountryCode,
  10. CarrierCode,
  11. NationalNumber,
  12. Extension,
  13. ParseError,
  14. NumberFoundLegacy,
  15. NumberFound,
  16. NumberType,
  17. NumberFormat,
  18. NumberingPlan
  19. } from './types.d.js';
  20. import {
  21. ParsedNumber,
  22. FormatNumberOptions,
  23. ParseNumberOptions
  24. } from './index.d.js';
  25. export {
  26. MetadataJson,
  27. Examples,
  28. PhoneNumber,
  29. E164Number,
  30. CountryCallingCode,
  31. CountryCode,
  32. CarrierCode,
  33. NationalNumber,
  34. Extension,
  35. FormatNumberOptions,
  36. ParsedNumber,
  37. ParseNumberOptions,
  38. ParseError,
  39. NumberFoundLegacy,
  40. NumberFound,
  41. NumberFormat,
  42. NumberType,
  43. NumberingPlan
  44. };
  45. // `parsePhoneNumber()` named export has been renamed to `parsePhoneNumberWithError()`.
  46. export function parsePhoneNumber(text: string, metadata: MetadataJson): PhoneNumber;
  47. export function parsePhoneNumber(text: string, defaultCountry: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string, extract?: boolean }, metadata: MetadataJson): PhoneNumber;
  48. export function parsePhoneNumberWithError(text: string, metadata: MetadataJson): PhoneNumber;
  49. export function parsePhoneNumberWithError(text: string, defaultCountry: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string, extract?: boolean }, metadata: MetadataJson): PhoneNumber;
  50. // `parsePhoneNumberFromString()` named export is now considered legacy:
  51. // it has been promoted to a default export due to being too verbose.
  52. export function parsePhoneNumberFromString(text: string, metadata: MetadataJson): PhoneNumber;
  53. export function parsePhoneNumberFromString(text: string, defaultCountry: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string, extract?: boolean }, metadata: MetadataJson): PhoneNumber;
  54. export default parsePhoneNumberFromString;
  55. export function parse(text: string, metadata: MetadataJson): ParsedNumber;
  56. export function parse(text: string, options: CountryCode | ParseNumberOptions, metadata: MetadataJson): ParsedNumber;
  57. export function parseNumber(text: string, metadata: MetadataJson): ParsedNumber | {};
  58. export function parseNumber(text: string, options: CountryCode | ParseNumberOptions, metadata: MetadataJson): ParsedNumber | {};
  59. // `format()` and `formatCustom` are deprecated.
  60. // Use `formatNumber()` and `formatNumberCustom()` instead.
  61. export function format(parsedNumber: ParsedNumber, format: NumberFormat, metadata: MetadataJson): string;
  62. export function format(phone: NationalNumber, format: NumberFormat, metadata: MetadataJson): string;
  63. export function format(phone: NationalNumber, country: CountryCode, format: NumberFormat, metadata: MetadataJson): string;
  64. export function formatNumber(parsedNumber: ParsedNumber, format: NumberFormat, metadata: MetadataJson): string;
  65. export function formatNumber(parsedNumber: ParsedNumber, format: NumberFormat, options: FormatNumberOptions, metadata: MetadataJson): string;
  66. export function formatNumber(phone: NationalNumber, format: NumberFormat, metadata: MetadataJson): string;
  67. export function formatNumber(phone: NationalNumber, format: NumberFormat, options: FormatNumberOptions, metadata: MetadataJson): string;
  68. export function formatNumber(phone: NationalNumber, country: CountryCode, format: NumberFormat, metadata: MetadataJson): string;
  69. export function formatNumber(phone: NationalNumber, country: CountryCode, format: NumberFormat, options: FormatNumberOptions, metadata: MetadataJson): string;
  70. export function getNumberType(parsedNumber: ParsedNumber, metadata: MetadataJson): NumberType;
  71. export function getNumberType(phone: NationalNumber, metadata: MetadataJson): NumberType;
  72. export function getNumberType(phone: NationalNumber, country: CountryCode, metadata: MetadataJson): NumberType;
  73. export function getExampleNumber(country: CountryCode, examples: Examples, metadata: MetadataJson): PhoneNumber | undefined;
  74. export function isPossibleNumber(parsedNumber: ParsedNumber, metadata: MetadataJson): boolean;
  75. export function isPossibleNumber(phone: NationalNumber, metadata: MetadataJson): boolean;
  76. export function isPossibleNumber(phone: NationalNumber, country: CountryCode, metadata: MetadataJson): boolean;
  77. export function isValidNumber(parsedNumber: ParsedNumber, metadata: MetadataJson): boolean;
  78. export function isValidNumber(phone: NationalNumber, metadata: MetadataJson): boolean;
  79. export function isValidNumber(phone: NationalNumber, country: CountryCode, metadata: MetadataJson): boolean;
  80. export function isValidNumberForRegion(phone: NationalNumber, country: CountryCode, metadata: MetadataJson): boolean;
  81. // Deprecated.
  82. export function findParsedNumbers(text: string, metadata: MetadataJson): NumberFoundLegacy[];
  83. export function findParsedNumbers(text: string, options: CountryCode | { defaultCountry?: CountryCode }, metadata: MetadataJson): NumberFoundLegacy[];
  84. // Deprecated.
  85. export function searchParsedNumbers(text: string, metadata: MetadataJson): IterableIterator<NumberFoundLegacy>;
  86. export function searchParsedNumbers(text: string, options: CountryCode | { defaultCountry?: CountryCode }, metadata: MetadataJson): IterableIterator<NumberFoundLegacy>;
  87. // Deprecated.
  88. export class ParsedNumberSearch {
  89. constructor(text: string, metadata: MetadataJson);
  90. constructor(text: string, options: { defaultCountry?: CountryCode }, metadata: MetadataJson);
  91. hasNext(): boolean;
  92. next(): NumberFoundLegacy | undefined;
  93. }
  94. export function findNumbers(text: string, metadata: MetadataJson): NumberFoundLegacy[];
  95. export function findNumbers(text: string, options: CountryCode | { defaultCountry?: CountryCode, v2: true }, metadata: MetadataJson): NumberFound[];
  96. export function searchNumbers(text: string, metadata: MetadataJson): IterableIterator<NumberFoundLegacy>;
  97. export function searchNumbers(text: string, options: CountryCode | { defaultCountry?: CountryCode, v2: true }, metadata: MetadataJson): IterableIterator<NumberFound>;
  98. export function findPhoneNumbersInText(text: string, metadata: MetadataJson): NumberFound[];
  99. export function findPhoneNumbersInText(text: string, options: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string, extended?: boolean }, metadata: MetadataJson): NumberFound[];
  100. export function searchPhoneNumbersInText(text: string, metadata: MetadataJson): IterableIterator<NumberFound>;
  101. export function searchPhoneNumbersInText(text: string, options: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string, extended?: boolean }, metadata: MetadataJson): IterableIterator<NumberFound>;
  102. export class PhoneNumberMatcher {
  103. constructor(text: string, metadata: MetadataJson);
  104. constructor(text: string, options: { defaultCountry?: CountryCode, v2: true }, metadata: MetadataJson);
  105. hasNext(): boolean;
  106. next(): NumberFound | undefined;
  107. }
  108. export function getCountries(metadata: MetadataJson): CountryCode[];
  109. export function getCountryCallingCode(countryCode: CountryCode, metadata: MetadataJson): CountryCallingCode;
  110. // Deprecated
  111. export function getPhoneCode(countryCode: CountryCode, metadata: MetadataJson): CountryCallingCode;
  112. export function getExtPrefix(countryCode: CountryCode, metadata: MetadataJson): string;
  113. export function isSupportedCountry(countryCode: CountryCode, metadata: MetadataJson): boolean;
  114. export function formatIncompletePhoneNumber(number: string, metadata: MetadataJson): string;
  115. export function formatIncompletePhoneNumber(number: string, defaultCountryCode: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string } | undefined, metadata: MetadataJson): string;
  116. export function parseIncompletePhoneNumber(text: string): string;
  117. export function parsePhoneNumberCharacter(character: string): string;
  118. export function parseDigits(character: string): string;
  119. export class AsYouType {
  120. constructor(defaultCountryCode: CountryCode | { defaultCountry?: CountryCode, defaultCallingCode?: string } | undefined, metadata: MetadataJson);
  121. input(text: string): string;
  122. reset(): void;
  123. country: CountryCode | undefined;
  124. getNumber(): PhoneNumber | undefined;
  125. getNumberValue(): E164Number | undefined;
  126. getNationalNumber(): string;
  127. getChars(): string;
  128. getTemplate(): string;
  129. getCallingCode(): string | undefined;
  130. getCountry(): CountryCode | undefined;
  131. isInternational(): boolean;
  132. isPossible(): boolean;
  133. isValid(): boolean;
  134. }
  135. export class Metadata {
  136. constructor(metadata: MetadataJson);
  137. selectNumberingPlan(country: CountryCode): void;
  138. numberingPlan?: NumberingPlan;
  139. }