@askeleven/sms-guard 0.1.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/LICENSE +21 -0
- package/README.md +267 -0
- package/bin/cli.js +212 -0
- package/package.json +59 -0
- package/src/data/countries.js +78 -0
- package/src/data/gsm.js +53 -0
- package/src/data/nanp.js +271 -0
- package/src/data/shorteners.js +10 -0
- package/src/index.js +420 -0
- package/src/mcp.js +289 -0
- package/src/phone.js +213 -0
- package/src/report.js +165 -0
- package/src/segments.js +139 -0
- package/src/split.js +127 -0
- package/src/version.js +6 -0
- package/types/data/countries.d.ts +2 -0
- package/types/data/gsm.d.ts +17 -0
- package/types/data/nanp.d.ts +17 -0
- package/types/data/shorteners.d.ts +5 -0
- package/types/index.d.ts +240 -0
- package/types/mcp.d.ts +23 -0
- package/types/phone.d.ts +121 -0
- package/types/report.d.ts +22 -0
- package/types/segments.d.ts +115 -0
- package/types/split.d.ts +46 -0
- package/types/version.d.ts +2 -0
package/src/data/gsm.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The GSM 03.38 default alphabet (3GPP TS 23.038), in code order, without the escape
|
|
3
|
+
* at 0x1B. Non-ASCII characters are written as escapes so no lookalike can creep in.
|
|
4
|
+
* Note that it is not ASCII: 0x24 is the currency sign, and the backtick is missing.
|
|
5
|
+
*/
|
|
6
|
+
export const GSM_BASIC = new Set(
|
|
7
|
+
[
|
|
8
|
+
// 0x00
|
|
9
|
+
'@\u00A3$\u00A5\u00E8\u00E9\u00F9\u00EC\u00F2\u00C7\n\u00D8\u00F8\r\u00C5\u00E5',
|
|
10
|
+
// 0x10, escape at 0x1B left out
|
|
11
|
+
'\u0394_\u03A6\u0393\u039B\u03A9\u03A0\u03A8\u03A3\u0398\u039E\u00C6\u00E6\u00DF\u00C9',
|
|
12
|
+
// 0x20
|
|
13
|
+
' !"#\u00A4%&\'()*+,-./0123456789:;<=>?',
|
|
14
|
+
// 0x40
|
|
15
|
+
'\u00A1ABCDEFGHIJKLMNOPQRSTUVWXYZ\u00C4\u00D6\u00D1\u00DC\u00A7',
|
|
16
|
+
// 0x60
|
|
17
|
+
'\u00BFabcdefghijklmnopqrstuvwxyz\u00E4\u00F6\u00F1\u00FC\u00E0',
|
|
18
|
+
].join(''),
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The extension table: each is sent as the escape plus one septet, so it costs two.
|
|
23
|
+
*/
|
|
24
|
+
export const GSM_EXTENSION = new Set(['\f', '^', '{', '}', '\\', '[', '~', ']', '|', '\u20AC'])
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Typographic characters with a GSM-7 equivalent that reads the same. Only these are
|
|
28
|
+
* ever offered as replacements. Accented letters are real text and are left alone.
|
|
29
|
+
*
|
|
30
|
+
* @type {Map<string, string>}
|
|
31
|
+
*/
|
|
32
|
+
export const GSM_REPLACEMENTS = new Map([
|
|
33
|
+
// Single quotes and primes
|
|
34
|
+
['\u2018', "'"], ['\u2019', "'"], ['\u201A', "'"], ['\u201B', "'"], ['\u2032', "'"],
|
|
35
|
+
['\u2039', "'"], ['\u203A', "'"],
|
|
36
|
+
// Double quotes, guillemets
|
|
37
|
+
['\u201C', '"'], ['\u201D', '"'], ['\u201E', '"'], ['\u201F', '"'], ['\u2033', '"'],
|
|
38
|
+
['\u00AB', '"'], ['\u00BB', '"'],
|
|
39
|
+
// Dashes and the minus sign
|
|
40
|
+
['\u2010', '-'], ['\u2011', '-'], ['\u2012', '-'], ['\u2013', '-'], ['\u2014', '-'],
|
|
41
|
+
['\u2015', '-'], ['\u2212', '-'],
|
|
42
|
+
// Ellipsis
|
|
43
|
+
['\u2026', '...'],
|
|
44
|
+
// Bullets
|
|
45
|
+
['\u2022', '-'], ['\u2023', '-'], ['\u2043', '-'],
|
|
46
|
+
// Tab, no-break and other spaces
|
|
47
|
+
['\t', ' '], ['\u00A0', ' '], ['\u2000', ' '], ['\u2001', ' '], ['\u2002', ' '],
|
|
48
|
+
['\u2003', ' '], ['\u2004', ' '], ['\u2005', ' '], ['\u2006', ' '], ['\u2007', ' '],
|
|
49
|
+
['\u2008', ' '], ['\u2009', ' '], ['\u200A', ' '], ['\u202F', ' '], ['\u205F', ' '],
|
|
50
|
+
['\u3000', ' '],
|
|
51
|
+
// Invisible: zero-width space, word joiner, byte order mark
|
|
52
|
+
['\u200B', ''], ['\u2060', ''], ['\uFEFF', ''],
|
|
53
|
+
])
|
package/src/data/nanp.js
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Geographic NANP area codes for the US, its territories, Canada, and the Caribbean
|
|
3
|
+
* countries on +1, mapped to IANA time zones.
|
|
4
|
+
*
|
|
5
|
+
* An area code whose territory crosses a time zone line lists every zone it covers,
|
|
6
|
+
* and sms-guard reports it as ambiguous instead of picking one. Zones follow the
|
|
7
|
+
* official boundaries, not local habit (a town that unofficially keeps its
|
|
8
|
+
* neighbour's time is not listed separately). Where we were not sure an area code
|
|
9
|
+
* stays inside one zone, it is listed as ambiguous: a question to a person is cheaper
|
|
10
|
+
* than a text at the wrong hour.
|
|
11
|
+
*
|
|
12
|
+
* Non-geographic codes (toll-free 8XX, 500, 600, 700, 900) are left out on purpose:
|
|
13
|
+
* they say nothing about where the phone is.
|
|
14
|
+
*
|
|
15
|
+
* Each row is [region, zone or zones, area codes].
|
|
16
|
+
*
|
|
17
|
+
* @type {Array<[string, string | string[], string[]]>}
|
|
18
|
+
*/
|
|
19
|
+
const ROWS = [
|
|
20
|
+
// United States
|
|
21
|
+
['Alabama', 'America/Chicago', ['205', '251', '256', '334', '659', '938']],
|
|
22
|
+
// The Aleutians west of 169.5W keep Hawaii-Aleutian time.
|
|
23
|
+
['Alaska', ['America/Anchorage', 'America/Adak'], ['907']],
|
|
24
|
+
['Arizona', 'America/Phoenix', ['480', '520', '602', '623']],
|
|
25
|
+
// Northern Arizona includes the Navajo Nation, which observes daylight saving time.
|
|
26
|
+
['Arizona', ['America/Phoenix', 'America/Denver'], ['928']],
|
|
27
|
+
['Arkansas', 'America/Chicago', ['327', '479', '501', '870']],
|
|
28
|
+
[
|
|
29
|
+
'California',
|
|
30
|
+
'America/Los_Angeles',
|
|
31
|
+
[
|
|
32
|
+
'209', '213', '279', '310', '323', '341', '350', '369', '408', '415', '424',
|
|
33
|
+
'442', '510', '530', '559', '562', '619', '626', '628', '650', '657', '661',
|
|
34
|
+
'669', '707', '714', '747', '760', '805', '818', '820', '831', '840', '858',
|
|
35
|
+
'909', '916', '925', '949', '951',
|
|
36
|
+
],
|
|
37
|
+
],
|
|
38
|
+
['Colorado', 'America/Denver', ['303', '719', '720', '970', '983']],
|
|
39
|
+
['Connecticut', 'America/New_York', ['203', '475', '860', '959']],
|
|
40
|
+
['Delaware', 'America/New_York', ['302']],
|
|
41
|
+
['District of Columbia', 'America/New_York', ['202', '771']],
|
|
42
|
+
[
|
|
43
|
+
'Florida',
|
|
44
|
+
'America/New_York',
|
|
45
|
+
[
|
|
46
|
+
'239', '305', '321', '324', '352', '386', '407', '561', '645', '656', '689',
|
|
47
|
+
'727', '754', '772', '786', '813', '863', '904', '941', '954',
|
|
48
|
+
],
|
|
49
|
+
],
|
|
50
|
+
// The panhandle west of the Apalachicola River is Central.
|
|
51
|
+
['Florida', ['America/New_York', 'America/Chicago'], ['448', '850']],
|
|
52
|
+
[
|
|
53
|
+
'Georgia',
|
|
54
|
+
'America/New_York',
|
|
55
|
+
['229', '404', '470', '478', '678', '706', '762', '770', '912'],
|
|
56
|
+
],
|
|
57
|
+
['Hawaii', 'Pacific/Honolulu', ['808']],
|
|
58
|
+
// The panhandle is Pacific, the south is Mountain.
|
|
59
|
+
['Idaho', ['America/Boise', 'America/Los_Angeles'], ['208', '986']],
|
|
60
|
+
[
|
|
61
|
+
'Illinois',
|
|
62
|
+
'America/Chicago',
|
|
63
|
+
[
|
|
64
|
+
'217', '224', '309', '312', '331', '447', '464', '618', '630', '708', '730',
|
|
65
|
+
'773', '779', '815', '847', '872',
|
|
66
|
+
],
|
|
67
|
+
],
|
|
68
|
+
['Indiana', 'America/Indiana/Indianapolis', ['260', '317', '463', '765']],
|
|
69
|
+
// Northwest and southwest Indiana are Central; the rest is Eastern.
|
|
70
|
+
[
|
|
71
|
+
'Indiana',
|
|
72
|
+
['America/Chicago', 'America/Indiana/Indianapolis'],
|
|
73
|
+
['219', '574', '812', '930'],
|
|
74
|
+
],
|
|
75
|
+
['Iowa', 'America/Chicago', ['319', '515', '563', '641', '712']],
|
|
76
|
+
['Kansas', 'America/Chicago', ['316', '913']],
|
|
77
|
+
// Four western counties are Mountain.
|
|
78
|
+
['Kansas', ['America/Chicago', 'America/Denver'], ['620', '785']],
|
|
79
|
+
['Kentucky', 'America/Kentucky/Louisville', ['502', '859']],
|
|
80
|
+
['Kentucky', ['America/Kentucky/Louisville', 'America/Chicago'], ['270', '364', '606']],
|
|
81
|
+
['Louisiana', 'America/Chicago', ['225', '318', '337', '504', '985']],
|
|
82
|
+
['Maine', 'America/New_York', ['207']],
|
|
83
|
+
['Maryland', 'America/New_York', ['227', '240', '301', '410', '443', '667']],
|
|
84
|
+
[
|
|
85
|
+
'Massachusetts',
|
|
86
|
+
'America/New_York',
|
|
87
|
+
['339', '351', '413', '508', '617', '774', '781', '857', '978'],
|
|
88
|
+
],
|
|
89
|
+
[
|
|
90
|
+
'Michigan',
|
|
91
|
+
'America/Detroit',
|
|
92
|
+
[
|
|
93
|
+
'231', '248', '269', '313', '517', '586', '616', '679', '734', '810', '947',
|
|
94
|
+
'989',
|
|
95
|
+
],
|
|
96
|
+
],
|
|
97
|
+
// Four Upper Peninsula counties on the Wisconsin border are Central.
|
|
98
|
+
['Michigan', ['America/Detroit', 'America/Menominee'], ['906']],
|
|
99
|
+
['Minnesota', 'America/Chicago', ['218', '320', '507', '612', '651', '763', '952']],
|
|
100
|
+
['Mississippi', 'America/Chicago', ['228', '601', '662', '769']],
|
|
101
|
+
[
|
|
102
|
+
'Missouri',
|
|
103
|
+
'America/Chicago',
|
|
104
|
+
['314', '417', '557', '573', '636', '660', '816', '975'],
|
|
105
|
+
],
|
|
106
|
+
['Montana', 'America/Denver', ['406']],
|
|
107
|
+
['Nebraska', 'America/Chicago', ['402', '531']],
|
|
108
|
+
['Nebraska', ['America/Chicago', 'America/Denver'], ['308']],
|
|
109
|
+
['Nevada', 'America/Los_Angeles', ['702', '725']],
|
|
110
|
+
// West Wendover is officially Mountain.
|
|
111
|
+
['Nevada', ['America/Los_Angeles', 'America/Denver'], ['775']],
|
|
112
|
+
['New Hampshire', 'America/New_York', ['603']],
|
|
113
|
+
[
|
|
114
|
+
'New Jersey',
|
|
115
|
+
'America/New_York',
|
|
116
|
+
['201', '551', '609', '640', '732', '848', '856', '862', '908', '973'],
|
|
117
|
+
],
|
|
118
|
+
['New Mexico', 'America/Denver', ['505', '575']],
|
|
119
|
+
[
|
|
120
|
+
'New York',
|
|
121
|
+
'America/New_York',
|
|
122
|
+
[
|
|
123
|
+
'212', '315', '329', '332', '347', '363', '516', '518', '585', '607', '624',
|
|
124
|
+
'631', '646', '680', '716', '718', '838', '845', '914', '917', '929', '934',
|
|
125
|
+
],
|
|
126
|
+
],
|
|
127
|
+
[
|
|
128
|
+
'North Carolina',
|
|
129
|
+
'America/New_York',
|
|
130
|
+
['252', '336', '472', '704', '743', '828', '910', '919', '980', '984'],
|
|
131
|
+
],
|
|
132
|
+
// The southwest is Mountain.
|
|
133
|
+
['North Dakota', ['America/Chicago', 'America/Denver'], ['701']],
|
|
134
|
+
[
|
|
135
|
+
'Ohio',
|
|
136
|
+
'America/New_York',
|
|
137
|
+
[
|
|
138
|
+
'216', '220', '234', '283', '326', '330', '380', '419', '436', '440', '513',
|
|
139
|
+
'567', '614', '740', '937',
|
|
140
|
+
],
|
|
141
|
+
],
|
|
142
|
+
['Oklahoma', 'America/Chicago', ['405', '539', '572', '580', '918']],
|
|
143
|
+
['Oregon', 'America/Los_Angeles', ['503', '971']],
|
|
144
|
+
// Most of Malheur County is Mountain.
|
|
145
|
+
['Oregon', ['America/Los_Angeles', 'America/Boise'], ['458', '541']],
|
|
146
|
+
[
|
|
147
|
+
'Pennsylvania',
|
|
148
|
+
'America/New_York',
|
|
149
|
+
[
|
|
150
|
+
'215', '223', '267', '272', '412', '445', '484', '570', '582', '610', '717',
|
|
151
|
+
'724', '814', '835', '878',
|
|
152
|
+
],
|
|
153
|
+
],
|
|
154
|
+
['Rhode Island', 'America/New_York', ['401']],
|
|
155
|
+
['South Carolina', 'America/New_York', ['803', '821', '839', '843', '854', '864']],
|
|
156
|
+
// East river is Central, west river is Mountain.
|
|
157
|
+
['South Dakota', ['America/Chicago', 'America/Denver'], ['605']],
|
|
158
|
+
['Tennessee', 'America/Chicago', ['615', '629', '731', '901']],
|
|
159
|
+
['Tennessee', 'America/New_York', ['865']],
|
|
160
|
+
// Both cover counties close to the Eastern/Central line.
|
|
161
|
+
['Tennessee', ['America/New_York', 'America/Chicago'], ['423', '931']],
|
|
162
|
+
[
|
|
163
|
+
'Texas',
|
|
164
|
+
'America/Chicago',
|
|
165
|
+
[
|
|
166
|
+
'210', '214', '254', '281', '325', '346', '361', '409', '430', '432', '469',
|
|
167
|
+
'512', '682', '713', '726', '737', '806', '817', '830', '832', '903', '936',
|
|
168
|
+
'940', '945', '956', '972', '979',
|
|
169
|
+
],
|
|
170
|
+
],
|
|
171
|
+
// El Paso and Hudspeth counties.
|
|
172
|
+
['Texas', 'America/Denver', ['915']],
|
|
173
|
+
['Utah', 'America/Denver', ['385', '435', '801']],
|
|
174
|
+
['Vermont', 'America/New_York', ['802']],
|
|
175
|
+
[
|
|
176
|
+
'Virginia',
|
|
177
|
+
'America/New_York',
|
|
178
|
+
['276', '434', '540', '571', '686', '703', '757', '804', '826', '948'],
|
|
179
|
+
],
|
|
180
|
+
['Washington', 'America/Los_Angeles', ['206', '253', '360', '425', '509', '564']],
|
|
181
|
+
['West Virginia', 'America/New_York', ['304', '681']],
|
|
182
|
+
[
|
|
183
|
+
'Wisconsin',
|
|
184
|
+
'America/Chicago',
|
|
185
|
+
['262', '274', '353', '414', '534', '608', '715', '920'],
|
|
186
|
+
],
|
|
187
|
+
['Wyoming', 'America/Denver', ['307']],
|
|
188
|
+
|
|
189
|
+
// US territories
|
|
190
|
+
['Puerto Rico', 'America/Puerto_Rico', ['787', '939']],
|
|
191
|
+
['US Virgin Islands', 'America/St_Thomas', ['340']],
|
|
192
|
+
['Guam', 'Pacific/Guam', ['671']],
|
|
193
|
+
['Northern Mariana Islands', 'Pacific/Saipan', ['670']],
|
|
194
|
+
['American Samoa', 'Pacific/Pago_Pago', ['684']],
|
|
195
|
+
|
|
196
|
+
// Canada
|
|
197
|
+
['Alberta', 'America/Edmonton', ['368', '403', '587', '780', '825']],
|
|
198
|
+
// 604 is the Lower Mainland only. The province-wide overlays also cover the East
|
|
199
|
+
// Kootenays (Mountain) and the Peace River region (Mountain, no daylight saving).
|
|
200
|
+
['British Columbia', 'America/Vancouver', ['604']],
|
|
201
|
+
[
|
|
202
|
+
'British Columbia',
|
|
203
|
+
['America/Vancouver', 'America/Edmonton', 'America/Dawson_Creek'],
|
|
204
|
+
['236', '250', '672', '778'],
|
|
205
|
+
],
|
|
206
|
+
['Manitoba', 'America/Winnipeg', ['204', '431', '584']],
|
|
207
|
+
['New Brunswick', 'America/Moncton', ['428', '506']],
|
|
208
|
+
// Labrador is mostly on Atlantic time.
|
|
209
|
+
['Newfoundland and Labrador', ['America/St_Johns', 'America/Goose_Bay'], ['709', '879']],
|
|
210
|
+
['Nova Scotia and Prince Edward Island', 'America/Halifax', ['782', '902']],
|
|
211
|
+
[
|
|
212
|
+
'Ontario',
|
|
213
|
+
'America/Toronto',
|
|
214
|
+
[
|
|
215
|
+
'226', '249', '289', '343', '365', '382', '416', '437', '519', '548', '613',
|
|
216
|
+
'647', '683', '705', '742', '753', '905', '942',
|
|
217
|
+
],
|
|
218
|
+
],
|
|
219
|
+
// Northwestern Ontario west of 90W is Central; Atikokan keeps Eastern Standard.
|
|
220
|
+
['Ontario', ['America/Toronto', 'America/Winnipeg', 'America/Atikokan'], ['807']],
|
|
221
|
+
[
|
|
222
|
+
'Quebec',
|
|
223
|
+
'America/Toronto',
|
|
224
|
+
['263', '354', '438', '450', '468', '514', '579', '819', '873'],
|
|
225
|
+
],
|
|
226
|
+
// Eastern Quebec includes the Magdalen Islands and the Lower North Shore, which
|
|
227
|
+
// are on Atlantic time.
|
|
228
|
+
['Quebec', ['America/Toronto', 'America/Halifax', 'America/Blanc-Sablon'], ['367', '418', '581']],
|
|
229
|
+
// Lloydminster, on the Alberta border, keeps Alberta time.
|
|
230
|
+
['Saskatchewan', ['America/Regina', 'America/Edmonton'], ['306', '474', '639']],
|
|
231
|
+
[
|
|
232
|
+
'Yukon, Northwest Territories and Nunavut',
|
|
233
|
+
['America/Whitehorse', 'America/Edmonton', 'America/Winnipeg', 'America/Toronto'],
|
|
234
|
+
['867'],
|
|
235
|
+
],
|
|
236
|
+
|
|
237
|
+
// Caribbean and Atlantic countries on +1
|
|
238
|
+
['Anguilla', 'America/Anguilla', ['264']],
|
|
239
|
+
['Antigua and Barbuda', 'America/Antigua', ['268']],
|
|
240
|
+
['Bahamas', 'America/Nassau', ['242']],
|
|
241
|
+
['Barbados', 'America/Barbados', ['246']],
|
|
242
|
+
['Bermuda', 'Atlantic/Bermuda', ['441']],
|
|
243
|
+
['British Virgin Islands', 'America/Tortola', ['284']],
|
|
244
|
+
['Cayman Islands', 'America/Cayman', ['345']],
|
|
245
|
+
['Dominica', 'America/Dominica', ['767']],
|
|
246
|
+
['Dominican Republic', 'America/Santo_Domingo', ['809', '829', '849']],
|
|
247
|
+
['Grenada', 'America/Grenada', ['473']],
|
|
248
|
+
['Jamaica', 'America/Jamaica', ['658', '876']],
|
|
249
|
+
['Montserrat', 'America/Montserrat', ['664']],
|
|
250
|
+
['Saint Kitts and Nevis', 'America/St_Kitts', ['869']],
|
|
251
|
+
['Saint Lucia', 'America/St_Lucia', ['758']],
|
|
252
|
+
['Saint Vincent and the Grenadines', 'America/St_Vincent', ['784']],
|
|
253
|
+
['Sint Maarten', 'America/Lower_Princes', ['721']],
|
|
254
|
+
['Trinidad and Tobago', 'America/Port_of_Spain', ['868']],
|
|
255
|
+
['Turks and Caicos Islands', 'America/Grand_Turk', ['649']],
|
|
256
|
+
]
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* @typedef {object} ZoneEntry
|
|
260
|
+
* @property {string} region State, province, territory or country.
|
|
261
|
+
* @property {string[]} zones IANA zones. More than one means ambiguous.
|
|
262
|
+
*/
|
|
263
|
+
|
|
264
|
+
/** @type {Map<string, ZoneEntry>} */
|
|
265
|
+
export const NANP_AREA_CODES = new Map()
|
|
266
|
+
for (const [region, zone, codes] of ROWS) {
|
|
267
|
+
for (const code of codes) {
|
|
268
|
+
if (NANP_AREA_CODES.has(code)) throw new Error(`Area code ${code} is listed twice.`)
|
|
269
|
+
NANP_AREA_CODES.set(code, { region, zones: Array.isArray(zone) ? zone : [zone] })
|
|
270
|
+
}
|
|
271
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public URL shorteners. Carriers filter links on shared shortener domains, because
|
|
3
|
+
* anyone can hide any destination behind one. Matched exactly, and on subdomains.
|
|
4
|
+
*/
|
|
5
|
+
export const SHORTENER_DOMAINS = new Set([
|
|
6
|
+
'bit.ly', 'bitly.com', 'buff.ly', 'cutt.ly', 'goo.gl', 'is.gd', 'lnkd.in', 'ow.ly',
|
|
7
|
+
'rb.gy', 'rebrand.ly', 'shorturl.at', 't.co', 't.ly', 'tiny.cc', 'tinyurl.com',
|
|
8
|
+
'v.gd', 'x.co', 'bl.ink', 'short.io', 'shorte.st', 'soo.gd', 'clck.ru', 'qrco.de',
|
|
9
|
+
's.id', 'urlz.fr', 'tr.ee',
|
|
10
|
+
])
|