-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
25 lines (24 loc) · 810 Bytes
/
index.js
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
'use strict';
let slds = {
ar: require('./countries/ar.js'),
at: require('./countries/at.js'),
au: require('./countries/au.js'),
br: require('./countries/br.js'),
mt: require('./countries/mt.js'),
mx: require('./countries/mx.js'),
nz: require('./countries/nz.js'),
sg: require('./countries/sg.js'),
uk: require('./countries/uk.js'),
za: require('./countries/za.js')
};
/**
* Check whether a given domain name is a top level domain.
* @param domain_name {string}
* @returns {boolean}
*/
module.exports = (domain_name) => {
// Convert a.b.c.d => ['d', 'c'] (only interested in last two elements in reverse order)
const niamod = domain_name.split('.').reverse().splice(0, 2);
const sld = slds[niamod[0]];
return !!sld && sld.indexOf(niamod[1]) >= 0;
}