UNPKG

867 BJavaScriptView Raw
1"use strict";
2
3const {platform, type} = require("os");
4
5const supportedPlatforms = new Set([
6 "aix",
7 "android",
8 "darwin",
9 "freebsd",
10 "linux",
11 "openbsd",
12 "sunos",
13 "win32"
14]);
15
16const plat = platform();
17
18if (supportedPlatforms.has(plat)) {
19 let file = plat;
20 if (plat === "aix") {
21 file = type() === "OS400" ? "ibmi" : "sunos"; // AIX `netstat` output is compatible with Solaris
22 }
23
24 const m = require(`./${file}.js`);
25 module.exports.v4 = () => m.v4();
26 module.exports.v6 = () => m.v6();
27 module.exports.v4.sync = () => m.v4.sync();
28 module.exports.v6.sync = () => m.v6.sync();
29} else {
30 const err = new Error(`Unsupported Platform: ${plat}`);
31 module.exports.v4 = () => Promise.reject(err);
32 module.exports.v6 = () => Promise.reject(err);
33 module.exports.v4.sync = () => { throw err; };
34 module.exports.v6.sync = () => { throw err; };
35}