libphonenumber-js 1.13.4 → 1.13.5

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/CHANGELOG.md CHANGED
@@ -67,21 +67,26 @@ And edit the README:
67
67
 
68
68
  <!-- This changelog [only](https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/16#note_594165443) mentions the changes in the code. See [Google's changelog](https://github.com/google/libphonenumber/blob/master/release_notes.txt) for metadata changes. -->
69
69
 
70
- <!-- CHANGELOG START -->
71
-
72
- 1.13.3 / 22.5.2026
73
- ===================
74
-
75
- * Updated metadata to version 9.0.31:
76
- - Updated alternate formatting data for country calling code(s): 84
77
- - Updated phone metadata for region code(s):
78
- AI, BO, DZ, ET, GE, GM, IN, TR, UG, VN
79
- - Updated short number metadata for region code(s): IT
80
- - Updated geocoding data for country calling code(s): 213 (en)
81
- - Updated carrier data for country calling code(s):
82
- 34 (en), 43 (en), 84 (en), 90 (en), 220 (en), 251 (en), 256 (en), 354 (en),
83
- 591 (en), 1264 (en)
84
-
70
+ <!-- CHANGELOG START -->
71
+
72
+ 1.13.5 / 03.06.2026
73
+ ===================
74
+
75
+ * Converted any "tagged" types [back](https://gitlab.com/catamphetamine/libphonenumber-js/-/work_items/144#note_3415397139) to simple strings. Originally, some developers lobbied the use of so-called ["tagged"](https://medium.com/@ethanresnick/advanced-typescript-tagged-types-for-fewer-bugs-and-better-security-24db681d5721) types in this package in order to return more "strict" values. My knowledge of TypeScript at that time was limited to just its title, so I naturally succumbed to that influence and merged whatever changes seemed to be consensual between the participants in the issue discussions. Now though I can see how the concept of "tagged" types is redundant and adds nothing, so I decided to revert any "tagged" types back to simple strings.
76
+
77
+ 1.13.3 / 22.5.2026
78
+ ===================
79
+
80
+ * Updated metadata to version 9.0.31:
81
+ - Updated alternate formatting data for country calling code(s): 84
82
+ - Updated phone metadata for region code(s):
83
+ AI, BO, DZ, ET, GE, GM, IN, TR, UG, VN
84
+ - Updated short number metadata for region code(s): IT
85
+ - Updated geocoding data for country calling code(s): 213 (en)
86
+ - Updated carrier data for country calling code(s):
87
+ 34 (en), 43 (en), 84 (en), 90 (en), 220 (en), 251 (en), 256 (en), 354 (en),
88
+ 591 (en), 1264 (en)
89
+
85
90
  1.13.0 / 08.05.2026
86
91
  ===================
87
92
 
@@ -1 +1 @@
1
- {"version":3,"file":"checkNumberLength.test.js","names":["_mocha","require","_chai","_metadata","_interopRequireWildcard","_metadataMax","_interopRequireDefault","_metadataMin","_checkNumberLength","e","__esModule","t","WeakMap","r","n","o","i","f","__proto__","_typeof","has","get","set","_t","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","describe","it","expect","checkNumberLengthWithCountry","to","equal","undefined","metadataInstance","Metadata","metadata","selectNumberingPlan","checkNumberLengthForType","oldMetadataInstance","oldMetadata","checkNumberLength","number","country","type"],"sources":["../../source/helpers/checkNumberLength.test.js"],"sourcesContent":["import { describe, it } from 'mocha'\r\nimport { expect } from 'chai'\r\n\r\nimport Metadata, { getCountryCallingCode } from '../metadata.js'\r\nimport metadata from '../../metadata.max.json' with { type: 'json' }\r\nimport oldMetadata from '../../test/metadata/1.0.0/metadata.min.json' with { type: 'json' }\r\n\r\nimport checkNumberLength, { checkNumberLengthForType } from './checkNumberLength.js'\r\n\r\ndescribe('checkNumberLength', () => {\r\n\tit('should check phone number length (`country` is pre-selected in metadata instance)', () => {\r\n\t\t// Too short.\r\n\t\texpect(checkNumberLengthWithCountry('800555353', 'RU', 'FIXED_LINE')).to.equal('TOO_SHORT')\r\n\t\t// Normal.\r\n\t\texpect(checkNumberLengthWithCountry('8005553535', 'RU', 'FIXED_LINE')).to.equal('IS_POSSIBLE')\r\n\t\t// Too long.\r\n\t\texpect(checkNumberLengthWithCountry('80055535355', 'RU', 'FIXED_LINE')).to.equal('TOO_LONG')\r\n\r\n\t\t// No such type.\r\n\t\texpect(checkNumberLengthWithCountry('169454850', 'AC', 'VOIP')).to.equal('INVALID_LENGTH')\r\n\t\t// No such possible length.\r\n\t\texpect(checkNumberLengthWithCountry('1694548', 'AD', undefined)).to.equal('INVALID_LENGTH')\r\n\r\n\t\t// FIXED_LINE_OR_MOBILE\r\n\t\texpect(checkNumberLengthWithCountry('1694548', 'AD', 'FIXED_LINE_OR_MOBILE')).to.equal('INVALID_LENGTH')\r\n\t\t// No mobile phones.\r\n\t\texpect(checkNumberLengthWithCountry('8123', 'TA', 'FIXED_LINE_OR_MOBILE')).to.equal('IS_POSSIBLE')\r\n\t\t// No \"possible lengths\" for \"mobile\".\r\n\t\texpect(checkNumberLengthWithCountry('81234567', 'SZ', 'FIXED_LINE_OR_MOBILE')).to.equal('IS_POSSIBLE')\r\n\t})\r\n\r\n\tit('should check phone number length (`country` override)', () => {\r\n\t\tconst metadataInstance = new Metadata(metadata)\r\n\t\tmetadataInstance.selectNumberingPlan('US')\r\n\t\t// \"UAN\" phone number type doesn't exist in \"US\".\r\n\t\t// Hence, it returns \"INVALID_LENGTH\".\r\n\t\texpect(checkNumberLengthForType('2133734253', 'UAN', undefined, metadataInstance)).to.equal('INVALID_LENGTH')\r\n\t\texpect(checkNumberLengthForType('2133734253', 'UAN', 'CA', metadataInstance)).to.equal('TOO_LONG')\r\n\t\t// \"UAN\" phone number type doesn't exist in \"US\".\r\n\t\t// Hence, it returns \"INVALID_LENGTH\".\r\n\t\texpect(checkNumberLengthForType('2133734', 'UAN', undefined, metadataInstance)).to.equal('INVALID_LENGTH')\r\n\t\texpect(checkNumberLengthForType('2133734', 'UAN', 'CA', metadataInstance)).to.equal('IS_POSSIBLE')\r\n\t})\r\n\r\n\tit('should work for old metadata (`country` specified)', function() {\r\n\t\tconst oldMetadataInstance = new Metadata(oldMetadata)\r\n\t\toldMetadataInstance.selectNumberingPlan('KZ')\r\n\t\texpect(checkNumberLengthForType('8005553535', 'FIXED_LINE', 'RU', oldMetadataInstance)).to.equal('IS_POSSIBLE')\r\n\t})\r\n\r\n\tit('should work for old metadata (no `country` specified)', function() {\r\n\t\tconst oldMetadataInstance = new Metadata(oldMetadata)\r\n\t\toldMetadataInstance.selectNumberingPlan('RU')\r\n\t\texpect(checkNumberLengthForType('8005553535', 'FIXED_LINE', undefined, oldMetadataInstance)).to.equal('IS_POSSIBLE')\r\n\t})\r\n\r\n\tit('should handle the cases when multiple countries share the same country calling code and a phone number is possible in non-\"main\" country and is not possible in the \"main\" country', () => {\r\n\t\tconst metadataInstance = new Metadata(metadata)\r\n\t\tmetadataInstance.selectNumberingPlan('1')\r\n\t\texpect(checkNumberLength('3100000', undefined, metadataInstance)).to.equal('TOO_SHORT');\r\n\t\texpect(checkNumberLength('3100000', 'US', metadataInstance)).to.equal('TOO_SHORT');\r\n\t\texpect(checkNumberLength('3100000', 'CA', metadataInstance)).to.equal('IS_POSSIBLE');\r\n\t})\r\n})\r\n\r\nfunction checkNumberLengthWithCountry(number, country, type) {\r\n\tconst metadataInstance = new Metadata(metadata)\r\n\tmetadataInstance.selectNumberingPlan(country)\r\n\treturn checkNumberLengthForType(number, type, undefined, metadataInstance)\r\n}"],"mappings":";;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAEA,IAAAE,SAAA,GAAAC,uBAAA,CAAAH,OAAA;AACA,IAAAI,YAAA,GAAAC,sBAAA,CAAAL,OAAA;AACA,IAAAM,YAAA,GAAAD,sBAAA,CAAAL,OAAA;AAEA,IAAAO,kBAAA,GAAAJ,uBAAA,CAAAH,OAAA;AAAoF,SAAAK,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,gBAAAA,CAAA;AAAA,SAAAL,wBAAAK,CAAA,EAAAE,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAR,uBAAA,YAAAA,wBAAAK,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAC,UAAA,SAAAD,CAAA,MAAAM,CAA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EAAEP,gBAAgB,CAAC,CAAC,CAACH,EAAE,CAACC,KAAK,CAAC,WAAW,CAAC;IAClF,IAAAH,YAAM,EAAC,IAAAY,6BAAiB,EAAC,SAAS,EAAE,IAAI,EAAEP,gBAAgB,CAAC,CAAC,CAACH,EAAE,CAACC,KAAK,CAAC,aAAa,CAAC;EACrF,CAAC,CAAC;AACH,CAAC,CAAC;AAEF,SAASF,4BAA4BA,CAACY,MAAM,EAAEC,OAAO,EAAEC,IAAI,EAAE;EAC5D,IAAMV,gBAAgB,GAAG,IAAIC,oBAAQ,CAACC,uBAAQ,CAAC;EAC/CF,gBAAgB,CAACG,mBAAmB,CAACM,OAAO,CAAC;EAC7C,OAAO,IAAAL,2CAAwB,EAACI,MAAM,EAAEE,IAAI,EAAEX,SAAS,EAAEC,gBAAgB,CAAC;AAC3E","ignoreList":[]}
1
+ {"version":3,"file":"checkNumberLength.test.js","names":["_mocha","require","_chai","_metadata","_interopRequireWildcard","_metadataMax","_interopRequireDefault","_metadataMin","_checkNumberLength","e","__esModule","t","WeakMap","r","n","o","i","f","__proto__","_typeof","has","get","set","_t","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","describe","it","expect","checkNumberLengthWithCountry","to","equal","undefined","metadataInstance","Metadata","metadata","selectNumberingPlan","checkNumberLengthForType","oldMetadataInstance","oldMetadata","checkNumberLength","number","country","type"],"sources":["../../source/helpers/checkNumberLength.test.js"],"sourcesContent":["import { describe, it } from 'mocha'\r\nimport { expect } from 'chai'\r\n\r\nimport Metadata, { getCountryCallingCode } from '../metadata.js'\r\nimport metadata from '../../metadata.max.json' with { type: 'json' }\r\nimport oldMetadata from '../../test/metadata/1.0.0/metadata.min.json' with { type: 'json' }\r\n\r\nimport checkNumberLength, { checkNumberLengthForType } from './checkNumberLength.js'\r\n\r\ndescribe('checkNumberLength', () => {\r\n\tit('should check phone number length (`country` is pre-selected in metadata instance)', () => {\r\n\t\t// Too short.\r\n\t\texpect(checkNumberLengthWithCountry('800555353', 'RU', 'FIXED_LINE')).to.equal('TOO_SHORT')\r\n\t\t// Normal.\r\n\t\texpect(checkNumberLengthWithCountry('8005553535', 'RU', 'FIXED_LINE')).to.equal('IS_POSSIBLE')\r\n\t\t// Too long.\r\n\t\texpect(checkNumberLengthWithCountry('80055535355', 'RU', 'FIXED_LINE')).to.equal('TOO_LONG')\r\n\r\n\t\t// No such type.\r\n\t\texpect(checkNumberLengthWithCountry('169454850', 'AC', 'VOIP')).to.equal('INVALID_LENGTH')\r\n\t\t// No such possible length.\r\n\t\texpect(checkNumberLengthWithCountry('1694548', 'AD', undefined)).to.equal('INVALID_LENGTH')\r\n\r\n\t\t// FIXED_LINE_OR_MOBILE\r\n\t\texpect(checkNumberLengthWithCountry('1694548', 'AD', 'FIXED_LINE_OR_MOBILE')).to.equal('INVALID_LENGTH')\r\n\t\t// No mobile phones.\r\n\t\texpect(checkNumberLengthWithCountry('8123', 'TA', 'FIXED_LINE_OR_MOBILE')).to.equal('IS_POSSIBLE')\r\n\t\t// No \"possible lengths\" for \"mobile\".\r\n\t\texpect(checkNumberLengthWithCountry('81234567', 'SZ', 'FIXED_LINE_OR_MOBILE')).to.equal('IS_POSSIBLE')\r\n\t})\r\n\r\n\tit('should check phone number length (`country` override)', () => {\r\n\t\tconst metadataInstance = new Metadata(metadata)\r\n\t\tmetadataInstance.selectNumberingPlan('US')\r\n\r\n\t\t// The country code \"US\" will be overridden with \"CA\".\r\n\t\t//\r\n\t\t// How to find a suitable override for tests:\r\n\t\t//\r\n\t\t// for (const callingCode of Object.keys(metadata.country_calling_codes)) {\r\n\t\t// \tconst countries = metadata.country_calling_codes[callingCode]\r\n\t\t// \tif (countries.length > 1) {\r\n\t\t// \t\tconst mainCountry = countries.shift()\r\n\t\t// \t\tfor (const country of countries) {\r\n\t\t// \t\t\tif (JSON.stringify(metadata.countries[country].possible_lengths) !== JSON.stringify(metadata.countries[mainCountry].possible_lengths)) {\r\n\t\t// \t\t\t\tconsole.log(country, 'has different possible lengths from the default country', mainCountry)\r\n\t\t// \t\t\t}\r\n\t\t// \t\t}\r\n\t\t// \t}\r\n\t\t// }\r\n\r\n\t\t// \"UAN\" phone number type doesn't exist in \"US\".\r\n\t\t// Hence, it returns \"INVALID_LENGTH\".\r\n\t\texpect(checkNumberLengthForType('2133734253', 'UAN', undefined, metadataInstance)).to.equal('INVALID_LENGTH')\r\n\t\texpect(checkNumberLengthForType('2133734253', 'UAN', 'CA', metadataInstance)).to.equal('TOO_LONG')\r\n\t\t// \"UAN\" phone number type doesn't exist in \"US\".\r\n\t\t// Hence, it returns \"INVALID_LENGTH\".\r\n\t\texpect(checkNumberLengthForType('2133734', 'UAN', undefined, metadataInstance)).to.equal('INVALID_LENGTH')\r\n\t\texpect(checkNumberLengthForType('2133734', 'UAN', 'CA', metadataInstance)).to.equal('IS_POSSIBLE')\r\n\t})\r\n\r\n\tit('should work for old metadata (`country` specified)', function() {\r\n\t\tconst oldMetadataInstance = new Metadata(oldMetadata)\r\n\t\toldMetadataInstance.selectNumberingPlan('KZ')\r\n\t\texpect(checkNumberLengthForType('8005553535', 'FIXED_LINE', 'RU', oldMetadataInstance)).to.equal('IS_POSSIBLE')\r\n\t})\r\n\r\n\tit('should work for old metadata (no `country` specified)', function() {\r\n\t\tconst oldMetadataInstance = new Metadata(oldMetadata)\r\n\t\toldMetadataInstance.selectNumberingPlan('RU')\r\n\t\texpect(checkNumberLengthForType('8005553535', 'FIXED_LINE', undefined, oldMetadataInstance)).to.equal('IS_POSSIBLE')\r\n\t})\r\n\r\n\tit('should handle the cases when multiple countries share the same country calling code and a phone number is possible in non-\"main\" country and is not possible in the \"main\" country', () => {\r\n\t\tconst metadataInstance = new Metadata(metadata)\r\n\t\tmetadataInstance.selectNumberingPlan('1')\r\n\t\texpect(checkNumberLength('3100000', undefined, metadataInstance)).to.equal('TOO_SHORT');\r\n\t\texpect(checkNumberLength('3100000', 'US', metadataInstance)).to.equal('TOO_SHORT');\r\n\t\texpect(checkNumberLength('3100000', 'CA', metadataInstance)).to.equal('IS_POSSIBLE');\r\n\t})\r\n})\r\n\r\nfunction checkNumberLengthWithCountry(number, country, type) {\r\n\tconst metadataInstance = new Metadata(metadata)\r\n\tmetadataInstance.selectNumberingPlan(country)\r\n\treturn checkNumberLengthForType(number, type, undefined, metadataInstance)\r\n}"],"mappings":";;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAEA,IAAAE,SAAA,GAAAC,uBAAA,CAAAH,OAAA;AACA,IAAAI,YAAA,GAAAC,sBAAA,CAAAL,OAAA;AACA,IAAAM,YAAA,GAAAD,sBAAA,CAAAL,OAAA;AAEA,IAAAO,kBAAA,GAAAJ,uBAAA,CAAAH,OAAA;AAAoF,SAAAK,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,gBAAAA,CAAA;AAAA,SAAAL,wBAAAK,CAAA,EAAAE,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAR,uBAAA,YAAAA,wBAAAK,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAC,UAAA,SAAAD,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,mBAAAT,CAAA,iBAAAA,CAAA,gBAAAU,OAAA,CAAAV,CAAA,0BAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAJ,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAE,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,cAAAM,EAAA,IAAAd,CAAA,gBAAAc,EAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAhB,CAAA,EAAAc,EAAA,OAAAP,CAAA,IAAAD,CAAA,GAAAW,MA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AC/CF,gBAAgB,CAACG,mBAAmB,CAACM,OAAO,CAAC;EAC7C,OAAO,IAAAL,2CAAwB,EAACI,MAAM,EAAEE,IAAI,EAAEX,SAAS,EAAEC,gBAAgB,CAAC;AAC3E","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"checkNumberLength.test.js","names":["describe","it","expect","Metadata","getCountryCallingCode","metadata","type","oldMetadata","checkNumberLength","checkNumberLengthForType","checkNumberLengthWithCountry","to","equal","undefined","metadataInstance","selectNumberingPlan","oldMetadataInstance","number","country"],"sources":["../../source/helpers/checkNumberLength.test.js"],"sourcesContent":["import { describe, it } from 'mocha'\r\nimport { expect } from 'chai'\r\n\r\nimport Metadata, { getCountryCallingCode } from '../metadata.js'\r\nimport metadata from '../../metadata.max.json' with { type: 'json' }\r\nimport oldMetadata from '../../test/metadata/1.0.0/metadata.min.json' with { type: 'json' }\r\n\r\nimport checkNumberLength, { checkNumberLengthForType } from './checkNumberLength.js'\r\n\r\ndescribe('checkNumberLength', () => {\r\n\tit('should check phone number length (`country` is pre-selected in metadata instance)', () => {\r\n\t\t// Too short.\r\n\t\texpect(checkNumberLengthWithCountry('800555353', 'RU', 'FIXED_LINE')).to.equal('TOO_SHORT')\r\n\t\t// Normal.\r\n\t\texpect(checkNumberLengthWithCountry('8005553535', 'RU', 'FIXED_LINE')).to.equal('IS_POSSIBLE')\r\n\t\t// Too long.\r\n\t\texpect(checkNumberLengthWithCountry('80055535355', 'RU', 'FIXED_LINE')).to.equal('TOO_LONG')\r\n\r\n\t\t// No such type.\r\n\t\texpect(checkNumberLengthWithCountry('169454850', 'AC', 'VOIP')).to.equal('INVALID_LENGTH')\r\n\t\t// No such possible length.\r\n\t\texpect(checkNumberLengthWithCountry('1694548', 'AD', undefined)).to.equal('INVALID_LENGTH')\r\n\r\n\t\t// FIXED_LINE_OR_MOBILE\r\n\t\texpect(checkNumberLengthWithCountry('1694548', 'AD', 'FIXED_LINE_OR_MOBILE')).to.equal('INVALID_LENGTH')\r\n\t\t// No mobile phones.\r\n\t\texpect(checkNumberLengthWithCountry('8123', 'TA', 'FIXED_LINE_OR_MOBILE')).to.equal('IS_POSSIBLE')\r\n\t\t// No \"possible lengths\" for \"mobile\".\r\n\t\texpect(checkNumberLengthWithCountry('81234567', 'SZ', 'FIXED_LINE_OR_MOBILE')).to.equal('IS_POSSIBLE')\r\n\t})\r\n\r\n\tit('should check phone number length (`country` override)', () => {\r\n\t\tconst metadataInstance = new Metadata(metadata)\r\n\t\tmetadataInstance.selectNumberingPlan('US')\r\n\t\t// \"UAN\" phone number type doesn't exist in \"US\".\r\n\t\t// Hence, it returns \"INVALID_LENGTH\".\r\n\t\texpect(checkNumberLengthForType('2133734253', 'UAN', undefined, metadataInstance)).to.equal('INVALID_LENGTH')\r\n\t\texpect(checkNumberLengthForType('2133734253', 'UAN', 'CA', metadataInstance)).to.equal('TOO_LONG')\r\n\t\t// \"UAN\" phone number type doesn't exist in \"US\".\r\n\t\t// Hence, it returns \"INVALID_LENGTH\".\r\n\t\texpect(checkNumberLengthForType('2133734', 'UAN', undefined, metadataInstance)).to.equal('INVALID_LENGTH')\r\n\t\texpect(checkNumberLengthForType('2133734', 'UAN', 'CA', metadataInstance)).to.equal('IS_POSSIBLE')\r\n\t})\r\n\r\n\tit('should work for old metadata (`country` specified)', function() {\r\n\t\tconst oldMetadataInstance = new Metadata(oldMetadata)\r\n\t\toldMetadataInstance.selectNumberingPlan('KZ')\r\n\t\texpect(checkNumberLengthForType('8005553535', 'FIXED_LINE', 'RU', oldMetadataInstance)).to.equal('IS_POSSIBLE')\r\n\t})\r\n\r\n\tit('should work for old metadata (no `country` specified)', function() {\r\n\t\tconst oldMetadataInstance = new Metadata(oldMetadata)\r\n\t\toldMetadataInstance.selectNumberingPlan('RU')\r\n\t\texpect(checkNumberLengthForType('8005553535', 'FIXED_LINE', undefined, oldMetadataInstance)).to.equal('IS_POSSIBLE')\r\n\t})\r\n\r\n\tit('should handle the cases when multiple countries share the same country calling code and a phone number is possible in non-\"main\" country and is not possible in the \"main\" country', () => {\r\n\t\tconst metadataInstance = new Metadata(metadata)\r\n\t\tmetadataInstance.selectNumberingPlan('1')\r\n\t\texpect(checkNumberLength('3100000', undefined, metadataInstance)).to.equal('TOO_SHORT');\r\n\t\texpect(checkNumberLength('3100000', 'US', metadataInstance)).to.equal('TOO_SHORT');\r\n\t\texpect(checkNumberLength('3100000', 'CA', metadataInstance)).to.equal('IS_POSSIBLE');\r\n\t})\r\n})\r\n\r\nfunction checkNumberLengthWithCountry(number, country, type) {\r\n\tconst metadataInstance = new Metadata(metadata)\r\n\tmetadataInstance.selectNumberingPlan(country)\r\n\treturn checkNumberLengthForType(number, type, undefined, metadataInstance)\r\n}"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,EAAE,QAAQ,OAAO;AACpC,SAASC,MAAM,QAAQ,MAAM;AAE7B,OAAOC,QAAQ,IAAIC,qBAAqB,QAAQ,gBAAgB;AAChE,OAAOC,QAAQ,MAAM,yBAAyB,QAAQC,IAAI,EAAE,MAAM;AAClE,OAAOC,WAAW,MAAM,6CAA6C,QAAQD,IAAI,EAAE,MAAM;AAEzF,OAAOE,iBAAiB,IAAIC,wBAAwB,QAAQ,wBAAwB;AAEpFT,QAAQ,CAAC,mBAAmB,EAAE,YAAM;EACnCC,EAAE,CAAC,mFAAmF,EAAE,YAAM;IAC7F;IACAC,MAAM,CAACQ,4BAA4B,CAAC,WAAW,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC,CAACC,EAAE,CAACC,KAAK,CAAC,WAAW,CAAC;IAC3F;IACAV,MAAM,CAACQ,4BAA4B,CAAC,YAAY,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC,CAACC,EAAE,CAACC,KAAK,CAAC,aAAa,CAAC;IAC9F;IACAV,MAAM,CAACQ,4BAA4B,CAAC,aAAa,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC,CAACC,EAAE,CAACC,KAAK,CAAC,UAAU,CAAC;;IAE5F;IACAV,MAAM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,CAACC,KAAK,CAAC,aAAa,CAAC;EACrF,CAAC,CAAC;AACH,CAAC,CAAC;AAEF,SAASF,4BAA4BA,CAACO,MAAM,EAAEC,OAAO,EAAEZ,IAAI,EAAE;EAC5D,IAAMQ,gBAAgB,GAAG,IAAIX,QAAQ,CAACE,QAAQ,CAAC;EAC/CS,gBAAgB,CAACC,mBAAmB,CAACG,OAAO,CAAC;EAC7C,OAAOT,wBAAwB,CAACQ,MAAM,EAAEX,IAAI,EAAEO,SAAS,EAAEC,gBAAgB,CAAC;AAC3E","ignoreList":[]}
1
+ {"version":3,"file":"checkNumberLength.test.js","names":["describe","it","expect","Metadata","getCountryCallingCode","metadata","type","oldMetadata","checkNumberLength","checkNumberLengthForType","checkNumberLengthWithCountry","to","equal","undefined","metadataInstance","selectNumberingPlan","oldMetadataInstance","number","country"],"sources":["../../source/helpers/checkNumberLength.test.js"],"sourcesContent":["import { describe, it } from 'mocha'\r\nimport { expect } from 'chai'\r\n\r\nimport Metadata, { getCountryCallingCode } from '../metadata.js'\r\nimport metadata from '../../metadata.max.json' with { type: 'json' }\r\nimport oldMetadata from '../../test/metadata/1.0.0/metadata.min.json' with { type: 'json' }\r\n\r\nimport checkNumberLength, { checkNumberLengthForType } from './checkNumberLength.js'\r\n\r\ndescribe('checkNumberLength', () => {\r\n\tit('should check phone number length (`country` is pre-selected in metadata instance)', () => {\r\n\t\t// Too short.\r\n\t\texpect(checkNumberLengthWithCountry('800555353', 'RU', 'FIXED_LINE')).to.equal('TOO_SHORT')\r\n\t\t// Normal.\r\n\t\texpect(checkNumberLengthWithCountry('8005553535', 'RU', 'FIXED_LINE')).to.equal('IS_POSSIBLE')\r\n\t\t// Too long.\r\n\t\texpect(checkNumberLengthWithCountry('80055535355', 'RU', 'FIXED_LINE')).to.equal('TOO_LONG')\r\n\r\n\t\t// No such type.\r\n\t\texpect(checkNumberLengthWithCountry('169454850', 'AC', 'VOIP')).to.equal('INVALID_LENGTH')\r\n\t\t// No such possible length.\r\n\t\texpect(checkNumberLengthWithCountry('1694548', 'AD', undefined)).to.equal('INVALID_LENGTH')\r\n\r\n\t\t// FIXED_LINE_OR_MOBILE\r\n\t\texpect(checkNumberLengthWithCountry('1694548', 'AD', 'FIXED_LINE_OR_MOBILE')).to.equal('INVALID_LENGTH')\r\n\t\t// No mobile phones.\r\n\t\texpect(checkNumberLengthWithCountry('8123', 'TA', 'FIXED_LINE_OR_MOBILE')).to.equal('IS_POSSIBLE')\r\n\t\t// No \"possible lengths\" for \"mobile\".\r\n\t\texpect(checkNumberLengthWithCountry('81234567', 'SZ', 'FIXED_LINE_OR_MOBILE')).to.equal('IS_POSSIBLE')\r\n\t})\r\n\r\n\tit('should check phone number length (`country` override)', () => {\r\n\t\tconst metadataInstance = new Metadata(metadata)\r\n\t\tmetadataInstance.selectNumberingPlan('US')\r\n\r\n\t\t// The country code \"US\" will be overridden with \"CA\".\r\n\t\t//\r\n\t\t// How to find a suitable override for tests:\r\n\t\t//\r\n\t\t// for (const callingCode of Object.keys(metadata.country_calling_codes)) {\r\n\t\t// \tconst countries = metadata.country_calling_codes[callingCode]\r\n\t\t// \tif (countries.length > 1) {\r\n\t\t// \t\tconst mainCountry = countries.shift()\r\n\t\t// \t\tfor (const country of countries) {\r\n\t\t// \t\t\tif (JSON.stringify(metadata.countries[country].possible_lengths) !== JSON.stringify(metadata.countries[mainCountry].possible_lengths)) {\r\n\t\t// \t\t\t\tconsole.log(country, 'has different possible lengths from the default country', mainCountry)\r\n\t\t// \t\t\t}\r\n\t\t// \t\t}\r\n\t\t// \t}\r\n\t\t// }\r\n\r\n\t\t// \"UAN\" phone number type doesn't exist in \"US\".\r\n\t\t// Hence, it returns \"INVALID_LENGTH\".\r\n\t\texpect(checkNumberLengthForType('2133734253', 'UAN', undefined, metadataInstance)).to.equal('INVALID_LENGTH')\r\n\t\texpect(checkNumberLengthForType('2133734253', 'UAN', 'CA', metadataInstance)).to.equal('TOO_LONG')\r\n\t\t// \"UAN\" phone number type doesn't exist in \"US\".\r\n\t\t// Hence, it returns \"INVALID_LENGTH\".\r\n\t\texpect(checkNumberLengthForType('2133734', 'UAN', undefined, metadataInstance)).to.equal('INVALID_LENGTH')\r\n\t\texpect(checkNumberLengthForType('2133734', 'UAN', 'CA', metadataInstance)).to.equal('IS_POSSIBLE')\r\n\t})\r\n\r\n\tit('should work for old metadata (`country` specified)', function() {\r\n\t\tconst oldMetadataInstance = new Metadata(oldMetadata)\r\n\t\toldMetadataInstance.selectNumberingPlan('KZ')\r\n\t\texpect(checkNumberLengthForType('8005553535', 'FIXED_LINE', 'RU', oldMetadataInstance)).to.equal('IS_POSSIBLE')\r\n\t})\r\n\r\n\tit('should work for old metadata (no `country` specified)', function() {\r\n\t\tconst oldMetadataInstance = new Metadata(oldMetadata)\r\n\t\toldMetadataInstance.selectNumberingPlan('RU')\r\n\t\texpect(checkNumberLengthForType('8005553535', 'FIXED_LINE', undefined, oldMetadataInstance)).to.equal('IS_POSSIBLE')\r\n\t})\r\n\r\n\tit('should handle the cases when multiple countries share the same country calling code and a phone number is possible in non-\"main\" country and is not possible in the \"main\" country', () => {\r\n\t\tconst metadataInstance = new Metadata(metadata)\r\n\t\tmetadataInstance.selectNumberingPlan('1')\r\n\t\texpect(checkNumberLength('3100000', undefined, metadataInstance)).to.equal('TOO_SHORT');\r\n\t\texpect(checkNumberLength('3100000', 'US', metadataInstance)).to.equal('TOO_SHORT');\r\n\t\texpect(checkNumberLength('3100000', 'CA', metadataInstance)).to.equal('IS_POSSIBLE');\r\n\t})\r\n})\r\n\r\nfunction checkNumberLengthWithCountry(number, country, type) {\r\n\tconst metadataInstance = new Metadata(metadata)\r\n\tmetadataInstance.selectNumberingPlan(country)\r\n\treturn checkNumberLengthForType(number, type, undefined, metadataInstance)\r\n}"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,EAAE,QAAQ,OAAO;AACpC,SAASC,MAAM,QAAQ,MAAM;AAE7B,OAAOC,QAAQ,IAAIC,qBAAqB,QAAQ,gBAAgB;AA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,IAAIb,QAAQ,CAACI,WAAW,CAAC;IACrDS,mBAAmB,CAACD,mBAAmB,CAAC,IAAI,CAAC;IAC7Cb,MAAM,CAACO,wBAAwB,CAAC,YAAY,EAAE,YAAY,EAAEI,SAAS,EAAEG,mBAAmB,CAAC,CAAC,CAACL,EAAE,CAACC,KAAK,CAAC,aAAa,CAAC;EACrH,CAAC,CAAC;EAEFX,EAAE,CAAC,oLAAoL,EAAE,YAAM;IAC9L,IAAMa,gBAAgB,GAAG,IAAIX,QAAQ,CAACE,QAAQ,CAAC;IAC/CS,gBAAgB,CAACC,mBAAmB,CAAC,GAAG,CAAC;IACzCb,MAAM,CAACM,iBAAiB,CAAC,SAAS,EAAEK,SAAS,EAAEC,gBAAgB,CAAC,CAAC,CAACH,EAAE,CAACC,KAAK,CAAC,WAAW,CAAC;IACvFV,MAAM,CAACM,iBAAiB,CAAC,SAAS,EAAE,IAAI,EAAEM,gBAAgB,CAAC,CAAC,CAACH,EAAE,CAACC,KAAK,CAAC,WAAW,CAAC;IAClFV,MAAM,CAACM,iBAAiB,CAAC,SAAS,EAAE,IAAI,EAAEM,gBAAgB,CAAC,CAAC,CAACH,EAAE,CAACC,KAAK,CAAC,aAAa,CAAC;EACrF,CAAC,CAAC;AACH,CAAC,CAAC;AAEF,SAASF,4BAA4BA,CAACO,MAAM,EAAEC,OAAO,EAAEZ,IAAI,EAAE;EAC5D,IAAMQ,gBAAgB,GAAG,IAAIX,QAAQ,CAACE,QAAQ,CAAC;EAC/CS,gBAAgB,CAACC,mBAAmB,CAACG,OAAO,CAAC;EAC7C,OAAOT,wBAAwB,CAACQ,MAAM,EAAEX,IAAI,EAAEO,SAAS,EAAEC,gBAAgB,CAAC;AAC3E","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"checkNumberLength.test.js","names":["describe","it","expect","Metadata","getCountryCallingCode","metadata","type","oldMetadata","checkNumberLength","checkNumberLengthForType","checkNumberLengthWithCountry","to","equal","undefined","metadataInstance","selectNumberingPlan","oldMetadataInstance","number","country"],"sources":["../../source/helpers/checkNumberLength.test.js"],"sourcesContent":["import { describe, it } from 'mocha'\r\nimport { expect } from 'chai'\r\n\r\nimport Metadata, { getCountryCallingCode } from '../metadata.js'\r\nimport metadata from '../../metadata.max.json' with { type: 'json' }\r\nimport oldMetadata from '../../test/metadata/1.0.0/metadata.min.json' with { type: 'json' }\r\n\r\nimport checkNumberLength, { checkNumberLengthForType } from './checkNumberLength.js'\r\n\r\ndescribe('checkNumberLength', () => {\r\n\tit('should check phone number length (`country` is pre-selected in metadata instance)', () => {\r\n\t\t// Too short.\r\n\t\texpect(checkNumberLengthWithCountry('800555353', 'RU', 'FIXED_LINE')).to.equal('TOO_SHORT')\r\n\t\t// Normal.\r\n\t\texpect(checkNumberLengthWithCountry('8005553535', 'RU', 'FIXED_LINE')).to.equal('IS_POSSIBLE')\r\n\t\t// Too long.\r\n\t\texpect(checkNumberLengthWithCountry('80055535355', 'RU', 'FIXED_LINE')).to.equal('TOO_LONG')\r\n\r\n\t\t// No such type.\r\n\t\texpect(checkNumberLengthWithCountry('169454850', 'AC', 'VOIP')).to.equal('INVALID_LENGTH')\r\n\t\t// No such possible length.\r\n\t\texpect(checkNumberLengthWithCountry('1694548', 'AD', undefined)).to.equal('INVALID_LENGTH')\r\n\r\n\t\t// FIXED_LINE_OR_MOBILE\r\n\t\texpect(checkNumberLengthWithCountry('1694548', 'AD', 'FIXED_LINE_OR_MOBILE')).to.equal('INVALID_LENGTH')\r\n\t\t// No mobile phones.\r\n\t\texpect(checkNumberLengthWithCountry('8123', 'TA', 'FIXED_LINE_OR_MOBILE')).to.equal('IS_POSSIBLE')\r\n\t\t// No \"possible lengths\" for \"mobile\".\r\n\t\texpect(checkNumberLengthWithCountry('81234567', 'SZ', 'FIXED_LINE_OR_MOBILE')).to.equal('IS_POSSIBLE')\r\n\t})\r\n\r\n\tit('should check phone number length (`country` override)', () => {\r\n\t\tconst metadataInstance = new Metadata(metadata)\r\n\t\tmetadataInstance.selectNumberingPlan('US')\r\n\t\t// \"UAN\" phone number type doesn't exist in \"US\".\r\n\t\t// Hence, it returns \"INVALID_LENGTH\".\r\n\t\texpect(checkNumberLengthForType('2133734253', 'UAN', undefined, metadataInstance)).to.equal('INVALID_LENGTH')\r\n\t\texpect(checkNumberLengthForType('2133734253', 'UAN', 'CA', metadataInstance)).to.equal('TOO_LONG')\r\n\t\t// \"UAN\" phone number type doesn't exist in \"US\".\r\n\t\t// Hence, it returns \"INVALID_LENGTH\".\r\n\t\texpect(checkNumberLengthForType('2133734', 'UAN', undefined, metadataInstance)).to.equal('INVALID_LENGTH')\r\n\t\texpect(checkNumberLengthForType('2133734', 'UAN', 'CA', metadataInstance)).to.equal('IS_POSSIBLE')\r\n\t})\r\n\r\n\tit('should work for old metadata (`country` specified)', function() {\r\n\t\tconst oldMetadataInstance = new Metadata(oldMetadata)\r\n\t\toldMetadataInstance.selectNumberingPlan('KZ')\r\n\t\texpect(checkNumberLengthForType('8005553535', 'FIXED_LINE', 'RU', oldMetadataInstance)).to.equal('IS_POSSIBLE')\r\n\t})\r\n\r\n\tit('should work for old metadata (no `country` specified)', function() {\r\n\t\tconst oldMetadataInstance = new Metadata(oldMetadata)\r\n\t\toldMetadataInstance.selectNumberingPlan('RU')\r\n\t\texpect(checkNumberLengthForType('8005553535', 'FIXED_LINE', undefined, oldMetadataInstance)).to.equal('IS_POSSIBLE')\r\n\t})\r\n\r\n\tit('should handle the cases when multiple countries share the same country calling code and a phone number is possible in non-\"main\" country and is not possible in the \"main\" country', () => {\r\n\t\tconst metadataInstance = new Metadata(metadata)\r\n\t\tmetadataInstance.selectNumberingPlan('1')\r\n\t\texpect(checkNumberLength('3100000', undefined, metadataInstance)).to.equal('TOO_SHORT');\r\n\t\texpect(checkNumberLength('3100000', 'US', metadataInstance)).to.equal('TOO_SHORT');\r\n\t\texpect(checkNumberLength('3100000', 'CA', metadataInstance)).to.equal('IS_POSSIBLE');\r\n\t})\r\n})\r\n\r\nfunction checkNumberLengthWithCountry(number, country, type) {\r\n\tconst metadataInstance = new Metadata(metadata)\r\n\tmetadataInstance.selectNumberingPlan(country)\r\n\treturn checkNumberLengthForType(number, type, undefined, metadataInstance)\r\n}"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,EAAE,QAAQ,OAAO;AACpC,SAASC,MAAM,QAAQ,MAAM;AAE7B,OAAOC,QAAQ,IAAIC,qBAAqB,QAAQ,gBAAgB;AAChE,OAAOC,QAAQ,MAAM,yBAAyB,QAAQC,IAAI,EAAE,MAAM;AAClE,OAAOC,WAAW,MAAM,6CAA6C,QAAQD,IAAI,EAAE,MAAM;AAEzF,OAAOE,iBAAiB,IAAIC,wBAAwB,QAAQ,wBAAwB;AAEpFT,QAAQ,CAAC,mBAAmB,EAAE,MAAM;EACnCC,EAAE,CAAC,mFAAmF,EAAE,MAAM;IAC7F;IACAC,MAAM,CAACQ,4BAA4B,CAAC,WAAW,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC,CAACC,EAAE,CAACC,KAAK,CAAC,WAAW,CAAC;IAC3F;IACAV,MAAM,CAACQ,4BAA4B,CAAC,YAAY,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC,CAACC,EAAE,CAACC,KAAK,CAAC,aAAa,CAAC;IAC9F;IACAV,MAAM,CAACQ,4BAA4B,CAAC,aAAa,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC,CAACC,EAAE,CAACC,KAAK,CAAC,UAAU,CAAC;;IAE5F;IACAV,MAAM,CAACQ,4BAA4B,CAAC,WAAW,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAACC,EAAE,CAACC,KAAK,CAAC,gBAAgB,CAAC;IAC1F;IACAV,MAAM,CAACQ,4BAA4B,CAAC,SAAS,EAAE,IAAI,EAAEG,SAAS,CAAC,CAAC,CAACF,EAAE,CAACC,KAAK,CAAC,gBAAgB,CAAC;;IAE3F;IACAV,MAAM,CAACQ,4BAA4B,CAAC,SAAS,EAAE,IAAI,EAAE,sBAAsB,CA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,gBAAgB,CAAC;AAC3E","ignoreList":[]}
1
+ {"version":3,"file":"checkNumberLength.test.js","names":["describe","it","expect","Metadata","getCountryCallingCode","metadata","type","oldMetadata","checkNumberLength","checkNumberLengthForType","checkNumberLengthWithCountry","to","equal","undefined","metadataInstance","selectNumberingPlan","oldMetadataInstance","number","country"],"sources":["../../source/helpers/checkNumberLength.test.js"],"sourcesContent":["import { describe, it } from 'mocha'\r\nimport { expect } from 'chai'\r\n\r\nimport Metadata, { getCountryCallingCode } from '../metadata.js'\r\nimport metadata from '../../metadata.max.json' with { type: 'json' }\r\nimport oldMetadata from '../../test/metadata/1.0.0/metadata.min.json' with { type: 'json' }\r\n\r\nimport checkNumberLength, { checkNumberLengthForType } from './checkNumberLength.js'\r\n\r\ndescribe('checkNumberLength', () => {\r\n\tit('should check phone number length (`country` is pre-selected in metadata instance)', () => {\r\n\t\t// Too short.\r\n\t\texpect(checkNumberLengthWithCountry('800555353', 'RU', 'FIXED_LINE')).to.equal('TOO_SHORT')\r\n\t\t// Normal.\r\n\t\texpect(checkNumberLengthWithCountry('8005553535', 'RU', 'FIXED_LINE')).to.equal('IS_POSSIBLE')\r\n\t\t// Too long.\r\n\t\texpect(checkNumberLengthWithCountry('80055535355', 'RU', 'FIXED_LINE')).to.equal('TOO_LONG')\r\n\r\n\t\t// No such type.\r\n\t\texpect(checkNumberLengthWithCountry('169454850', 'AC', 'VOIP')).to.equal('INVALID_LENGTH')\r\n\t\t// No such possible length.\r\n\t\texpect(checkNumberLengthWithCountry('1694548', 'AD', undefined)).to.equal('INVALID_LENGTH')\r\n\r\n\t\t// FIXED_LINE_OR_MOBILE\r\n\t\texpect(checkNumberLengthWithCountry('1694548', 'AD', 'FIXED_LINE_OR_MOBILE')).to.equal('INVALID_LENGTH')\r\n\t\t// No mobile phones.\r\n\t\texpect(checkNumberLengthWithCountry('8123', 'TA', 'FIXED_LINE_OR_MOBILE')).to.equal('IS_POSSIBLE')\r\n\t\t// No \"possible lengths\" for \"mobile\".\r\n\t\texpect(checkNumberLengthWithCountry('81234567', 'SZ', 'FIXED_LINE_OR_MOBILE')).to.equal('IS_POSSIBLE')\r\n\t})\r\n\r\n\tit('should check phone number length (`country` override)', () => {\r\n\t\tconst metadataInstance = new Metadata(metadata)\r\n\t\tmetadataInstance.selectNumberingPlan('US')\r\n\r\n\t\t// The country code \"US\" will be overridden with \"CA\".\r\n\t\t//\r\n\t\t// How to find a suitable override for tests:\r\n\t\t//\r\n\t\t// for (const callingCode of Object.keys(metadata.country_calling_codes)) {\r\n\t\t// \tconst countries = metadata.country_calling_codes[callingCode]\r\n\t\t// \tif (countries.length > 1) {\r\n\t\t// \t\tconst mainCountry = countries.shift()\r\n\t\t// \t\tfor (const country of countries) {\r\n\t\t// \t\t\tif (JSON.stringify(metadata.countries[country].possible_lengths) !== JSON.stringify(metadata.countries[mainCountry].possible_lengths)) {\r\n\t\t// \t\t\t\tconsole.log(country, 'has different possible lengths from the default country', mainCountry)\r\n\t\t// \t\t\t}\r\n\t\t// \t\t}\r\n\t\t// \t}\r\n\t\t// }\r\n\r\n\t\t// \"UAN\" phone number type doesn't exist in \"US\".\r\n\t\t// Hence, it returns \"INVALID_LENGTH\".\r\n\t\texpect(checkNumberLengthForType('2133734253', 'UAN', undefined, metadataInstance)).to.equal('INVALID_LENGTH')\r\n\t\texpect(checkNumberLengthForType('2133734253', 'UAN', 'CA', metadataInstance)).to.equal('TOO_LONG')\r\n\t\t// \"UAN\" phone number type doesn't exist in \"US\".\r\n\t\t// Hence, it returns \"INVALID_LENGTH\".\r\n\t\texpect(checkNumberLengthForType('2133734', 'UAN', undefined, metadataInstance)).to.equal('INVALID_LENGTH')\r\n\t\texpect(checkNumberLengthForType('2133734', 'UAN', 'CA', metadataInstance)).to.equal('IS_POSSIBLE')\r\n\t})\r\n\r\n\tit('should work for old metadata (`country` specified)', function() {\r\n\t\tconst oldMetadataInstance = new Metadata(oldMetadata)\r\n\t\toldMetadataInstance.selectNumberingPlan('KZ')\r\n\t\texpect(checkNumberLengthForType('8005553535', 'FIXED_LINE', 'RU', oldMetadataInstance)).to.equal('IS_POSSIBLE')\r\n\t})\r\n\r\n\tit('should work for old metadata (no `country` specified)', function() {\r\n\t\tconst oldMetadataInstance = new Metadata(oldMetadata)\r\n\t\toldMetadataInstance.selectNumberingPlan('RU')\r\n\t\texpect(checkNumberLengthForType('8005553535', 'FIXED_LINE', undefined, oldMetadataInstance)).to.equal('IS_POSSIBLE')\r\n\t})\r\n\r\n\tit('should handle the cases when multiple countries share the same country calling code and a phone number is possible in non-\"main\" country and is not possible in the \"main\" country', () => {\r\n\t\tconst metadataInstance = new Metadata(metadata)\r\n\t\tmetadataInstance.selectNumberingPlan('1')\r\n\t\texpect(checkNumberLength('3100000', undefined, metadataInstance)).to.equal('TOO_SHORT');\r\n\t\texpect(checkNumberLength('3100000', 'US', metadataInstance)).to.equal('TOO_SHORT');\r\n\t\texpect(checkNumberLength('3100000', 'CA', metadataInstance)).to.equal('IS_POSSIBLE');\r\n\t})\r\n})\r\n\r\nfunction checkNumberLengthWithCountry(number, country, type) {\r\n\tconst metadataInstance = new Metadata(metadata)\r\n\tmetadataInstance.selectNumberingPlan(country)\r\n\treturn checkNumberLengthForType(number, type, undefined, metadataInstance)\r\n}"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,EAAE,QAAQ,OAAO;AACpC,SAASC,MAAM,QAAQ,MAAM;AAE7B,OAAOC,QAAQ,IAAIC,qBAAqB,QAAQ,gBAAgB;AAChE,OAAOC,QAAQ,MAAM,yBAAyB,QAAQC,IAAI,EAAE,MAAM;AAClE,OAAOC,WAAW,MAAM,6CAA6C,QAAQD,IAAI,EAAE,MAAM;AAEzF,OAAOE,iBAAiB,IAAIC,wBAAwB,QAAQ,wBAAwB;AAEpFT,QAAQ,CAAC,mBAAmB,EAAE,MAAM;EACnCC,EAAE,CAAC,mFAAmF,EAAE,MAAM;IAC7F;IACAC,MAAM,CAACQ,4BAA4B,CAAC,WAAW,EAAE,IAAI,EAA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AQ,CAACE,QAAQ,CAAC;IAC/CS,gBAAgB,CAACC,mBAAmB,CAAC,GAAG,CAAC;IACzCb,MAAM,CAACM,iBAAiB,CAAC,SAAS,EAAEK,SAAS,EAAEC,gBAAgB,CAAC,CAAC,CAACH,EAAE,CAACC,KAAK,CAAC,WAAW,CAAC;IACvFV,MAAM,CAACM,iBAAiB,CAAC,SAAS,EAAE,IAAI,EAAEM,gBAAgB,CAAC,CAAC,CAACH,EAAE,CAACC,KAAK,CAAC,WAAW,CAAC;IAClFV,MAAM,CAACM,iBAAiB,CAAC,SAAS,EAAE,IAAI,EAAEM,gBAAgB,CAAC,CAAC,CAACH,EAAE,CAACC,KAAK,CAAC,aAAa,CAAC;EACrF,CAAC,CAAC;AACH,CAAC,CAAC;AAEF,SAASF,4BAA4BA,CAACO,MAAM,EAAEC,OAAO,EAAEZ,IAAI,EAAE;EAC5D,MAAMQ,gBAAgB,GAAG,IAAIX,QAAQ,CAACE,QAAQ,CAAC;EAC/CS,gBAAgB,CAACC,mBAAmB,CAACG,OAAO,CAAC;EAC7C,OAAOT,wBAAwB,CAACQ,MAAM,EAAEX,IAAI,EAAEO,SAAS,EAAEC,gBAAgB,CAAC;AAC3E","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libphonenumber-js",
3
- "version": "1.13.4",
3
+ "version": "1.13.5",
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",
package/types.d.cts CHANGED
@@ -87,40 +87,11 @@ export type PhoneNumberType = 'PREMIUM_RATE' | 'TOLL_FREE' | 'SHARED_COST' | 'VO
87
87
  */
88
88
  export type NumberType = PhoneNumberType | undefined;
89
89
 
90
- // "Tagged" types are used to introduce some degree of type safety when passing in arguments to the functions.
91
- // https://medium.com/@ethanresnick/advanced-typescript-tagged-types-for-fewer-bugs-and-better-security-24db681d5721
92
- //
93
- // For example, if some function returns an `E164Number`, it can only be interpreted as
94
- // either a `string` or an `E164Number` and it can't mistakenly be interpreted as
95
- // a `NationalNumber` or an `Extension` or a `CarrierCode` or a `CountryCallingCode`.
96
- //
97
- // Example:
98
- //
99
- // import type { E164Number, CarrierCode } from 'libphonenumber-js'
100
- // const number: E164Number = '+78005553535'
101
- // const carrierCode: CarrierCode = number
102
- //
103
- // Shows an error:
104
- // Type 'E164Number' is not assignable to type 'CarrierCode'.
105
- //
106
- // Originally, the `__tag` property was declared optional in order to allow passing
107
- // a generic `string` in place of a `Tagged` type argument to functions that receive such arguments:
108
- // that would allow ingesting generic `string` values from an outside source such as a database.
109
- // Without that, those externally-obtained `string` values would have to be forcefully converted
110
- // to the `Tagged` type via TypeScript `as` operator which is an anti-pattern.
111
- //
112
- // Later, it has been decided to make the `__tag` property non-optional and instead
113
- // declare the arguments of those functions as `string | Tagged` rather than just `Tagged`:
114
- // that would still allow ingesting generic `string` values from an outside source
115
- // and would also make the `Tagged` type more "type safe".
116
- //
117
- type Tagged<A, T> = A & { __tag: T };
118
-
119
- export type E164Number = Tagged<string, "E164Number">;
120
- export type NationalNumber = Tagged<string, "NationalNumber">;
121
- export type Extension = Tagged<string, "Extension">;
122
- export type CarrierCode = Tagged<string, "CarrierCode">;
123
- export type CountryCallingCode = Tagged<string, "CountryCallingCode">;
90
+ export type E164Number = string;
91
+ export type NationalNumber = string;
92
+ export type Extension = string;
93
+ export type CarrierCode = string;
94
+ export type CountryCallingCode = string;
124
95
 
125
96
  type FormatExtension = (formattedNumber: string, extension: Extension, metadata: MetadataJson) => string
126
97
 
package/types.d.ts CHANGED
@@ -87,40 +87,11 @@ export type PhoneNumberType = 'PREMIUM_RATE' | 'TOLL_FREE' | 'SHARED_COST' | 'VO
87
87
  */
88
88
  export type NumberType = PhoneNumberType | undefined;
89
89
 
90
- // "Tagged" types are used to introduce some degree of type safety when passing in arguments to the functions.
91
- // https://medium.com/@ethanresnick/advanced-typescript-tagged-types-for-fewer-bugs-and-better-security-24db681d5721
92
- //
93
- // For example, if some function returns an `E164Number`, it can only be interpreted as
94
- // either a `string` or an `E164Number` and it can't mistakenly be interpreted as
95
- // a `NationalNumber` or an `Extension` or a `CarrierCode` or a `CountryCallingCode`.
96
- //
97
- // Example:
98
- //
99
- // import type { E164Number, CarrierCode } from 'libphonenumber-js'
100
- // const number: E164Number = '+78005553535'
101
- // const carrierCode: CarrierCode = number
102
- //
103
- // Shows an error:
104
- // Type 'E164Number' is not assignable to type 'CarrierCode'.
105
- //
106
- // Originally, the `__tag` property was declared optional in order to allow passing
107
- // a generic `string` in place of a `Tagged` type argument to functions that receive such arguments:
108
- // that would allow ingesting generic `string` values from an outside source such as a database.
109
- // Without that, those externally-obtained `string` values would have to be forcefully converted
110
- // to the `Tagged` type via TypeScript `as` operator which is an anti-pattern.
111
- //
112
- // Later, it has been decided to make the `__tag` property non-optional and instead
113
- // declare the arguments of those functions as `string | Tagged` rather than just `Tagged`:
114
- // that would still allow ingesting generic `string` values from an outside source
115
- // and would also make the `Tagged` type more "type safe".
116
- //
117
- type Tagged<A, T> = A & { __tag: T };
118
-
119
- export type E164Number = Tagged<string, "E164Number">;
120
- export type NationalNumber = Tagged<string, "NationalNumber">;
121
- export type Extension = Tagged<string, "Extension">;
122
- export type CarrierCode = Tagged<string, "CarrierCode">;
123
- export type CountryCallingCode = Tagged<string, "CountryCallingCode">;
90
+ export type E164Number = string;
91
+ export type NationalNumber = string;
92
+ export type Extension = string;
93
+ export type CarrierCode = string;
94
+ export type CountryCallingCode = string;
124
95
 
125
96
  type FormatExtension = (formattedNumber: string, extension: Extension, metadata: MetadataJson) => string
126
97