ingeniuscliq-core 0.5.38 → 0.5.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/components/common/form/FormPhone.d.ts.map +1 -1
  2. package/dist/components/common/form/FormPhone.js +11 -20
  3. package/dist/node_modules/libphonenumber-js/es6/metadata.js +1 -6
  4. package/package.json +1 -1
  5. package/dist/node_modules/libphonenumber-js/es6/ParseError.js +0 -34
  6. package/dist/node_modules/libphonenumber-js/es6/PhoneNumber.js +0 -194
  7. package/dist/node_modules/libphonenumber-js/es6/constants.js +0 -32
  8. package/dist/node_modules/libphonenumber-js/es6/format.js +0 -208
  9. package/dist/node_modules/libphonenumber-js/es6/helpers/RFC3966.js +0 -17
  10. package/dist/node_modules/libphonenumber-js/es6/helpers/applyInternationalSeparatorStyle.js +0 -37
  11. package/dist/node_modules/libphonenumber-js/es6/helpers/checkNumberLength.js +0 -82
  12. package/dist/node_modules/libphonenumber-js/es6/helpers/extension/createExtensionPattern.js +0 -96
  13. package/dist/node_modules/libphonenumber-js/es6/helpers/extension/extractExtension.js +0 -31
  14. package/dist/node_modules/libphonenumber-js/es6/helpers/extractCountryCallingCode.js +0 -142
  15. package/dist/node_modules/libphonenumber-js/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +0 -47
  16. package/dist/node_modules/libphonenumber-js/es6/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js +0 -66
  17. package/dist/node_modules/libphonenumber-js/es6/helpers/extractNationalNumber.js +0 -117
  18. package/dist/node_modules/libphonenumber-js/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +0 -103
  19. package/dist/node_modules/libphonenumber-js/es6/helpers/extractPhoneContext.js +0 -82
  20. package/dist/node_modules/libphonenumber-js/es6/helpers/formatNationalNumberUsingFormat.js +0 -32
  21. package/dist/node_modules/libphonenumber-js/es6/helpers/getCountryByCallingCode.js +0 -23
  22. package/dist/node_modules/libphonenumber-js/es6/helpers/getCountryByNationalNumber.js +0 -81
  23. package/dist/node_modules/libphonenumber-js/es6/helpers/getIddPrefix.js +0 -27
  24. package/dist/node_modules/libphonenumber-js/es6/helpers/getNumberType.js +0 -86
  25. package/dist/node_modules/libphonenumber-js/es6/helpers/getPossibleCountriesForNumber.js +0 -29
  26. package/dist/node_modules/libphonenumber-js/es6/helpers/isViablePhoneNumber.js +0 -78
  27. package/dist/node_modules/libphonenumber-js/es6/helpers/matchesEntirely.js +0 -13
  28. package/dist/node_modules/libphonenumber-js/es6/helpers/parseDigits.js +0 -82
  29. package/dist/node_modules/libphonenumber-js/es6/helpers/stripIddPrefix.js +0 -31
  30. package/dist/node_modules/libphonenumber-js/es6/isPossible.js +0 -78
  31. package/dist/node_modules/libphonenumber-js/es6/isValid.js +0 -58
  32. package/dist/node_modules/libphonenumber-js/es6/isValidPhoneNumber.js +0 -22
  33. package/dist/node_modules/libphonenumber-js/es6/normalizeArguments.js +0 -70
  34. package/dist/node_modules/libphonenumber-js/es6/parse.js +0 -326
  35. package/dist/node_modules/libphonenumber-js/es6/parseIncompletePhoneNumber.js +0 -62
  36. package/dist/node_modules/libphonenumber-js/es6/parsePhoneNumberWithError_.js +0 -15
  37. package/dist/node_modules/libphonenumber-js/es6/parsePhoneNumber_.js +0 -29
  38. package/dist/node_modules/libphonenumber-js/min/exports/isValidPhoneNumber.js +0 -8
