index.js 765 B

1234567891011121314151617181920212223242526272829303132333435
  1. 'use strict';
  2. var os = require('os');
  3. var semver = require('semver');
  4. var nameMap = {
  5. '10.0': '10',
  6. '6.3': '8.1',
  7. '6.2': '8',
  8. '6.1': '7',
  9. '6.0': 'Vista',
  10. '5.1': 'XP',
  11. '5.0': '2000',
  12. '4.9': 'ME',
  13. '4.1': '98',
  14. '4.0': '95'
  15. };
  16. module.exports = function (release) {
  17. var verRe = /\d+\.\d+/;
  18. var version = verRe.exec(release || os.release());
  19. // workaround for Windows 10 on node < 3.1.0
  20. if (!release && process.platform === 'win32' &&
  21. semver.satisfies(process.version, '>=0.12.0 <3.1.0')) {
  22. try {
  23. version = verRe.exec(String(require('child_process').execSync('ver.exe', {timeout: 2000})));
  24. } catch (err) {}
  25. }
  26. if (release && !version) {
  27. throw new Error('`release` argument doesn\'t match `n.n`');
  28. }
  29. return nameMap[(version || [])[0]];
  30. };