index.js 822 B

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