index.js 800B

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict';
  2. var os = require('os');
  3. var macosRelease = require('macos-release');
  4. var winRelease = require('win-release');
  5. module.exports = function (platform, release) {
  6. if (!platform && release) {
  7. throw new Error('You can\'t specify a `release` without specifying `platform`');
  8. }
  9. platform = platform || os.platform();
  10. release = release || os.release();
  11. var id;
  12. if (platform === 'darwin') {
  13. var prefix = Number(release.split('.')[0]) > 15 ? 'macOS' : 'OS X';
  14. id = macosRelease(release).name;
  15. return prefix + (id ? ' ' + id : '');
  16. }
  17. if (platform === 'linux') {
  18. id = release.replace(/^(\d+\.\d+).*/, '$1');
  19. return 'Linux' + (id ? ' ' + id : '');
  20. }
  21. if (platform === 'win32') {
  22. id = winRelease(release);
  23. return 'Windows' + (id ? ' ' + id : '');
  24. }
  25. return platform;
  26. };