Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

před 3 roky
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <div align="center">
  2. <img src="shots/logo.png" alt="kleur" height="120" />
  3. </div>
  4. <div align="center">
  5. <a href="https://npmjs.org/package/kleur">
  6. <img src="https://badgen.now.sh/npm/v/kleur" alt="version" />
  7. </a>
  8. <a href="https://travis-ci.org/lukeed/kleur">
  9. <img src="https://badgen.now.sh/travis/lukeed/kleur" alt="travis" />
  10. </a>
  11. <a href="https://npmjs.org/package/kleur">
  12. <img src="https://badgen.now.sh/npm/dm/kleur" alt="downloads" />
  13. </a>
  14. <a href="https://packagephobia.now.sh/result?p=kleur">
  15. <img src="https://packagephobia.now.sh/badge?p=kleur" alt="install size" />
  16. </a>
  17. </div>
  18. <div align="center">The fastest Node.js library for formatting terminal text with ANSI colors~!</div>
  19. ## Features
  20. * No dependencies
  21. * Super [lightweight](##load-time) & [performant](#performance)
  22. * Supports [nested](#nested-methods) & [chained](#chained-methods) colors
  23. * No `String.prototype` modifications
  24. * Conditional [color support](#conditional-support)
  25. * Familiar [API](#api)
  26. _Originally inspired by [`ansi-colors`](https://github.com/doowb/ansi-colors). See [Credits](#credits) for more info!_
  27. ## Install
  28. ```
  29. $ npm install --save kleur
  30. ```
  31. ## Usage
  32. ```js
  33. const kleur = require('kleur');
  34. // basic usage
  35. kleur.red('red text');
  36. // chained methods
  37. kleur.blue.bold.underline('howdy partner');
  38. // nested methods
  39. kleur.bold(`${ kleur.bgRed.white('[ERROR]') } ${ kleur.red.italic('Something happened')}`);
  40. ```
  41. ### Chained Methods
  42. ```js
  43. console.log(kleur.bold.red('this is a bold red message'));
  44. console.log(kleur.bold.italic('this is a bold italicized message'));
  45. console.log(kleur.bold.yellow.bgRed.italic('this is a bold yellow italicized message'));
  46. console.log(kleur.green.bold.underline('this is a bold green underlined message'));
  47. ```
  48. <img src="shots/1.png" width="300" />
  49. ### Nested Methods
  50. ```js
  51. const { yellow, red, cyan } = require('kleur');
  52. console.log(yellow(`foo ${red.bold('red')} bar ${cyan('cyan')} baz`));
  53. console.log(yellow('foo ' + red.bold('red') + ' bar ' + cyan('cyan') + ' baz'));
  54. ```
  55. <img src="shots/2.png" width="300" />
  56. ### Conditional Support
  57. Toggle color support as needed; `kleur` assumes it's always enabled.
  58. ```js
  59. const kleur = require('kleur');
  60. // manually disable
  61. kleur.enabled = false;
  62. // or use a library to detect support
  63. kleur.enabled = require('color-support').level;
  64. console.log(kleur.red('I will only be colored red if the terminal supports colors'));
  65. ```
  66. ## API
  67. Any `kleur` method returns a `String` (when invoked, not chained). It's up to the developer to pass the output to destinations like `console.log`, `process.stdout.write`, etc.
  68. The methods below are grouped by type for legibility purposes only. They each can be [chained](#chained-methods) or [nested](#nested-methods) with one another.
  69. ***Colors:***
  70. > black &mdash; red &mdash; green &mdash; yellow &mdash; blue &mdash; magenta &mdash; cyan &mdash; white &mdash; gray
  71. ***Backgrounds:***
  72. > bgBlack &mdash; bgRed &mdash; bgGreen &mdash; bgYellow &mdash; bgBlue &mdash; bgMagenta &mdash; bgCyan &mdash; bgWhite
  73. ***Modifiers:***
  74. > reset &mdash; bold &mdash; dim &mdash; italic* &mdash; underline &mdash; inverse &mdash; hidden &mdash; strikethrough*
  75. <sup>* <em>Not widely supported</em></sup>
  76. ## Benchmarks
  77. > Using Node v8.9.0
  78. ### Load time
  79. ```
  80. chalk: 9.372ms
  81. turbocolor: 0.526ms
  82. ansi-colors: 0.851ms
  83. kleur: 0.862ms
  84. ```
  85. ### Performance
  86. ```
  87. # All Colors
  88. ansi-colors x 60,485 ops/sec ±0.63% (96 runs sampled)
  89. chalk x 7,184 ops/sec ±3.77% (68 runs sampled)
  90. turbocolor x 95,468 ops/sec ±0.60% (94 runs sampled))
  91. kleur x 151,365 ops/sec ±0.22% (95 runs sampled)
  92. # Stacked colors
  93. ansi-colors x 13,754 ops/sec ±0.44% (93 runs sampled)
  94. chalk x 1,732 ops/sec ±3.76% (71 runs sampled)
  95. turbocolor x 28,709 ops/sec ±1.32% (92 runs sampled)
  96. kleur x 30,837 ops/sec ±0.13% (93 runs sampled)
  97. # Nested colors
  98. ansi-colors x 28,898 ops/sec ±0.32% (96 runs sampled)
  99. chalk x 3,389 ops/sec ±4.03% (71 runs sampled)
  100. turbocolor x 48,034 ops/sec ±1.47% (99 runs sampled)
  101. kleur x 61,266 ops/sec ±0.33% (97 runs sampled)
  102. ```
  103. ## Credits
  104. This project was originally inspired by [Brian Woodward](https://github.com/doowb)'s awesome [`ansi-colors`](https://github.com/doowb/ansi-colors) project.
  105. Unlike v1, the latest version(s) of `kleur` no longer supports:
  106. * printf-formatting
  107. * variadic function arguments
  108. * multiline text via `\n` or `\r`
  109. * `kleur.clear()` method
  110. In addition, `kleur` continues to be ship without symbols and bright color variants.
  111. If you need _any_ of these features, please use `ansi-colors` instead~!
  112. ## License
  113. MIT © [Luke Edwards](https://lukeed.com)