@@ -1 +1 @@
1
- {"version":3,"file":"FormPhone.d.ts","sourceRoot":"","sources":["../../../../src/components/common/form/FormPhone.tsx"],"names":[],"mappings":"AACA,OAAO,EAAS,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,MAAM,EAAyD,MAAM,wBAAwB,CAAC;AAEvG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEtD,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAW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BAAkB,CAAC,EAAE,OAAO,CAAC;IACtC,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC;IACtC,QAAQ,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC;IACvC,QAAQ,CAAC,oBAAoB,CAAC,EAAE,MAAM,CAAC;IACvC,QAAQ,CAAC,oBAAoB,CAAC,EAAE,MAAM,CAAC;IACvC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IACrC,QAAQ,CAAC,WAAW,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,OAAO,MAAM,CAAC,CAAC;CAC5D;AAED,wBAAgB,SAAS,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EAAE,EAC7D,OAAO,EACP,IAAI,EACJ,KAAiB,EACjB,WAAuB,EACvB,WAAgB,EAChB,SAAc,EACd,UAAe,EACf,WAAmB,EACnB,aAAqB,EACrB,aAAqB,EACrB,QAAgB,EAChB,kBAA0B,EAC1B,QAAQ,EACR,KAAK,EACL,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,WAAgB,EACjB,EAAE,cAAc,CAAC,CAAC,CAAC,+BAsJnB"}
@@ -3,14 +3,13 @@ import { CustomFormField } from './CustomFormField.js';
3
3
  import { Input } from '../../ui/input.js';
4
4
  import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from '../../ui/select.js';
5
5
  import { useLanguage } from '../../../hooks/useLanguage.js';
6
- import { useMemo, useState, useEffect, useCallback } from 'react';
6
+ import { useMemo, useEffect, useCallback } from 'react';
7
7
  import { cn } from '../../../lib/utils.js';
8
8
  import countries from '../../../_virtual/index.js';
9
9
  import enLocale from '../../../node_modules/i18n-iso-countries/langs/en.json.js';
10
10
  import esLocale from '../../../node_modules/i18n-iso-countries/langs/es.json.js';
11
11
  import { getCountries } from '../../../node_modules/libphonenumber-js/min/exports/getCountries.js';
12
12
  import { getCountryCallingCode } from '../../../node_modules/libphonenumber-js/min/exports/getCountryCallingCode.js';
13
- import { isValidPhoneNumber } from '../../../node_modules/libphonenumber-js/min/exports/isValidPhoneNumber.js';
14
13
 
15
14
  countries.registerLocale(enLocale);
16
15
  countries.registerLocale(esLocale);
