index.cjs.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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/62
  6. // https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/61#note_950728292
  7. var min = require('./min/index.cjs')
  8. var metadata = require('./metadata.min.json')
  9. function withMetadataArgument(func, _arguments) {
  10. var args = Array.prototype.slice.call(_arguments)
  11. args.push(metadata)
  12. return func.apply(this, args)
  13. }
  14. // ES5 `require()` "default" "interoperability" hack.
  15. // https://github.com/babel/babel/issues/2212#issuecomment-131827986
  16. // An alternative approach:
  17. // https://www.npmjs.com/package/babel-plugin-add-module-exports
  18. exports = module.exports = min.parsePhoneNumberFromString
  19. exports['default'] = min.parsePhoneNumberFromString
  20. // `parsePhoneNumberFromString()` named export is now considered legacy:
  21. // it has been promoted to a default export due to being too verbose.
  22. exports.parsePhoneNumberFromString = min.parsePhoneNumberFromString
  23. exports.ParseError = min.ParseError
  24. // `parsePhoneNumber()` named export has been renamed to `parsePhoneNumberWithError()`.
  25. exports.parsePhoneNumber = min.parsePhoneNumberWithError
  26. exports.parsePhoneNumberWithError = min.parsePhoneNumberWithError
  27. exports.isValidPhoneNumber = min.isValidPhoneNumber
  28. exports.isPossiblePhoneNumber = min.isPossiblePhoneNumber
  29. exports.validatePhoneNumberLength = min.validatePhoneNumberLength
  30. // `parse()` and `parseNumber()` functions are deprecated.
  31. var parse_ = require('./build/legacy/parse.js').default
  32. exports.parse = function parse() {
  33. return withMetadataArgument(parse_, arguments)
  34. }
  35. exports.parseNumber = exports.parse
  36. // `format()` and `formatNumber()` functions are deprecated.
  37. var format_ = require('./build/legacy/format.js').default
  38. exports.format = function format() {
  39. return withMetadataArgument(format_, arguments)
  40. }
  41. exports.formatNumber = exports.format
  42. // Deprecated.
  43. var getNumberType_ = require('./build/legacy/getNumberType.js').default
  44. exports.getNumberType = function getNumberType() {
  45. return withMetadataArgument(getNumberType_, arguments)
  46. }
  47. // Deprecated.
  48. var isPossibleNumber_ = require('./build/legacy/isPossibleNumber.js').default
  49. exports.isPossibleNumber = function isPossibleNumber() {
  50. return withMetadataArgument(isPossibleNumber_, arguments)
  51. }
  52. // Deprecated.
  53. var isValidNumber_ = require('./build/legacy/isValidNumber.js').default
  54. exports.isValidNumber = function isValidNumber() {
  55. return withMetadataArgument(isValidNumber_, arguments)
  56. }
  57. // Deprecated.
  58. var isValidNumberForRegion_ = require('./build/legacy/isValidNumberForRegion.js').default
  59. exports.isValidNumberForRegion = function isValidNumberForRegion() {
  60. return withMetadataArgument(isValidNumberForRegion_, arguments)
  61. }
  62. exports.getExampleNumber = min.getExampleNumber
  63. exports.Metadata = min.Metadata
  64. // Deprecated.
  65. var findPhoneNumbers_ = require('./build/legacy/findPhoneNumbers.js').default
  66. exports.findPhoneNumbers = function findPhoneNumbers() {
  67. return withMetadataArgument(findPhoneNumbers_, arguments)
  68. }
  69. // Deprecated.
  70. var searchPhoneNumbers_ = require('./build/legacy/findPhoneNumbers.js').searchPhoneNumbers
  71. exports.searchPhoneNumbers = function searchPhoneNumbers() {
  72. return withMetadataArgument(searchPhoneNumbers_, arguments)
  73. }
  74. // Deprecated.
  75. var PhoneNumberSearch_ = require('./build/legacy/findPhoneNumbersInitialImplementation.js').PhoneNumberSearch
  76. exports.PhoneNumberSearch = function PhoneNumberSearch(text, options) {
  77. return PhoneNumberSearch_.call(this, text, options, metadata)
  78. }
  79. exports.PhoneNumberSearch.prototype = Object.create(PhoneNumberSearch_.prototype, {})
  80. exports.PhoneNumberSearch.prototype.constructor = exports.PhoneNumberSearch
  81. // Deprecated.
  82. exports.findNumbers = min.findNumbers
  83. // Deprecated.
  84. exports.searchNumbers = min.searchNumbers
  85. exports.findPhoneNumbersInText = min.findPhoneNumbersInText
  86. exports.searchPhoneNumbersInText = min.searchPhoneNumbersInText
  87. exports.PhoneNumberMatcher = min.PhoneNumberMatcher
  88. exports.AsYouType = min.AsYouType
  89. exports.getCountries = min.getCountries
  90. exports.getCountryCallingCode = min.getCountryCallingCode
  91. exports.isSupportedCountry = min.isSupportedCountry
  92. exports.getExtPrefix = min.getExtPrefix
  93. exports.parseRFC3966 = min.parseRFC3966
  94. exports.formatRFC3966 = min.formatRFC3966
  95. // Deprecated: `DIGITS` were used by `react-phone-number-input`.
  96. // Replaced by `parseDigits()`.
  97. exports.DIGITS = require('./build/helpers/parseDigits.js').DIGITS
  98. exports.DIGIT_PLACEHOLDER = min.DIGIT_PLACEHOLDER
  99. // `getPhoneCode` name is deprecated
  100. exports.getPhoneCode = min.getCountryCallingCode
  101. exports.formatIncompletePhoneNumber = min.formatIncompletePhoneNumber
  102. exports.parseIncompletePhoneNumber = min.parseIncompletePhoneNumber
  103. exports.parsePhoneNumberCharacter = min.parsePhoneNumberCharacter
  104. exports.parseDigits = min.parseDigits