index.cjs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. 'use strict'
  2. var metadata = require('../metadata.max.json')
  3. var core = require('../core/index.cjs')
  4. function call(func, _arguments) {
  5. var args = Array.prototype.slice.call(_arguments)
  6. args.push(metadata)
  7. return func.apply(this, args)
  8. }
  9. function parsePhoneNumberFromString() {
  10. return call(core.parsePhoneNumberFromString, arguments)
  11. }
  12. // ES5 `require()` "default" "interoperability" hack.
  13. // https://github.com/babel/babel/issues/2212#issuecomment-131827986
  14. // An alternative approach:
  15. // https://www.npmjs.com/package/babel-plugin-add-module-exports
  16. exports = module.exports = parsePhoneNumberFromString
  17. exports['default'] = parsePhoneNumberFromString
  18. exports.ParseError = core.ParseError
  19. function parsePhoneNumberWithError() {
  20. return call(core.parsePhoneNumberWithError, arguments)
  21. }
  22. // `parsePhoneNumber()` named export has been renamed to `parsePhoneNumberWithError()`.
  23. exports.parsePhoneNumber = parsePhoneNumberWithError
  24. exports.parsePhoneNumberWithError = parsePhoneNumberWithError
  25. // `parsePhoneNumberFromString()` named export is now considered legacy:
  26. // it has been promoted to a default export due to being too verbose.
  27. exports.parsePhoneNumberFromString = parsePhoneNumberFromString
  28. exports.isValidPhoneNumber = function isValidPhoneNumber() {
  29. return call(core.isValidPhoneNumber, arguments)
  30. }
  31. exports.isPossiblePhoneNumber = function isPossiblePhoneNumber() {
  32. return call(core.isPossiblePhoneNumber, arguments)
  33. }
  34. exports.validatePhoneNumberLength = function validatePhoneNumberLength() {
  35. return call(core.validatePhoneNumberLength, arguments)
  36. }
  37. exports.findNumbers = function findNumbers() {
  38. return call(core.findNumbers, arguments)
  39. }
  40. exports.searchNumbers = function searchNumbers() {
  41. return call(core.searchNumbers, arguments)
  42. }
  43. exports.findPhoneNumbersInText = function findPhoneNumbersInText() {
  44. return call(core.findPhoneNumbersInText, arguments)
  45. }
  46. exports.searchPhoneNumbersInText = function searchPhoneNumbersInText() {
  47. return call(core.searchPhoneNumbersInText, arguments)
  48. }
  49. exports.PhoneNumberMatcher = function PhoneNumberMatcher(text, options) {
  50. return core.PhoneNumberMatcher.call(this, text, options, metadata)
  51. }
  52. exports.PhoneNumberMatcher.prototype = Object.create(core.PhoneNumberMatcher.prototype, {})
  53. exports.PhoneNumberMatcher.prototype.constructor = exports.PhoneNumberMatcher
  54. exports.AsYouType = function AsYouType(country) {
  55. return core.AsYouType.call(this, country, metadata)
  56. }
  57. exports.AsYouType.prototype = Object.create(core.AsYouType.prototype, {})
  58. exports.AsYouType.prototype.constructor = exports.AsYouType
  59. exports.isSupportedCountry = function isSupportedCountry(country) {
  60. return call(core.isSupportedCountry, arguments)
  61. }
  62. exports.getCountries = function getCountries() {
  63. return call(core.getCountries, arguments)
  64. }
  65. exports.getCountryCallingCode = function getCountryCallingCode() {
  66. return call(core.getCountryCallingCode, arguments)
  67. }
  68. exports.getExtPrefix = function getExtPrefix(country) {
  69. return call(core.getExtPrefix, arguments)
  70. }
  71. exports.getExampleNumber = function getExampleNumber() {
  72. return call(core.getExampleNumber, arguments)
  73. }
  74. exports.formatIncompletePhoneNumber = function formatIncompletePhoneNumber() {
  75. return call(core.formatIncompletePhoneNumber, arguments)
  76. }
  77. exports.parseIncompletePhoneNumber = core.parseIncompletePhoneNumber
  78. exports.parsePhoneNumberCharacter = core.parsePhoneNumberCharacter
  79. exports.parseDigits = core.parseDigits
  80. exports.DIGIT_PLACEHOLDER = core.DIGIT_PLACEHOLDER
  81. exports.parseRFC3966 = core.parseRFC3966
  82. exports.formatRFC3966 = core.formatRFC3966