index.js 850 B

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