@yext/phonenumber-util 0.2.2 → 0.2.4
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/.husky/pre-commit +1 -1
- package/README.md +12 -1
- package/package.json +8 -8
- package/src/areaCodeList.js +7 -0
- package/src/compliance.js +2 -0
- package/src/phoneCodes.js +4 -2
- package/src/phoneFormats.js +2 -0
- package/src/timezones.js +3 -0
package/.husky/pre-commit
CHANGED
package/README.md
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
Utility for extracting and validating phone numbers. Extracts an array of phone numbers from an inputted string, validates that these numbers appear genuine and provide data about those phone numbers.
|
|
2
2
|
|
|
3
|
-
[](https://opensource.org/licenses/BSD-3-Clause)
|
|
3
|
+
[](https://opensource.org/licenses/BSD-3-Clause)
|
|
4
|
+
[](https://www.npmjs.com/package/@yext/phonenumber-util)
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+

|
|
4
9
|
|
|
5
10
|
### Scripts
|
|
6
11
|
|
|
@@ -38,6 +43,12 @@ npx vitest run --coverage
|
|
|
38
43
|
|
|
39
44
|
The returned object will include a `rawNumber` value. This value is the return of the exact value passed to the function. No sanitization occurs with this value. If you reference this number, ensure you sanitize it _BEFORE_ passing to this function.
|
|
40
45
|
|
|
46
|
+
### Install
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npm i @yext/phonenumber-util --save
|
|
50
|
+
```
|
|
51
|
+
|
|
41
52
|
### Usage
|
|
42
53
|
|
|
43
54
|
There is additional functionality exposed as `export`, but the primary expected use case is:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yext/phonenumber-util",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"author": "bajohnson@hearsaycorp.com",
|
|
5
5
|
"license": "BSD-3-Clause",
|
|
6
6
|
"description": "Utility for extracting and validating phone numbers",
|
|
@@ -26,14 +26,14 @@
|
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@eslint/js": "^9.7.0",
|
|
29
|
-
"@vitest/coverage-v8": "^2.1.
|
|
30
|
-
"eslint": "^9.
|
|
31
|
-
"generate-license-file": "^3.
|
|
32
|
-
"globals": "^15.
|
|
33
|
-
"husky": "^9.1.
|
|
29
|
+
"@vitest/coverage-v8": "^2.1.8",
|
|
30
|
+
"eslint": "^9.17.0",
|
|
31
|
+
"generate-license-file": "^3.6.0",
|
|
32
|
+
"globals": "^15.14.0",
|
|
33
|
+
"husky": "^9.1.7",
|
|
34
34
|
"istanbul-badges-readme": "^1.9.0",
|
|
35
|
-
"lint-staged": "^15.2.
|
|
36
|
-
"prettier": "^3.
|
|
35
|
+
"lint-staged": "^15.2.11",
|
|
36
|
+
"prettier": "^3.4.2",
|
|
37
37
|
"vitest": "^2.1.1"
|
|
38
38
|
},
|
|
39
39
|
"eslintConfig": {},
|
package/src/areaCodeList.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
// The AREA_CODE_LIST is used in validation of NANP phone numbers. If a number is passed to `isValidPhoneNumber` that is not found in this array, `false` will be returned.
|
|
2
|
+
// If a new area code is added to this array, it must also be added to the AREA_CODES object in phoneCodes.js.
|
|
3
|
+
// If a new area code is added and covers a region that has multiple timezones, it will need to be added to the STATES_WITH_MULTIPLE_TIMEZONES object in timezones.js.
|
|
4
|
+
// If a new area code is added and covers a region that has portions that do and portions that do not adhere to daylight savings time, it will need to be added to the AREA_CODES_WITH_MULTIPLE_DAYLIGHT_SAVINGS object in daylightSavings.js.
|
|
1
5
|
export const AREA_CODE_LIST = [
|
|
2
6
|
'201',
|
|
3
7
|
'202',
|
|
@@ -22,6 +26,7 @@ export const AREA_CODE_LIST = [
|
|
|
22
26
|
'224',
|
|
23
27
|
'225',
|
|
24
28
|
'226',
|
|
29
|
+
'227',
|
|
25
30
|
'257',
|
|
26
31
|
'228',
|
|
27
32
|
'229',
|
|
@@ -50,6 +55,7 @@ export const AREA_CODE_LIST = [
|
|
|
50
55
|
'276',
|
|
51
56
|
'279',
|
|
52
57
|
'281',
|
|
58
|
+
'283',
|
|
53
59
|
'284',
|
|
54
60
|
'289',
|
|
55
61
|
'301',
|
|
@@ -347,6 +353,7 @@ export const AREA_CODE_LIST = [
|
|
|
347
353
|
'839',
|
|
348
354
|
'840',
|
|
349
355
|
'843',
|
|
356
|
+
'844',
|
|
350
357
|
'845',
|
|
351
358
|
'847',
|
|
352
359
|
'848',
|
package/src/compliance.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// Compliance settings are used to define quiet hours for the US (using TCPA) and Canada (using CRTC).
|
|
1
2
|
export const TCPA_QUIET_HOURS = {
|
|
2
3
|
start: 8,
|
|
3
4
|
end: 21,
|
|
@@ -14,6 +15,7 @@ export const CRTC_QUIET_HOURS = {
|
|
|
14
15
|
},
|
|
15
16
|
};
|
|
16
17
|
|
|
18
|
+
// The strings of CRTC_STATES must match the `name` field found within AREA_CODES object in phoneCodes.js.
|
|
17
19
|
export const CRTC_STATES = [
|
|
18
20
|
'Alberta',
|
|
19
21
|
'British Columbia',
|
package/src/phoneCodes.js
CHANGED
|
@@ -6,6 +6,7 @@ export const AREA_CODES = {
|
|
|
6
6
|
// Toll Free / Not Geographic
|
|
7
7
|
800: { name: 'Toll-free', region: { name: 'United States', code: 'US' } },
|
|
8
8
|
833: { name: 'Toll-free', region: { name: 'United States', code: 'US' } },
|
|
9
|
+
844: { name: 'Toll-free', region: { name: 'United States', code: 'US' } },
|
|
9
10
|
888: { name: 'Toll-free', region: { name: 'United States', code: 'US' } },
|
|
10
11
|
877: { name: 'Toll-free', region: { name: 'United States', code: 'US' } },
|
|
11
12
|
866: { name: 'Toll-free', region: { name: 'United States', code: 'US' } },
|
|
@@ -156,6 +157,7 @@ export const AREA_CODES = {
|
|
|
156
157
|
504: { name: 'Louisiana', code: 'LA', region: UNITED_STATES },
|
|
157
158
|
985: { name: 'Louisiana', code: 'LA', region: UNITED_STATES },
|
|
158
159
|
207: { name: 'Maine', code: 'ME', region: UNITED_STATES },
|
|
160
|
+
227: { name: 'Maryland', code: 'MD', region: UNITED_STATES },
|
|
159
161
|
240: { name: 'Maryland', code: 'MD', region: UNITED_STATES },
|
|
160
162
|
301: { name: 'Maryland', code: 'MD', region: UNITED_STATES },
|
|
161
163
|
410: { name: 'Maryland', code: 'MD', region: UNITED_STATES },
|
|
@@ -256,6 +258,7 @@ export const AREA_CODES = {
|
|
|
256
258
|
216: { name: 'Ohio', code: 'OH', region: UNITED_STATES },
|
|
257
259
|
220: { name: 'Ohio', code: 'OH', region: UNITED_STATES },
|
|
258
260
|
234: { name: 'Ohio', code: 'OH', region: UNITED_STATES },
|
|
261
|
+
283: { name: 'Ohio', code: 'OH', region: UNITED_STATES },
|
|
259
262
|
326: { name: 'Ohio', code: 'OH', region: UNITED_STATES },
|
|
260
263
|
330: { name: 'Ohio', code: 'OH', region: UNITED_STATES },
|
|
261
264
|
380: { name: 'Ohio', code: 'OH', region: UNITED_STATES },
|
|
@@ -421,7 +424,6 @@ export const AREA_CODES = {
|
|
|
421
424
|
region: CANADA,
|
|
422
425
|
},
|
|
423
426
|
// Other North American Numbering Plan (NANP) Numbers
|
|
424
|
-
// These will return "United States, Canada" as the region, which is incorrect, but they follow the same standard.
|
|
425
427
|
684: { region: { name: 'American Samoa', code: 'AS', flag: '🇦🇸' } },
|
|
426
428
|
264: { region: { name: 'Anguilla', code: 'AI', flag: '🇦🇮' } },
|
|
427
429
|
268: { region: { name: 'Antigua and Barbuda', code: 'AG', flag: '🇦🇬' } },
|
|
@@ -492,7 +494,7 @@ export const REGION_CODES = {
|
|
|
492
494
|
235: { name: 'Chad', code: 'TD', flag: '🇹🇩' },
|
|
493
495
|
56: { name: 'Chile', code: 'CL', flag: '🇨🇱' },
|
|
494
496
|
86: { name: 'China', code: 'CN', flag: '🇨🇳' },
|
|
495
|
-
61: { name: '
|
|
497
|
+
61: { name: 'Australia', code: 'AU', flag: '🇦🇺' },
|
|
496
498
|
57: { name: 'Colombia', code: 'CO', flag: '🇨🇴' },
|
|
497
499
|
269: { name: 'Comoros', code: 'KM', flag: '🇰🇲' },
|
|
498
500
|
682: { name: 'Cook Islands', code: 'CK', flag: '🇨🇰' },
|
package/src/phoneFormats.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// For each region, provide a pretty format. Some regions may have multiple formats, in which case an array can be used. Each "x" will be replaced with a digit when the number of digits matches the number of "x"s in the format.
|
|
2
|
+
// If no format is found with a correct matching length, a sanitized e164 is returned as a fall-back.
|
|
1
3
|
export const PHONE_FORMATS = {
|
|
2
4
|
1: '(xxx) xxx-xxxx', // United States
|
|
3
5
|
7: '+x xxx xxx-xx-xx', // Russia
|
package/src/timezones.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// Default timezone for each state, region or province.
|
|
2
|
+
// While some region may have multiple timezones, we set the most common one here as a default. See STATES_WITH_MULTIPLE_TIMEZONES below for references to exceptions within these regions.
|
|
3
|
+
// Time calculations are only provided for US and Canada.
|
|
1
4
|
export const STATE_TIMEZONES = {
|
|
2
5
|
Alabama: '-06:00',
|
|
3
6
|
Alaska: '-09:00',
|