index.js 867 B

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