-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
30 lines (25 loc) · 740 Bytes
/
index.js
File metadata and controls
30 lines (25 loc) · 740 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
'use strict';
const MCCMNC = require('mccmnc.json');
exports.grok = function (imsi) {
// check if supplied IMSI number looks OK
if (typeof imsi != 'string')
throw new Error('Invalid IMSI type (expected string)');
if (!imsi)
throw new Error('Empty IMSI');
if (!/^\d+$/.test(imsi))
throw new Error('Invalid IMSI (contains non-digits)');
// try prefix of length 6
let entry6 = MCCMNC[ imsi.substr(0, 6) ];
if (entry6) {
entry6.msin = imsi.substr(6);
return entry6;
}
// try prefix of length 5
const entry5 = MCCMNC[ imsi.substr(0, 5) ];
if (entry5) {
entry5.msin = imsi.substr(5);
return entry5;
}
// not found
return null;
}