Newer
Older
CVSS_3.0_GUI / dist / CVSS_3.0_Calc-1.0.0-linux-x64 / node_modules / nwjs-builder-phoenix / node_modules / dir-compare / node_modules / colors / lib / colors.js
root on 7 May 2019 4 KB Initial commit
  1. /*
  2.  
  3. The MIT License (MIT)
  4.  
  5. Original Library
  6. - Copyright (c) Marak Squires
  7.  
  8. Additional functionality
  9. - Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
  10.  
  11. Permission is hereby granted, free of charge, to any person obtaining a copy
  12. of this software and associated documentation files (the "Software"), to deal
  13. in the Software without restriction, including without limitation the rights
  14. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  15. copies of the Software, and to permit persons to whom the Software is
  16. furnished to do so, subject to the following conditions:
  17.  
  18. The above copyright notice and this permission notice shall be included in
  19. all copies or substantial portions of the Software.
  20.  
  21. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  22. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  24. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  25. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  26. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  27. THE SOFTWARE.
  28.  
  29. */
  30.  
  31. var colors = {};
  32. module['exports'] = colors;
  33.  
  34. colors.themes = {};
  35.  
  36. var ansiStyles = colors.styles = require('./styles');
  37. var defineProps = Object.defineProperties;
  38.  
  39. colors.supportsColor = require('./system/supports-colors');
  40.  
  41. if (typeof colors.enabled === "undefined") {
  42. colors.enabled = colors.supportsColor;
  43. }
  44.  
  45. colors.stripColors = colors.strip = function(str){
  46. return ("" + str).replace(/\x1B\[\d+m/g, '');
  47. };
  48.  
  49.  
  50. var stylize = colors.stylize = function stylize (str, style) {
  51. return ansiStyles[style].open + str + ansiStyles[style].close;
  52. }
  53.  
  54. var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
  55. var escapeStringRegexp = function (str) {
  56. if (typeof str !== 'string') {
  57. throw new TypeError('Expected a string');
  58. }
  59. return str.replace(matchOperatorsRe, '\\$&');
  60. }
  61.  
  62. function build(_styles) {
  63. var builder = function builder() {
  64. return applyStyle.apply(builder, arguments);
  65. };
  66. builder._styles = _styles;
  67. // __proto__ is used because we must return a function, but there is
  68. // no way to create a function with a different prototype.
  69. builder.__proto__ = proto;
  70. return builder;
  71. }
  72.  
  73. var styles = (function () {
  74. var ret = {};
  75. ansiStyles.grey = ansiStyles.gray;
  76. Object.keys(ansiStyles).forEach(function (key) {
  77. ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
  78. ret[key] = {
  79. get: function () {
  80. return build(this._styles.concat(key));
  81. }
  82. };
  83. });
  84. return ret;
  85. })();
  86.  
  87. var proto = defineProps(function colors() {}, styles);
  88.  
  89. function applyStyle() {
  90. var args = arguments;
  91. var argsLen = args.length;
  92. var str = argsLen !== 0 && String(arguments[0]);
  93. if (argsLen > 1) {
  94. for (var a = 1; a < argsLen; a++) {
  95. str += ' ' + args[a];
  96. }
  97. }
  98.  
  99. if (!colors.enabled || !str) {
  100. return str;
  101. }
  102.  
  103. var nestedStyles = this._styles;
  104.  
  105. var i = nestedStyles.length;
  106. while (i--) {
  107. var code = ansiStyles[nestedStyles[i]];
  108. str = code.open + str.replace(code.closeRe, code.open) + code.close;
  109. }
  110.  
  111. return str;
  112. }
  113.  
  114. function applyTheme (theme) {
  115. for (var style in theme) {
  116. (function(style){
  117. colors[style] = function(str){
  118. return colors[theme[style]](str);
  119. };
  120. })(style)
  121. }
  122. }
  123.  
  124. colors.setTheme = function (theme) {
  125. if (typeof theme === 'string') {
  126. try {
  127. colors.themes[theme] = require(theme);
  128. applyTheme(colors.themes[theme]);
  129. return colors.themes[theme];
  130. } catch (err) {
  131. console.log(err);
  132. return err;
  133. }
  134. } else {
  135. applyTheme(theme);
  136. }
  137. };
  138.  
  139. function init() {
  140. var ret = {};
  141. Object.keys(styles).forEach(function (name) {
  142. ret[name] = {
  143. get: function () {
  144. return build([name]);
  145. }
  146. };
  147. });
  148. return ret;
  149. }
  150.  
  151. var sequencer = function sequencer (map, str) {
  152. var exploded = str.split(""), i = 0;
  153. exploded = exploded.map(map);
  154. return exploded.join("");
  155. };
  156.  
  157. // custom formatter methods
  158. colors.trap = require('./custom/trap');
  159. colors.zalgo = require('./custom/zalgo');
  160.  
  161. // maps
  162. colors.maps = {};
  163. colors.maps.america = require('./maps/america');
  164. colors.maps.zebra = require('./maps/zebra');
  165. colors.maps.rainbow = require('./maps/rainbow');
  166. colors.maps.random = require('./maps/random')
  167.  
  168. for (var map in colors.maps) {
  169. (function(map){
  170. colors[map] = function (str) {
  171. return sequencer(colors.maps[map], str);
  172. }
  173. })(map)
  174. }
  175.  
  176. defineProps(colors, init());
Buy Me A Coffee