@clipboard-health/phone-number 2.9.3 → 2.10.0
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/README.md +10 -0
- package/package.json +4 -4
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/index.js.map +1 -1
- package/src/lib/randomPhoneNumber.d.ts +12 -0
- package/src/lib/randomPhoneNumber.js +160 -0
- package/src/lib/randomPhoneNumber.js.map +1 -0
package/README.md
CHANGED
|
@@ -16,6 +16,16 @@ npm install @clipboard-health/phone-number
|
|
|
16
16
|
|
|
17
17
|
## Usage
|
|
18
18
|
|
|
19
|
+
```typescript
|
|
20
|
+
import { randomPhoneNumber } from "@clipboard-health/phone-number";
|
|
21
|
+
|
|
22
|
+
const nationalPhoneNumber = randomPhoneNumber();
|
|
23
|
+
const internationalPhoneNumber = randomPhoneNumber({ international: true });
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
`randomPhoneNumber` produces valid-looking NANP numbers for synthetic identities. The numbers are
|
|
27
|
+
not reserved, so callers must suppress outbound routing.
|
|
28
|
+
|
|
19
29
|
## Local development commands
|
|
20
30
|
|
|
21
31
|
See [`package.json`](./package.json) `scripts` for a list of commands.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clipboard-health/phone-number",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.0",
|
|
4
4
|
"description": "Phone number utility functions.",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"bugs": "https://github.com/ClipboardHealth/core-utils/issues",
|
|
@@ -17,12 +17,12 @@
|
|
|
17
17
|
"access": "public"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@clipboard-health/util-ts": "5.14.
|
|
20
|
+
"@clipboard-health/util-ts": "5.14.1",
|
|
21
21
|
"tslib": "2.8.1"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@clipboard-health/testing-core": "2.9.
|
|
25
|
-
"libphonenumber-js": "1.13.
|
|
24
|
+
"@clipboard-health/testing-core": "2.9.4",
|
|
25
|
+
"libphonenumber-js": "1.13.10"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"libphonenumber-js": "^1.12"
|
package/src/index.d.ts
CHANGED
package/src/index.js
CHANGED
|
@@ -3,4 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./lib/formatPhoneNumber"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./lib/isValidPhoneNumber"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./lib/randomPhoneNumber"), exports);
|
|
6
7
|
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/phone-number/src/index.ts"],"names":[],"mappings":";;;AAAA,kEAAwC;AACxC,mEAAyC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/phone-number/src/index.ts"],"names":[],"mappings":";;;AAAA,kEAAwC;AACxC,mEAAyC;AACzC,kEAAwC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface RandomPhoneNumberOptions {
|
|
2
|
+
/** Whether to include the US country code in the number. */
|
|
3
|
+
international?: boolean;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Creates a random US phone number accepted by pinned libphonenumber-js metadata.
|
|
7
|
+
*
|
|
8
|
+
* The 126 area codes × 8,000,000 full-width subscriber numbers provide
|
|
9
|
+
* 1,008,000,000 possible values. These are not reserved NANP test numbers;
|
|
10
|
+
* callers creating synthetic identities must suppress outbound routing.
|
|
11
|
+
*/
|
|
12
|
+
export declare function randomPhoneNumber(options?: RandomPhoneNumberOptions): string;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.randomPhoneNumber = randomPhoneNumber;
|
|
4
|
+
const VALID_TEST_PHONE_AREA_CODES = [
|
|
5
|
+
"201",
|
|
6
|
+
"202",
|
|
7
|
+
"203",
|
|
8
|
+
"205",
|
|
9
|
+
"206",
|
|
10
|
+
"207",
|
|
11
|
+
"208",
|
|
12
|
+
"209",
|
|
13
|
+
"210",
|
|
14
|
+
"212",
|
|
15
|
+
"213",
|
|
16
|
+
"214",
|
|
17
|
+
"215",
|
|
18
|
+
"216",
|
|
19
|
+
"217",
|
|
20
|
+
"218",
|
|
21
|
+
"219",
|
|
22
|
+
"220",
|
|
23
|
+
"223",
|
|
24
|
+
"224",
|
|
25
|
+
"225",
|
|
26
|
+
"227",
|
|
27
|
+
"228",
|
|
28
|
+
"229",
|
|
29
|
+
"231",
|
|
30
|
+
"234",
|
|
31
|
+
"235",
|
|
32
|
+
"239",
|
|
33
|
+
"240",
|
|
34
|
+
"248",
|
|
35
|
+
"251",
|
|
36
|
+
"252",
|
|
37
|
+
"253",
|
|
38
|
+
"254",
|
|
39
|
+
"256",
|
|
40
|
+
"260",
|
|
41
|
+
"262",
|
|
42
|
+
"267",
|
|
43
|
+
"269",
|
|
44
|
+
"270",
|
|
45
|
+
"272",
|
|
46
|
+
"276",
|
|
47
|
+
"279",
|
|
48
|
+
"281",
|
|
49
|
+
"283",
|
|
50
|
+
"301",
|
|
51
|
+
"302",
|
|
52
|
+
"303",
|
|
53
|
+
"304",
|
|
54
|
+
"305",
|
|
55
|
+
"307",
|
|
56
|
+
"308",
|
|
57
|
+
"309",
|
|
58
|
+
"310",
|
|
59
|
+
"312",
|
|
60
|
+
"313",
|
|
61
|
+
"314",
|
|
62
|
+
"315",
|
|
63
|
+
"316",
|
|
64
|
+
"317",
|
|
65
|
+
"318",
|
|
66
|
+
"319",
|
|
67
|
+
"320",
|
|
68
|
+
"321",
|
|
69
|
+
"323",
|
|
70
|
+
"324",
|
|
71
|
+
"325",
|
|
72
|
+
"326",
|
|
73
|
+
"327",
|
|
74
|
+
"329",
|
|
75
|
+
"330",
|
|
76
|
+
"331",
|
|
77
|
+
"332",
|
|
78
|
+
"334",
|
|
79
|
+
"336",
|
|
80
|
+
"337",
|
|
81
|
+
"339",
|
|
82
|
+
"341",
|
|
83
|
+
"346",
|
|
84
|
+
"347",
|
|
85
|
+
"350",
|
|
86
|
+
"351",
|
|
87
|
+
"352",
|
|
88
|
+
"353",
|
|
89
|
+
"360",
|
|
90
|
+
"361",
|
|
91
|
+
"363",
|
|
92
|
+
"364",
|
|
93
|
+
"369",
|
|
94
|
+
"380",
|
|
95
|
+
"385",
|
|
96
|
+
"386",
|
|
97
|
+
"401",
|
|
98
|
+
"402",
|
|
99
|
+
"404",
|
|
100
|
+
"405",
|
|
101
|
+
"406",
|
|
102
|
+
"407",
|
|
103
|
+
"408",
|
|
104
|
+
"409",
|
|
105
|
+
"410",
|
|
106
|
+
"412",
|
|
107
|
+
"413",
|
|
108
|
+
"414",
|
|
109
|
+
"415",
|
|
110
|
+
"417",
|
|
111
|
+
"419",
|
|
112
|
+
"423",
|
|
113
|
+
"424",
|
|
114
|
+
"425",
|
|
115
|
+
"430",
|
|
116
|
+
"432",
|
|
117
|
+
"434",
|
|
118
|
+
"435",
|
|
119
|
+
"440",
|
|
120
|
+
"442",
|
|
121
|
+
"443",
|
|
122
|
+
"445",
|
|
123
|
+
"447",
|
|
124
|
+
"448",
|
|
125
|
+
"458",
|
|
126
|
+
"463",
|
|
127
|
+
"464",
|
|
128
|
+
"469",
|
|
129
|
+
"470",
|
|
130
|
+
"475",
|
|
131
|
+
];
|
|
132
|
+
const MINIMUM_SUBSCRIBER_NUMBER = 2_000_000;
|
|
133
|
+
const MAXIMUM_SUBSCRIBER_NUMBER = 9_999_999;
|
|
134
|
+
/**
|
|
135
|
+
* Creates a random US phone number accepted by pinned libphonenumber-js metadata.
|
|
136
|
+
*
|
|
137
|
+
* The 126 area codes × 8,000,000 full-width subscriber numbers provide
|
|
138
|
+
* 1,008,000,000 possible values. These are not reserved NANP test numbers;
|
|
139
|
+
* callers creating synthetic identities must suppress outbound routing.
|
|
140
|
+
*/
|
|
141
|
+
function randomPhoneNumber(options = {}) {
|
|
142
|
+
const { international = false } = options;
|
|
143
|
+
const prefix = international ? "+1" : "";
|
|
144
|
+
const areaCode = randomAreaCode();
|
|
145
|
+
const subscriberNumber = randomInteger({
|
|
146
|
+
minimum: MINIMUM_SUBSCRIBER_NUMBER,
|
|
147
|
+
maximum: MAXIMUM_SUBSCRIBER_NUMBER,
|
|
148
|
+
});
|
|
149
|
+
return `${prefix}${areaCode}${subscriberNumber}`;
|
|
150
|
+
}
|
|
151
|
+
function randomInteger({ minimum, maximum }) {
|
|
152
|
+
const minimumInteger = Math.ceil(minimum);
|
|
153
|
+
const maximumInteger = Math.floor(maximum);
|
|
154
|
+
return Math.floor(Math.random() * (maximumInteger - minimumInteger + 1)) + minimumInteger;
|
|
155
|
+
}
|
|
156
|
+
function randomAreaCode() {
|
|
157
|
+
const index = randomInteger({ minimum: 0, maximum: VALID_TEST_PHONE_AREA_CODES.length - 1 });
|
|
158
|
+
return VALID_TEST_PHONE_AREA_CODES.slice(index, index + 1).join("");
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=randomPhoneNumber.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"randomPhoneNumber.js","sourceRoot":"","sources":["../../../../../packages/phone-number/src/lib/randomPhoneNumber.ts"],"names":[],"mappings":";;;AAKA,MAAM,2BAA2B,GAAG;IAClC,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;CACG,CAAC;AAEX,MAAM,yBAAyB,GAAG,SAAS,CAAC;AAC5C,MAAM,yBAAyB,GAAG,SAAS,CAAC;AA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