@@ -58,7 +57,6 @@ function FormPhone({
58
57
  const countryCodeField = countryCodeFieldName || "country_code";
59
58
  const phoneNumberField = phoneNumberFieldName || "phone_number";
60
59
  const selectedCountryField = "selected_country_iso";
61
- const [isValidNumber, setIsValidNumber] = useState(true);
62
60
  useEffect(() => {
63
61
  if (initialCountryCode && !watch(countryCodeField) && !watch(name)) {
64
62
  const country = countryCodes.find((c) => c.countryCode === initialCountryCode);
@@ -68,13 +66,6 @@ function FormPhone({
68
66
  }
69
67
  }
70
68
  }, [initialCountryCode, countryCodes]);
71
- useEffect(() => {
72
- const countryCode = watch(countryCodeField);
73
- const phoneNumber = watch(phoneNumberField);
74
- if (countryCode && phoneNumber) {
75
- setValue(name, `${countryCode}${phoneNumber}`);
76
- }
77
- }, [watch(countryCodeField), watch(phoneNumberField), setValue, name, countryCodeField, phoneNumberField]);
78
69
  useEffect(() => {
79
70
  const fullPhone = watch(name);
80
71
  if (fullPhone && typeof fullPhone === "string" && !watch(countryCodeField)) {
@@ -121,6 +112,11 @@ function FormPhone({
121
112
  const [isoCode, callingCode] = value.split("|");
122
113
  setValue(countryCodeField, callingCode);
123
114
  setValue(selectedCountryField, isoCode);
115
+ const phoneNumber = watch(phoneNumberField);
116
+ if (phoneNumber) {
117
+ const fullNumber = `${callingCode}${phoneNumber}`;
118
+ field.onChange(fullNumber);
119
+ }
124
120
  },
125
121
  value: (
126
122
  // Usar el código ISO guardado para encontrar el país exacto seleccionado
@@ -151,19 +147,14 @@ function FormPhone({
151
147
  const phoneNumber = e.target.value.replace(/[^\d]/g, "");
152
148
  setValue(phoneNumberField, phoneNumber);
153
149
  const countryCode = watch(countryCodeField);
154
- if (countryCode && phoneNumber) {
155
- const fullNumber = `${countryCode}${phoneNumber}`;
156
- try {
157
- const valid = isValidPhoneNumber(fullNumber);
158
- if (valid) {
159
- field.onChange(fullNumber);
160
- }
161
- } catch (error) {
162
- field.onChange(fullNumber);
163
- }
150
+ if (countryCode) {
151
+ const fullNumber = phoneNumber ? `${countryCode}${phoneNumber}` : "";
152
+ field.onChange(fullNumber);
164
153
  }
165
154
  },
166
155
  onBlur: field.onBlur,
156
+ name: field.name,
157
+ ref: field.ref,
167
158
  className: cn("flex-1", inputProps?.className)
168
159
  }
169
160
  )
@@ -574,11 +574,6 @@ function getCountryCallingCode(country, metadata) {
574
574
  }
575
575
  throw new Error("Unknown country: ".concat(country));
576
576
  }
577
- function isSupportedCountry(country, metadata) {
578
- // metadata = new Metadata(metadata)
579
- // return metadata.hasCountry(country)
580
- return metadata.countries.hasOwnProperty(country);
581
- }
582
577
  function setVersion(metadata) {
583
578
  var version = metadata.version;
584
579
  if (typeof version === 'number') {
@@ -604,4 +599,4 @@ function setVersion(metadata) {
604
599
  // return ISO_COUNTRY_CODE.test(countryCodeOrCountryCallingCode)
605
600
  // }
606
601
 
607
- export { Metadata as default, getCountryCallingCode, isSupportedCountry, validateMetadata };
602
+ export { Metadata as default, getCountryCallingCode, validateMetadata };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ingeniuscliq-core",
3
- "version": "0.5.38",
3
+ "version": "0.5.40",
4
4
  "description": "IngeniusCliq Core UI y lógica compartida",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,34 +0,0 @@
1
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- function _createClass(e, r, t) { return Object.defineProperty(e, "prototype", { writable: false }), e; }
3
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
4
- function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
5
- function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
6
- function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
7
- function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: true, configurable: true } }), Object.defineProperty(t, "prototype", { writable: false }), e && _setPrototypeOf(t, e); }
8
- function _wrapNativeSuper(t) { var r = "function" == typeof Map ? new Map() : void 0; return _wrapNativeSuper = function _wrapNativeSuper(t) { if (null === t || !_isNativeFunction(t)) return t; if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function"); if (void 0 !== r) { if (r.has(t)) return r.get(t); r.set(t, Wrapper); } function Wrapper() { return _construct(t, arguments, _getPrototypeOf(this).constructor); } return Wrapper.prototype = Object.create(t.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }), _setPrototypeOf(Wrapper, t); }, _wrapNativeSuper(t); }
9
- function _construct(t, e, r) { if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments); var o = [null]; o.push.apply(o, e); var p = new (t.bind.apply(t, o))(); return r && _setPrototypeOf(p, r.prototype), p; }
10
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
11
- function _isNativeFunction(t) { try { return -1 !== Function.toString.call(t).indexOf("[native code]"); } catch (n) { return "function" == typeof t; } }
12
- function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
13
- function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
14
- // https://stackoverflow.com/a/46971044/970769
15
- // "Breaking changes in Typescript 2.1"
16
- // "Extending built-ins like Error, Array, and Map may no longer work."
17
- // "As a recommendation, you can manually adjust the prototype immediately after any super(...) calls."
18
- // https://github.com/Microsoft/TypeScript-wiki/blob/main/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
19
- var ParseError = /*#__PURE__*/function (_Error) {
20
- function ParseError(code) {
21
- var _this;
22
- _classCallCheck(this, ParseError);
23
- _this = _callSuper(this, ParseError, [code]);
24
- // Set the prototype explicitly.
25
- // Any subclass of FooError will have to manually set the prototype as well.
26
- Object.setPrototypeOf(_this, ParseError.prototype);
27
- _this.name = _this.constructor.name;
28
- return _this;
29
- }
30
- _inherits(ParseError, _Error);
31
- return _createClass(ParseError);
32
- }(/*#__PURE__*/_wrapNativeSuper(Error));
33
-
34
- export { ParseError as default };
@@ -1,194 +0,0 @@
1
- import Metadata, { validateMetadata } from './metadata.js';
2
- import isPossiblePhoneNumber from './isPossible.js';
3
- import isValidNumber from './isValid.js';
4
- import getNumberType from './helpers/getNumberType.js';
5
- import getPossibleCountriesForNumber from './helpers/getPossibleCountriesForNumber.js';
6
- import extractCountryCallingCode from './helpers/extractCountryCallingCode.js';
7
- import isObject from './helpers/isObject.js';
8
- import formatNumber from './format.js';
9
-
10
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
11
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
12
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
13
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e; }
14
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
15
- function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || false, o.configurable = true, "value" in o && (o.writable = true), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
16
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), Object.defineProperty(e, "prototype", { writable: false }), e; }
17
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
18
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return (String )(t); }
19
- var PhoneNumber = /*#__PURE__*/function () {
20
- /**
21
- * @param {string} countryOrCountryCallingCode
22
- * @param {string} nationalNumber
23
- * @param {object} metadata — Metadata JSON
24
- * @return {PhoneNumber}
25
- */
26
- function PhoneNumber(countryOrCountryCallingCode, nationalNumber, metadata) {
27
- _classCallCheck(this, PhoneNumber);
28
- // Validate `countryOrCountryCallingCode` argument.
29
- if (!countryOrCountryCallingCode) {
30
- throw new TypeError('First argument is required');
31
- }
32
- if (typeof countryOrCountryCallingCode !== 'string') {
33
- throw new TypeError('First argument must be a string');
34
- }
35
-
36
- // In case of public API use: `constructor(number, metadata)`.
37
- // Transform the arguments from `constructor(number, metadata)` to
38
- // `constructor(countryOrCountryCallingCode, nationalNumber, metadata)`.
39
- if (countryOrCountryCallingCode[0] === '+' && !nationalNumber) {
40
- throw new TypeError('`metadata` argument not passed');
41
- }
42
- if (isObject(nationalNumber) && isObject(nationalNumber.countries)) {
43
- metadata = nationalNumber;
44
- var e164Number = countryOrCountryCallingCode;
45
- if (!E164_NUMBER_REGEXP.test(e164Number)) {
46
- throw new Error('Invalid `number` argument passed: must consist of a "+" followed by digits');
47
- }
48
- var _extractCountryCallin = extractCountryCallingCode(e164Number, undefined, undefined, undefined, metadata),
49
- _countryCallingCode = _extractCountryCallin.countryCallingCode,
50
- number = _extractCountryCallin.number;
51
- nationalNumber = number;
52
- countryOrCountryCallingCode = _countryCallingCode;
53
- if (!nationalNumber) {
54
- throw new Error('Invalid `number` argument passed: too short');
55
- }
56
- }
57
-
58
- // Validate `nationalNumber` argument.
59
- if (!nationalNumber) {
60
- throw new TypeError('`nationalNumber` argument is required');
61
- }
62
- if (typeof nationalNumber !== 'string') {
63
- throw new TypeError('`nationalNumber` argument must be a string');
64
- }
65
-
66
- // Validate `metadata` argument.
67
- validateMetadata(metadata);
68
-
69
- // Initialize properties.
70
- var _getCountryAndCountry = getCountryAndCountryCallingCode(countryOrCountryCallingCode, metadata),
71
- country = _getCountryAndCountry.country,
72
- countryCallingCode = _getCountryAndCountry.countryCallingCode;
73
- this.country = country;
74
- this.countryCallingCode = countryCallingCode;
75
- this.nationalNumber = nationalNumber;
76
- this.number = '+' + this.countryCallingCode + this.nationalNumber;
77
- // Exclude `metadata` property output from `PhoneNumber.toString()`
78
- // so that it doesn't clutter the console output of Node.js.
79
- // Previously, when Node.js did `console.log(new PhoneNumber(...))`,
80
- // it would output the whole internal structure of the `metadata` object.
81
- this.getMetadata = function () {
82
- return metadata;
83
- };
84
- }
85
- return _createClass(PhoneNumber, [{
86
- key: "setExt",
87
- value: function setExt(ext) {
88
- this.ext = ext;
89
- }
90
- }, {
91
- key: "getPossibleCountries",
92
- value: function getPossibleCountries() {
93
- if (this.country) {
94
- return [this.country];
95
- }
96
- return getPossibleCountriesForNumber(this.countryCallingCode, this.nationalNumber, this.getMetadata());
97
- }
98
- }, {
99
- key: "isPossible",
100
- value: function isPossible() {
101
- return isPossiblePhoneNumber(this, {
102
- v2: true
103
- }, this.getMetadata());
104
- }
105
- }, {
106
- key: "isValid",
107
- value: function isValid() {
108
- return isValidNumber(this, {
109
- v2: true
110
- }, this.getMetadata());
111
- }
112
- }, {
113
- key: "isNonGeographic",
114
- value: function isNonGeographic() {
115
- var metadata = new Metadata(this.getMetadata());
116
- return metadata.isNonGeographicCallingCode(this.countryCallingCode);
117
- }
118
- }, {
119
- key: "isEqual",
120
- value: function isEqual(phoneNumber) {
121
- return this.number === phoneNumber.number && this.ext === phoneNumber.ext;
122
- }
123
-
124
- // This function was originally meant to be an equivalent for `validatePhoneNumberLength()`,
125
- // but later it was found out that it doesn't include the possible `TOO_SHORT` result
126
- // returned from `parsePhoneNumberWithError()` in the original `validatePhoneNumberLength()`,
127
- // so eventually I simply commented out this method from the `PhoneNumber` class
128
- // and just left the `validatePhoneNumberLength()` function, even though that one would require
129
- // and additional step to also validate the actual country / calling code of the phone number.
130
- // validateLength() {
131
- // const metadata = new Metadata(this.getMetadata())
132
- // metadata.selectNumberingPlan(this.countryCallingCode)
133
- // const result = checkNumberLength(this.nationalNumber, metadata)
134
- // if (result !== 'IS_POSSIBLE') {
135
- // return result
136
- // }
137
- // }
138
- }, {
139
- key: "getType",
140
- value: function getType() {
141
- return getNumberType(this, {
142
- v2: true
143
- }, this.getMetadata());
144
- }
145
- }, {
146
- key: "format",
147
- value: function format(_format, options) {
148
- return formatNumber(this, _format, options ? _objectSpread(_objectSpread({}, options), {}, {
149
- v2: true
150
- }) : {
151
- v2: true
152
- }, this.getMetadata());
153
- }
154
- }, {
155
- key: "formatNational",
156
- value: function formatNational(options) {
157
- return this.format('NATIONAL', options);
158
- }
159
- }, {
160
- key: "formatInternational",
161
- value: function formatInternational(options) {
162
- return this.format('INTERNATIONAL', options);
163
- }
164
- }, {
165
- key: "getURI",
166
- value: function getURI(options) {
167
- return this.format('RFC3966', options);
168
- }
169
- }]);
170
- }();
171
- var isCountryCode = function isCountryCode(value) {
172
- return /^[A-Z]{2}$/.test(value);
173
- };
174
- function getCountryAndCountryCallingCode(countryOrCountryCallingCode, metadataJson) {
175
- var country;
176
- var countryCallingCode;
177
- var metadata = new Metadata(metadataJson);
178
- // If country code is passed then derive `countryCallingCode` from it.
179
- // Also store the country code as `.country`.
180
- if (isCountryCode(countryOrCountryCallingCode)) {
181
- country = countryOrCountryCallingCode;
182
- metadata.selectNumberingPlan(country);
183
- countryCallingCode = metadata.countryCallingCode();
184
- } else {
185
- countryCallingCode = countryOrCountryCallingCode;
186
- }
187
- return {
188
- country: country,
189
- countryCallingCode: countryCallingCode
190
- };
191
- }
192
- var E164_NUMBER_REGEXP = /^\+\d+$/;
193
-
194
- export { PhoneNumber as default };
@@ -1,32 +0,0 @@
1
- // The minimum length of the national significant number.
2
- var MIN_LENGTH_FOR_NSN = 2;
3
-
4
- // The ITU says the maximum length should be 15,
5
- // but one can find longer numbers in Germany.
6
- var MAX_LENGTH_FOR_NSN = 17;
7
-
8
- // The maximum length of the country calling code.
9
- var MAX_LENGTH_COUNTRY_CODE = 3;
10
-
11
- // Digits accepted in phone numbers
12
- // (ascii, fullwidth, arabic-indic, and eastern arabic digits).
13
- var VALID_DIGITS = "0-9\uFF10-\uFF19\u0660-\u0669\u06F0-\u06F9";
14
-
15
- // `DASHES` will be right after the opening square bracket of the "character class"
16
- var DASHES = "-\u2010-\u2015\u2212\u30FC\uFF0D";
17
- var SLASHES = "\uFF0F/";
18
- var DOTS = "\uFF0E.";
19
- var WHITESPACE = " \xA0\xAD\u200B\u2060\u3000";
20
- var BRACKETS = "()\uFF08\uFF09\uFF3B\uFF3D\\[\\]";
21
- // export const OPENING_BRACKETS = '(\uFF08\uFF3B\\\['
22
- var TILDES = "~\u2053\u223C\uFF5E";
23
-
24
- // Regular expression of acceptable punctuation found in phone numbers. This
25
- // excludes punctuation found as a leading character only. This consists of dash
26
- // characters, white space characters, full stops, slashes, square brackets,
27
- // parentheses and tildes. Full-width variants are also present.
28
- var VALID_PUNCTUATION = "".concat(DASHES).concat(SLASHES).concat(DOTS).concat(WHITESPACE).concat(BRACKETS).concat(TILDES);
29
- var PLUS_CHARS = "+\uFF0B";
30
- // const LEADING_PLUS_CHARS_PATTERN = new RegExp('^[' + PLUS_CHARS + ']+')
31
-
32
- export { MAX_LENGTH_COUNTRY_CODE, MAX_LENGTH_FOR_NSN, MIN_LENGTH_FOR_NSN, PLUS_CHARS, VALID_DIGITS, VALID_PUNCTUATION, WHITESPACE };
@@ -1,208 +0,0 @@
1
- import matchesEntirely from './helpers/matchesEntirely.js';
2
- import formatNationalNumberUsingFormat from './helpers/formatNationalNumberUsingFormat.js';
3
- import Metadata, { getCountryCallingCode } from './metadata.js';
4
- import getIddPrefix from './helpers/getIddPrefix.js';
5
- import { formatRFC3966 } from './helpers/RFC3966.js';
6
-
7
- // This is a port of Google Android `libphonenumber`'s
8
- // `phonenumberutil.js` of December 31th, 2018.
9
- //
10
- // https://github.com/googlei18n/libphonenumber/commits/master/javascript/i18n/phonenumbers/phonenumberutil.js
11
-
12
- var DEFAULT_OPTIONS = {
13
- formatExtension: function formatExtension(formattedNumber, extension, metadata) {
14
- return "".concat(formattedNumber).concat(metadata.ext()).concat(extension);
15
- }
16
- };
17
-
18
- /**
19
- * Formats a phone number.
20
- *
21
- * format(phoneNumberInstance, 'INTERNATIONAL', { ..., v2: true }, metadata)
22
- * format(phoneNumberInstance, 'NATIONAL', { ..., v2: true }, metadata)
23
- *
24
- * format({ phone: '8005553535', country: 'RU' }, 'INTERNATIONAL', { ... }, metadata)
25
- * format({ phone: '8005553535', country: 'RU' }, 'NATIONAL', undefined, metadata)
26
- *
27
- * @param {object|PhoneNumber} input — If `options.v2: true` flag is passed, the `input` should be a `PhoneNumber` instance. Otherwise, it should be an object of shape `{ phone: '...', country: '...' }`.
28
- * @param {string} format
29
- * @param {object} [options]
30
- * @param {object} metadata
31
- * @return {string}
32
- */
33
- function formatNumber(input, format, options, metadata) {
34
- // Apply default options.
35
- if (options) {
36
- // Using ES6 "rest spread" syntax here didn't work with `babel`/`istanbul`
37
- // for some weird reason: this line of code would cause the code coverage
38
- // to show as not 100%. That's because `babel`/`istanbul`, for some weird reason,
39
- // apparently doesn't know how to properly exclude Babel polyfills from code coverage.
40
- //
41
- // options = { ...DEFAULT_OPTIONS, ...options }
42
- //
43
- options = merge({}, DEFAULT_OPTIONS, options);
44
- } else {
45
- options = DEFAULT_OPTIONS;
46
- }
47
- metadata = new Metadata(metadata);
48
-
49
- // Normally, the `input` object is supposed to be a `PhoneNumber` class instance.
50
- // Also, according to the `PhoneNumber` class source code, `country` can't be "001".
51
- // It means that normally `input.country` or `input.countryCallingCode` is supposed
52
- // to be present because either of the two is always required to exist in a `PhoneNumber` instance.
53
- // This means that realistically, it's gonna step into either the first `if`
54
- // or the following `else if`, and normally it won't even reach the legacy-compatibility
55
- // `else return input.phone || ''` part.
56
- // So normally, it won't ever return an empty string here.
57
- if (input.country && input.country !== '001') {
58
- // Validate `input.country`.
59
- if (!metadata.hasCountry(input.country)) {
60
- throw new Error("Unknown country: ".concat(input.country));
61
- }
62
- metadata.selectNumberingPlan(input.country);
63
- } else if (input.countryCallingCode) {
64
- metadata.selectNumberingPlan(input.countryCallingCode);
65
- } else return input.phone || '';
66
- var countryCallingCode = metadata.countryCallingCode();
67
- var nationalNumber = options.v2 ? input.nationalNumber : input.phone;
68
-
69
- // This variable should have been declared inside `case`s
70
- // but Babel has a bug and it says "duplicate variable declaration".
71
- var number;
72
- switch (format) {
73
- case 'NATIONAL':
74
- // Normally, the `input` object is supposed to be a `PhoneNumber` class instance,
75
- // and a `PhoneNumber` class instance is always required to have a `nationalNumber`.
76
- // This means that the `if (!nationalNumber)` below is just for legacy-compatibility
77
- // and it normally can't really happen, so normally it won't ever return an empty string here.
78
- if (!nationalNumber) {
79
- return '';
80
- }
81
- number = formatNationalNumber(nationalNumber, input.carrierCode, 'NATIONAL', metadata, options);
82
- return addExtension(number, input.ext, metadata, options.formatExtension);
83
- case 'INTERNATIONAL':
84
- // Legacy argument support.
85
- // (`{ country: ..., phone: '' }`)
86
- if (!nationalNumber) {
87
- return "+".concat(countryCallingCode);
88
- }
89
- number = formatNationalNumber(nationalNumber, null, 'INTERNATIONAL', metadata, options);
90
- number = "+".concat(countryCallingCode, " ").concat(number);
91
- return addExtension(number, input.ext, metadata, options.formatExtension);
92
- case 'E.164':
93
- // `E.164` doesn't define "phone number extensions".
94
- return "+".concat(countryCallingCode).concat(nationalNumber);
95
- case 'RFC3966':
96
- return formatRFC3966({
97
- number: "+".concat(countryCallingCode).concat(nationalNumber),
98
- ext: input.ext
99
- });
100
-
101
- // For reference, here's Google's IDD formatter:
102
- // https://github.com/google/libphonenumber/blob/32719cf74e68796788d1ca45abc85dcdc63ba5b9/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java#L1546
103
- // Not saying that this IDD formatter replicates it 1:1, but it seems to work.
104
- // Who would even need to format phone numbers in IDD format anyway?
105
- case 'IDD':
106
- // If the required `fromCountry` parameter is not passed, it will return `undefined`.
107
- if (!options.fromCountry) {
108
- return;
109
- // throw new Error('`fromCountry` option not passed for IDD-prefixed formatting.')
110
- }
111
- var formattedNumber = formatIDD(nationalNumber, input.carrierCode, countryCallingCode, options.fromCountry, metadata);
112
- // If the country of the phone number doesn't support IDD calling, it will return `undefined`.
113
- if (!formattedNumber) {
114
- return;
115
- }
116
- return addExtension(formattedNumber, input.ext, metadata, options.formatExtension);
117
- default:
118
- throw new Error("Unknown \"format\" argument passed to \"formatNumber()\": \"".concat(format, "\""));
119
- }
120
- }
121
- function formatNationalNumber(number, carrierCode, formatAs, metadata, options) {
122
- var format = chooseFormatForNumber(metadata.formats(), number);
123
- if (!format) {
124
- return number;
125
- }
126
- return formatNationalNumberUsingFormat(number, format, {
127
- useInternationalFormat: formatAs === 'INTERNATIONAL',
128
- withNationalPrefix: format.nationalPrefixIsOptionalWhenFormattingInNationalFormat() && options && options.nationalPrefix === false ? false : true});
129
- }
130
- function chooseFormatForNumber(availableFormats, nationalNumber) {
131
- // Using a `for ... of` loop here didn't work with `babel`/`istanbul`:
132
- // for some weird reason, it showed code coverage less than 100%.
133
- // That's because `babel`/`istanbul`, for some weird reason,
134
- // apparently doesn't know how to properly exclude Babel polyfills from code coverage.
135
- //
136
- // for (const format of availableFormats) { ... }
137
- //
138
- return pickFirstMatchingElement(availableFormats, function (format) {
139
- // Validate leading digits.
140
- // The test case for "else path" could be found by searching for
141
- // "format.leadingDigitsPatterns().length === 0".
142
- if (format.leadingDigitsPatterns().length > 0) {
143
- // The last leading_digits_pattern is used here, as it is the most detailed
144
- var lastLeadingDigitsPattern = format.leadingDigitsPatterns()[format.leadingDigitsPatterns().length - 1];
145
- // If leading digits don't match then move on to the next phone number format
146
- if (nationalNumber.search(lastLeadingDigitsPattern) !== 0) {
147
- return false;
148
- }
149
- }
150
- // Check that the national number matches the phone number format regular expression
151
- return matchesEntirely(nationalNumber, format.pattern());
152
- });
153
- }
154
- function addExtension(formattedNumber, ext, metadata, formatExtension) {
155
- return ext ? formatExtension(formattedNumber, ext, metadata) : formattedNumber;
156
- }
157
- function formatIDD(nationalNumber, carrierCode, countryCallingCode, fromCountry, metadata) {
158
- var fromCountryCallingCode = getCountryCallingCode(fromCountry, metadata.metadata);
159
- // When calling within the same country calling code.
160
- if (fromCountryCallingCode === countryCallingCode) {
161
- var formattedNumber = formatNationalNumber(nationalNumber, carrierCode, 'NATIONAL', metadata);
162
- // For NANPA regions, return the national format for these regions
163
- // but prefix it with the country calling code.
164
- if (countryCallingCode === '1') {
165
- return countryCallingCode + ' ' + formattedNumber;
166
- }
167
- // If regions share a country calling code, the country calling code need
168
- // not be dialled. This also applies when dialling within a region, so this
169
- // if clause covers both these cases. Technically this is the case for
170
- // dialling from La Reunion to other overseas departments of France (French
171
- // Guiana, Martinique, Guadeloupe), but not vice versa - so we don't cover
172
- // this edge case for now and for those cases return the version including
173
- // country calling code. Details here:
174
- // http://www.petitfute.com/voyage/225-info-pratiques-reunion
175
- //
176
- return formattedNumber;
177
- }
178
- var iddPrefix = getIddPrefix(fromCountry, undefined, metadata.metadata);
179
- if (iddPrefix) {
180
- return "".concat(iddPrefix, " ").concat(countryCallingCode, " ").concat(formatNationalNumber(nationalNumber, null, 'INTERNATIONAL', metadata));
181
- }
182
- }
183
- function merge() {
184
- var i = 1;
185
- for (var _len = arguments.length, objects = new Array(_len), _key = 0; _key < _len; _key++) {
186
- objects[_key] = arguments[_key];
187
- }
188
- while (i < objects.length) {
189
- if (objects[i]) {
190
- for (var key in objects[i]) {
191
- objects[0][key] = objects[i][key];
192
- }
193
- }
194
- i++;
195
- }
196
- return objects[0];
197
- }
198
- function pickFirstMatchingElement(elements, testFunction) {
199
- var i = 0;
200
- while (i < elements.length) {
201
- if (testFunction(elements[i])) {
202
- return elements[i];
203
- }
204
- i++;
205
- }
206
- }
207
-
208
- export { chooseFormatForNumber, formatNumber as default };
@@ -1,17 +0,0 @@
1
- /**
2
- * @param {object} - `{ ?number, ?extension }`.
3
- * @return {string} Phone URI (RFC 3966).
4
- */
5
- function formatRFC3966(_ref) {
6
- var number = _ref.number,
7
- ext = _ref.ext;
8
- if (!number) {
9
- return '';
10
- }
11
- if (number[0] !== '+') {
12
- throw new Error("\"formatRFC3966()\" expects \"number\" to be in E.164 format.");
13
- }
14
- return "tel:".concat(number).concat(ext ? ';ext=' + ext : '');
15
- }
16
-
17
- export { formatRFC3966 };
@@ -1,37 +0,0 @@
1
- import { VALID_PUNCTUATION } from '../constants.js';
2
-
3
- // Removes brackets and replaces dashes with spaces.
4
- //
5
- // E.g. "(999) 111-22-33" -> "999 111 22 33"
6
- //
7
- // For some reason Google's metadata contains `<intlFormat/>`s with brackets and dashes.
8
- // Meanwhile, there's no single opinion about using punctuation in international phone numbers.
9
- //
10
- // For example, Google's `<intlFormat/>` for USA is `+1 213-373-4253`.
11
- // And here's a quote from WikiPedia's "North American Numbering Plan" page:
12
- // https://en.wikipedia.org/wiki/North_American_Numbering_Plan
13
- //
14
- // "The country calling code for all countries participating in the NANP is 1.
15
- // In international format, an NANP number should be listed as +1 301 555 01 00,
16
- // where 301 is an area code (Maryland)."
17
- //
18
- // I personally prefer the international format without any punctuation.
19
- // For example, brackets are remnants of the old age, meaning that the
20
- // phone number part in brackets (so called "area code") can be omitted
21
- // if dialing within the same "area".
22
- // And hyphens were clearly introduced for splitting local numbers into memorizable groups.
23
- // For example, remembering "5553535" is difficult but "555-35-35" is much simpler.
24
- // Imagine a man taking a bus from home to work and seeing an ad with a phone number.
25
- // He has a couple of seconds to memorize that number until it passes by.
26
- // If it were spaces instead of hyphens the man wouldn't necessarily get it,
27
- // but with hyphens instead of spaces the grouping is more explicit.
28
- // I personally think that hyphens introduce visual clutter,
29
- // so I prefer replacing them with spaces in international numbers.
30
- // In the modern age all output is done on displays where spaces are clearly distinguishable
31
- // so hyphens can be safely replaced with spaces without losing any legibility.
32
- //
33
- function applyInternationalSeparatorStyle(formattedNumber) {
34
- return formattedNumber.replace(new RegExp("[".concat(VALID_PUNCTUATION, "]+"), 'g'), ' ').trim();
35
- }
36
-
37
- export { applyInternationalSeparatorStyle as default };