-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (37 loc) · 970 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import dns from 'node:dns/promises'
import path from 'path'
export function fullPath (basePath, filePath) {
if (!basePath) return filePath
// if (filePath.startsWith('/')) return filePath
return path.resolve(basePath, path.basename(filePath))
}
export function valueCleanup (str) {
if (str.startsWith('"') && str.endsWith('"')) {
str = str.substr(1,str.length -2) // strip double quotes
}
if (/^[0-9.]+$/.test(str) && Number(str).toString() === str) {
return Number(str)
}
return str
}
export async function isDelegated (zone, expectedNS) {
try {
const servers = await dns.resolveNs(zone)
if (!servers) return false
for (const s of servers) {
if (expectedNS.includes(s)) return true
}
return false
}
catch (e) {
switch (e.code) {
case 'ENOTFOUND':
case 'ENODATA':
return false
case 'ESERVFAIL':
return true // TODO, not sure
default:
throw e
}
}
}