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.

62 lines
1.4 KiB

4 years ago
  1. ansi-html [![NPM version](https://badge.fury.io/js/ansi-html.svg)](http://badge.fury.io/js/ansi-html) [![Build Status](https://travis-ci.org/Tjatse/ansi-html.svg?branch=master)](https://travis-ci.org/Tjatse/ansi-html)
  2. =========
  3. An elegant lib that converts the chalked (ANSI) text to HTML.
  4. # Coverage
  5. - All styles of [chalk](https://github.com/sindresorhus/chalk) (100%) and [colors](https://github.com/Marak/colors.js).
  6. - There are over **150** randomized test cases under `test`.
  7. # Installation
  8. ```
  9. $ npm install ansi-html
  10. ```
  11. # Usage
  12. ```javascript
  13. var ansiHTML = require('ansi-html');
  14. var str = ansiHTML('[ANSI_TEXT]');
  15. ```
  16. e.g.:
  17. ```javascript
  18. var chalk = require('chalk');
  19. var str = chalk.bold.red('foo') + ' bar';
  20. console.log('[ANSI]', str)
  21. console.log('[HTML]', ansiHTML(str));
  22. ```
  23. See complete examples under `test` / `examples` directory.
  24. # Set Colors
  25. ```javascript
  26. ansiHTML.setColors({
  27. reset: ['555', '666'], // FOREGROUND-COLOR or [FOREGROUND-COLOR] or [, BACKGROUND-COLOR] or [FOREGROUND-COLOR, BACKGROUND-COLOR]
  28. black: 'aaa', // String
  29. red: 'bbb',
  30. green: 'ccc',
  31. yellow: 'ddd',
  32. blue: 'eee',
  33. magenta: 'fff',
  34. cyan: '999',
  35. lightgrey: '888',
  36. darkgrey: '777'
  37. });
  38. ```
  39. # Reset
  40. ```javascript
  41. ansiHTML.reset();
  42. ```
  43. # Exposed Tags
  44. ```javascript
  45. var openTags = ansiHTML.tags.open;
  46. var closeTags = ansiHTML.tags.close;
  47. ```
  48. # Test
  49. ```
  50. $ npm install -l
  51. $ npm test
  52. ```