c98586c857fa5d4abfe88f13b7cb286506a8af7b9c6f94b9c9a82fb7e9ba0a5d6db159d7daaf7c7c3833e24c84d9cf04ed6ba52fa79de6c2dc584f49d7928b 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. ansi-html [![NPM version](https://badge.fury.io/js/ansi-html-community.svg)](http://badge.fury.io/js/ansi-html) [![Build Status](https://app.travis-ci.com/mahdyar/ansi-html-community.svg?branch=master)](https://app.travis-ci.com/mahdyar/ansi-html-community)
  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-community
  10. ```
  11. # Usage
  12. ```javascript
  13. var ansiHTML = require('ansi-html-community');
  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. ```