index.cjs.js 4.1 KB

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