libphonenumber-js 1.10.8 → 1.10.11

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libphonenumber-js",
3
- "version": "1.10.8",
3
+ "version": "1.10.11",
4
4
  "description": "A simpler (and smaller) rewrite of Google Android's libphonenumber library in javascript",
5
5
  "main": "index.cjs",
6
6
  "module": "index.js",
@@ -97,7 +97,7 @@ export default class AsYouType {
97
97
  // with the old versions.
98
98
  this.country = country
99
99
  },
100
- onCallingCodeChange: (country, callingCode) => {
100
+ onCallingCodeChange: (callingCode, country) => {
101
101
  this.metadata.selectNumberingPlan(country, callingCode)
102
102
  this.formatter.reset(this.metadata.numberingPlan, this.state)
103
103
  this.parser.reset(this.metadata.numberingPlan)
@@ -1356,6 +1356,13 @@ describe('AsYouType.getNumberValue()', () => {
1356
1356
  formatter.reset()
1357
1357
  formatter.input('059').should.equal('059')
1358
1358
  })
1359
+
1360
+ it('should work for SK phone numbers (2)', function() {
1361
+ // https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/69
1362
+ const formatter = new AsYouType('SK')
1363
+ formatter.input('421901222333').should.equal('421 901 222 333')
1364
+ formatter.getTemplate().should.equal('xxx xxx xxx xxx')
1365
+ })
1359
1366
  })
1360
1367
 
1361
1368
  function type(something) {
@@ -385,7 +385,10 @@ export default class AsYouTypeParser {
385
385
  state.update({
386
386
  IDDPrefix: digits.slice(0, digits.length - numberWithoutIDD.length)
387
387
  })
388
- this.startInternationalNumber(state)
388
+ this.startInternationalNumber(state, {
389
+ country: undefined,
390
+ callingCode: undefined
391
+ })
389
392
  return true
390
393
  }
391
394
  }
@@ -405,14 +408,17 @@ export default class AsYouTypeParser {
405
408
  state.update({
406
409
  missingPlus: true
407
410
  })
408
- this.startInternationalNumber(state)
411
+ this.startInternationalNumber(state, {
412
+ country: state.country,
413
+ callingCode: newCallingCode
414
+ })
409
415
  return true
410
416
  }
411
417
  }
412
418
  }
413
419
 
414
- startInternationalNumber(state) {
415
- state.startInternationalNumber()
420
+ startInternationalNumber(state, { country, callingCode }) {
421
+ state.startInternationalNumber(country, callingCode)
416
422
  // If a national (significant) number has been extracted before, reset it.
417
423
  if (state.nationalSignificantNumber) {
418
424
  state.resetNationalSignificantNumber()
@@ -40,16 +40,16 @@ export default class AsYouTypeState {
40
40
 
41
41
  setCallingCode(callingCode) {
42
42
  this.callingCode = callingCode
43
- return this.onCallingCodeChange(this.country, callingCode)
43
+ this.onCallingCodeChange(callingCode, this.country)
44
44
  }
45
45
 
46
- startInternationalNumber() {
46
+ startInternationalNumber(country, callingCode) {
47
47
  // Prepend the `+` to parsed input.
48
48
  this.international = true
49
49
  // If a default country was set then reset it
50
50
  // because an explicitly international phone
51
51
  // number is being entered.
52
- this.initCountryAndCallingCode()
52
+ this.initCountryAndCallingCode(country, callingCode)
53
53
  }
54
54
 
55
55
  appendDigits(nextDigits) {
package/types.d.ts CHANGED
@@ -24,7 +24,7 @@ export type Countries = {
24
24
  // `in` operator docs:
25
25
  // https://www.typescriptlang.org/docs/handbook/advanced-types.html#mapped-types
26
26
  // `country in CountryCode` means "for each and every CountryCode".
27
- [country in CountryCode]: any[];
27
+ [country in CountryCode]?: any[];
28
28
  };
29
29
 
30
30
  export type MetadataJson = {