市场夺宝奇兵
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.

138 lines
3.4 KiB

  1. <sup>yoctocolors 🌈</sup>
  2. > The smallest and fastest command-line coloring package on the internet
  3. *Check out [Chalk](https://github.com/chalk/chalk) if you want something more mature and comprehensive.*
  4. ## Highlights
  5. - Tiny
  6. - Fast
  7. - Handles nested colors
  8. - Tree-shakeable
  9. - No dependencies
  10. - Actively maintained
  11. ## Install
  12. ESM:
  13. ```sh
  14. npm install yoctocolors
  15. ```
  16. Or CommonJS:
  17. ```sh
  18. npm install yoctocolors-cjs
  19. ```
  20. ## Usage
  21. ```js
  22. import colors from 'yoctocolors';
  23. console.log(colors.red('Yo!'));
  24. console.log(colors.blue(`Welcome to the ${colors.green('yoctocolors')} package!`));
  25. ```
  26. You can also import colors as named imports:
  27. ```js
  28. import {red, blue, green} from 'yoctocolors';
  29. console.log(red('Yo!'));
  30. console.log(blue(`Welcome to the ${green('yoctocolors')} package!`));
  31. ```
  32. *This package supports [basic color detection](https://nodejs.org/api/tty.html#writestreamhascolorscount-env). Colors can be forcefully enabled by setting the `FORCE_COLOR` environment variable to `1` and can be forcefully disabled by setting `NO_COLOR` or `NODE_DISABLE_COLORS` to any value. [More info.](https://nodejs.org/api/tty.html#writestreamgetcolordepthenv)*
  33. ## Styles
  34. ### Modifiers
  35. - `reset` - Reset the current style.
  36. - `bold` - Make the text bold.
  37. - `dim` - Make the text have lower opacity.
  38. - `italic` - Make the text italic. *(Not widely supported)*
  39. - `underline` - Put a horizontal line above the text. *(Not widely supported)*
  40. - `overline` - Put a horizontal line below the text. *(Not widely supported)*
  41. - `inverse`- Invert background and foreground colors.
  42. - `hidden` - Print the text but make it invisible.
  43. - `strikethrough` - Put a horizontal line through the center of the text. *(Not widely supported)*
  44. ### Colors
  45. - `black`
  46. - `red`
  47. - `green`
  48. - `yellow`
  49. - `blue`
  50. - `magenta`
  51. - `cyan`
  52. - `white`
  53. - `gray`
  54. - `redBright`
  55. - `greenBright`
  56. - `yellowBright`
  57. - `blueBright`
  58. - `magentaBright`
  59. - `cyanBright`
  60. - `whiteBright`
  61. ### Background colors
  62. - `bgBlack`
  63. - `bgRed`
  64. - `bgGreen`
  65. - `bgYellow`
  66. - `bgBlue`
  67. - `bgMagenta`
  68. - `bgCyan`
  69. - `bgWhite`
  70. - `bgGray`
  71. - `bgRedBright`
  72. - `bgGreenBright`
  73. - `bgYellowBright`
  74. - `bgBlueBright`
  75. - `bgMagentaBright`
  76. - `bgCyanBright`
  77. - `bgWhiteBright`
  78. ## Prior art
  79. Yes
  80. ## Benchmark
  81. ```sh
  82. $ ./benchmark.js
  83. ┌─────────┬────────────────┬─────────────┐
  84. │ (index) │ library │ ops/sec │
  85. ├─────────┼────────────────┼─────────────┤
  86. │ 0 │ 'yoctocolors' │ '8,000,000' │
  87. │ 1 │ 'colorette' │ '8,000,000' │
  88. │ 2 │ 'picocolors' │ '8,000,000' │
  89. │ 3 │ 'nanocolors' │ '5,988,024' │
  90. │ 4 │ 'chalk' │ '4,807,692' │
  91. │ 5 │ 'kleur/colors' │ '4,807,692' │
  92. │ 6 │ 'kleur' │ '4,784,689' │
  93. │ 7 │ 'ansi-colors' │ '2,178,649' │
  94. │ 8 │ 'cli-color' │ '585,138' │
  95. └─────────┴────────────────┴─────────────┘
  96. ```
  97. *See [benchmark.js](benchmark.js).*
  98. ## FAQ
  99. ### What is yocto?
  100. [It was the smallest official unit prefix in the metric system until 2022.](https://en.wikipedia.org/wiki/Yocto-) Much smaller than nano.
  101. ## Related
  102. - [yoctodelay](https://github.com/sindresorhus/yoctodelay) - Delay a promise a given amount of time
  103. - [chalk](https://github.com/chalk/chalk) - Terminal string styling