Dieses Repository beinhaltet HTML- und Javascript Code zur einer NotizenWebApp auf Basis von Web Storage. Zudem sind Mocha/Chai Tests im Browser enthalten. https://meinenotizen.netlify.app/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. 'use strict';
  2. const os = require('os');
  3. const hasFlag = require('has-flag');
  4. const {env} = process;
  5. let forceColor;
  6. if (hasFlag('no-color') ||
  7. hasFlag('no-colors') ||
  8. hasFlag('color=false')) {
  9. forceColor = 0;
  10. } else if (hasFlag('color') ||
  11. hasFlag('colors') ||
  12. hasFlag('color=true') ||
  13. hasFlag('color=always')) {
  14. forceColor = 1;
  15. }
  16. if ('FORCE_COLOR' in env) {
  17. if (env.FORCE_COLOR === true || env.FORCE_COLOR === 'true') {
  18. forceColor = 1;
  19. } else if (env.FORCE_COLOR === false || env.FORCE_COLOR === 'false') {
  20. forceColor = 0;
  21. } else {
  22. forceColor = env.FORCE_COLOR.length === 0 ? 1 : Math.min(parseInt(env.FORCE_COLOR, 10), 3);
  23. }
  24. }
  25. function translateLevel(level) {
  26. if (level === 0) {
  27. return false;
  28. }
  29. return {
  30. level,
  31. hasBasic: true,
  32. has256: level >= 2,
  33. has16m: level >= 3
  34. };
  35. }
  36. function supportsColor(stream) {
  37. if (forceColor === 0) {
  38. return 0;
  39. }
  40. if (hasFlag('color=16m') ||
  41. hasFlag('color=full') ||
  42. hasFlag('color=truecolor')) {
  43. return 3;
  44. }
  45. if (hasFlag('color=256')) {
  46. return 2;
  47. }
  48. if (stream && !stream.isTTY && forceColor === undefined) {
  49. return 0;
  50. }
  51. const min = forceColor || 0;
  52. if (env.TERM === 'dumb') {
  53. return min;
  54. }
  55. if (process.platform === 'win32') {
  56. // Node.js 7.5.0 is the first version of Node.js to include a patch to
  57. // libuv that enables 256 color output on Windows. Anything earlier and it
  58. // won't work. However, here we target Node.js 8 at minimum as it is an LTS
  59. // release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
  60. // release that supports 256 colors. Windows 10 build 14931 is the first release
  61. // that supports 16m/TrueColor.
  62. const osRelease = os.release().split('.');
  63. if (
  64. Number(process.versions.node.split('.')[0]) >= 8 &&
  65. Number(osRelease[0]) >= 10 &&
  66. Number(osRelease[2]) >= 10586
  67. ) {
  68. return Number(osRelease[2]) >= 14931 ? 3 : 2;
  69. }
  70. return 1;
  71. }
  72. if ('CI' in env) {
  73. if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
  74. return 1;
  75. }
  76. return min;
  77. }
  78. if ('TEAMCITY_VERSION' in env) {
  79. return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
  80. }
  81. if (env.COLORTERM === 'truecolor') {
  82. return 3;
  83. }
  84. if ('TERM_PROGRAM' in env) {
  85. const version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
  86. switch (env.TERM_PROGRAM) {
  87. case 'iTerm.app':
  88. return version >= 3 ? 3 : 2;
  89. case 'Apple_Terminal':
  90. return 2;
  91. // No default
  92. }
  93. }
  94. if (/-256(color)?$/i.test(env.TERM)) {
  95. return 2;
  96. }
  97. if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
  98. return 1;
  99. }
  100. if ('COLORTERM' in env) {
  101. return 1;
  102. }
  103. return min;
  104. }
  105. function getSupportLevel(stream) {
  106. const level = supportsColor(stream);
  107. return translateLevel(level);
  108. }
  109. module.exports = {
  110. supportsColor: getSupportLevel,
  111. stdout: getSupportLevel(process.stdout),
  112. stderr: getSupportLevel(process.stderr)
  113. };