Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

index.js 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. 'use strict';
  2. const os = require('os');
  3. const macosRelease = require('macos-release');
  4. const winRelease = require('windows-release');
  5. const osName = (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. let id;
  11. if (platform === 'darwin') {
  12. if (!release && os.platform() === 'darwin') {
  13. release = os.release();
  14. }
  15. const prefix = release ? (Number(release.split('.')[0]) > 15 ? 'macOS' : 'OS X') : 'macOS';
  16. id = release ? macosRelease(release).name : '';
  17. return prefix + (id ? ' ' + id : '');
  18. }
  19. if (platform === 'linux') {
  20. if (!release && os.platform() === 'linux') {
  21. release = os.release();
  22. }
  23. id = release ? release.replace(/^(\d+\.\d+).*/, '$1') : '';
  24. return 'Linux' + (id ? ' ' + id : '');
  25. }
  26. if (platform === 'win32') {
  27. if (!release && os.platform() === 'win32') {
  28. release = os.release();
  29. }
  30. id = release ? winRelease(release) : '';
  31. return 'Windows' + (id ? ' ' + id : '');
  32. }
  33. return platform;
  34. };
  35. module.exports = osName;