A low level parser for ANSI sequences.
- Converts text containing ANSI color escape codes into equivalent HTML elements.
- Allows converting the input into JSON output.
- HTML escaping
- Converts links into HTML elements
- Friendly APIs to use with virtual dom libraries
# Using npm
npm install --save anser
# Using yarn
yarn add anserconst Anser = require("anser");
const txt = "\u001b[38;5;196mHello\u001b[39m \u001b[48;5;226mWorld\u001b[49m";
console.log(Anser.ansiToHtml(txt));
// <span style="color:rgb(255, 0, 0)">Hello</span> <span style="background-color:rgb(255, 255, 0)">World</span>
console.log(Anser.ansiToHtml(txt, { use_classes: true }));
// <span class="ansi-palette-196-fg">Hello</span> <span class="ansi-palette-226-bg">World</span>
console.log(Anser.ansiToJson(txt));
// [ { content: '',
// fg: null,
// bg: null,
// fg_truecolor: null,
// bg_truecolor: null,
// clearLine: undefined,
// decoration: null,
// was_processed: false,
// isEmpty: [Function: isEmpty] },
// { content: 'Hello',
// fg: '255, 0, 0',
// bg: null,
// fg_truecolor: null,
// bg_truecolor: null,
// clearLine: false,
// decoration: null,
// was_processed: true,
// isEmpty: [Function: isEmpty] },
// { content: ' ',
// fg: null,
// bg: null,
// fg_truecolor: null,
// bg_truecolor: null,
// clearLine: false,
// decoration: null,
// was_processed: false,
// isEmpty: [Function: isEmpty] },
// { content: 'World',
// fg: null,
// bg: '255, 255, 0',
// fg_truecolor: null,
// bg_truecolor: null,
// clearLine: false,
// decoration: null,
// was_processed: true,
// isEmpty: [Function: isEmpty] },
// { content: '',
// fg: null,
// bg: null,
// fg_truecolor: null,
// bg_truecolor: null,
// clearLine: false,
// decoration: null,
// was_processed: false,
// isEmpty: [Function: isEmpty] } ]When using TypeScript without --esModuleInterop enabled you can do the following:
import Anser = require('anser');
const txt = "\u001b[38;5;196mHello\u001b[39m \u001b[48;5;226mWorld\u001b[49m";
console.log(Anser.ansiToHtml(txt));
// <span style="color:rgb(255, 0, 0)">Hello</span> <span style="background-color:rgb(255, 255, 0)">World</span>Or with --esModuleInterop enabled you can do the following:
import Anser from 'anser';
const txt = "\u001b[38;5;196mHello\u001b[39m \u001b[48;5;226mWorld\u001b[49m";
console.log(Anser.ansiToHtml(txt));
// <span style="color:rgb(255, 0, 0)">Hello</span> <span style="background-color:rgb(255, 255, 0)">World</span>There are few ways to get help:
- Please post questions on Stack Overflow. You can open issues with questions, as long you add a link to your Stack Overflow question.
- For bug reports and feature requests, open issues. 🐛
- For direct and quick help, you can use Codementor. 🚀
Add several widely used style codes
Processes the current chunk of text.
- String
text: The input text. - Object
options: An object containing the following fields: json(Boolean): Iftrue, the result will be an object.use_classes(Boolean): Iftrue, HTML classes will be appended to the HTML output.- Boolean
markup: If false, the colors will not be parsed.
- Object|String The result (object if
jsonis wanted back or string otherwise).
Have an idea? Found a bug? See how to contribute.
I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously, this takes time. You can integrate and use these projects in your applications for free! You can even change the source code and redistribute (even resell it).
However, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it:
-
Starring and sharing the projects you like 🚀
-
—I love books! I will remember you after years if you buy me one. 😁 📖
-
—You can make one-time donations via PayPal. I'll probably buy a
coffeetea. 🍵 -
—Set up a recurring monthly donation and you will get interesting news about what I'm doing (things that I don't share with everyone).
-
Bitcoin—You can send me bitcoins at this address (or scanning the code below):
1P9BRsmazNQcuyTxEqveUsnf5CERdq35V6
Thanks! ❤️
This project is highly based on ansi_up, by @drudru. Thanks! 🍰
If you are using this library in one of your projects, add it in this list. ✨
@10102004tan/react-native-select-dropdown-v2@_nomtek/react-native-shimmer-animation@adatechnology/react-native-android-getnet-pos@adembacaj/react-native-google-pay@affinidi/affinidi-auth-sdk-kernel@aibulat/naser@ajaykewat/myboilerplate@ali5049/react-native-buttons@alloc/react-error-overlay@apardellass/react-native-audio-stream@ascorbic/gatsby@assystant/firebase@atom-ide-community/nuclide-commons-ui@axio/react-dev-utils@aysea/react-native-ui-library@azalpacir/react-native-dhp-printer@baloochat/react-native-svg-uri@blkmarketco/components-library@brantalikp/rn-resize@callstack/react-native-visionos@classflow/react-dev-utils@classyllama/code-style@cocalc/ansi-to-react@codedown/ansi-to-react@codesandbox/sandpack-react@codewars/jest-reporter@con-test/react-native-concent-common@corelmax/react-native-my2c2p-sdk@cs6/react-native-test-native-view-library@cubejs-client/playground@curvenote/ansi-to-react@damian.lnc/core@damruravihara/react-native-testing-package@davidmccabe/sandpack-react@deix/paganini-ui@devpodio/console@digibear/socket-bridge@distasy/react-native-fix@ehyland-org/react-error-overlay@enkeledi/react-native-week-month-date-picker@expensify/react-native@felipesimmi/react-native-datalogic-module@geeky-apo/react-native-advanced-clipboard@hbglobal/react-native-actions-shortcuts@hemith/react-native-tnk@heora/cubejs-client-playground@hjopel/react-native@idas1/ui-component-lib@jfilipe-sparta/react-native-module_2@kloudlite/design-system@ko-developerhong/react-native-multiple-image-picker@kui-shell/plugin-client-common@labiebhn_/react-native-multiplier@lehuyaa/my-assets@leonchabbey/react-native-tvos@logisticinfotech/react-native-geocoding-reversegeocoding@navabi/react-native-ssl-pinning@naze/error@ndjoe/react-native-bluetooth-escpos-printer@next/react-dev-overlay@nonfx/flow-log@office-iss/react-native-win32@oiti/rn-liveness2d@ollion/flow-log@opensumi/ide-debug@orgbluetooth/react-native-arunpayupayment@plansys/react-dev-utils@popbot/react-native-macos@praella/localisationist@prague-digi/react-error-overlay@prozilla-os/terminal@react-native-ui-design/button@redux-devtools/inspector-monitor-trace-tab@routebuddies/react-native-mapbox-navigation@routeslk/react-native-eva-icons@saad27/react-native-bottom-tab-tour@sebastien_rts/react-native-tvos@sephriot/react-native-persistable-uri@shuvi/error-overlay@sidghimire/react-native-mapbox-navigation@soyjak/utils@sridharetikala/react-native-rn-lib-custom-components@status-im/react-native-transparent-video@suen/react-native-tvos@taingo97/react-native-bluetooth-escpos-printer@taingo97/react-native-bluetooth-xprinter@taingo97/react-native-expo-key-rsa-kt@taingo97/react-native-generate-key-rsa@taingo97/react-native-key-rsa@taingo97/react-native-print-xprinter@taingo97/react-native-printer-imin@taingo97/react-native-rsa-expo@taingo97/react-native-sunmi-printer@taingo97/react-native-telpo-printer@tasumaniadiabori/react-native-draggable-flatlist@th3rdwave/react-native@theia/console@throttleup/gatsby@tlgeo/react-native-gdal@trackier/react-native-trackier@unforgiven/react-native@viankakrisna/react-dev-utils@viankakrisna/react-error-overlay@vidit-me/react-native-wheely@zotasys/nativeact_mvvm_shop_cartada-packadyen-rnansi-html-themedansi-log-rendereransi-to-jsonansi-to-reactansi-to-react-with-optionsansi-to-vue3ansicolor-utilsarchlibraryawesome-module-kdbiometric-stbirken-react-native-community-image-editorbn-react-nativecallstack-task-react-dev-utilscallstack-task-react-error-overlaycheckbox-componentcycle-dev-utilsdogandev-simple-toastdulcet-error-overlayemg-apifawaterak-online-paymentfluent.adflow.reactnativesdkfluent.adflow.reactnativesdk-alphafmslframework_test_library_sixdeeframework_test_library_sixdee_newframework_test_library_sixdee_new_newgamification-integration-newgatsbygaurav-react-native-loopgenz-native-elementsipynb2htmlipynb2html-fixjesh-calculationjnf-accesscontrol-rnttljrennsoh88-react-native-scroll-indicatorkhaled-salem-custom-componentskunailambda-dev-utilslinklogmesh-devtoolmulti-termnative-apple-loginnative-date-picker-modulenative-google-loginnative-kakao-loginnative-modal-damage-vehiclenew-awesome-4321nove-repositorynpm_one_12_34_1_npm_one_1_2_3npm_one_2_2npm_qwertynuclidenuclide-commons-uipayutestingpnm-yph-react-native-custom-componentsprocrealms-clientraact-native-arunramya151reac-native-arun-ramya-testreact-ansireact-ansi-eighteenreact-dev-utils-custom-hmrreact-dev-utils-extrareact-dev-utils-sebfl-updatereact-error-guardreact-error-overlay-canaryreact-error-overlay-dangerousreact-ipynb-renderer-katexreact-nativereact-native-adarsh_react_native_video_playerreact-native-additionreact-native-android-native-viewreact-native-android-scoped-storagereact-native-android-video-player-viewreact-native-animate-textreact-native-ansi-viewreact-native-app-bubblereact-native-app-integrity-checksumreact-native-arps-authorize-netreact-native-arun-ramya-testreact-native-arunjeyam1987react-native-arunmeena1987react-native-arunramya151react-native-auth-service-clientreact-native-aventonfacetec-aventonreact-native-avinash_jha_test_pluginreact-native-awesome-android-123react-native-awesome-android-123-zeotapreact-native-awesome-module-dharmeshreact-native-awesome-module-latestreact-native-awesome-module-tworeact-native-azure-communication-servicesreact-native-badge-controlreact-native-basic-appreact-native-basic-screenreact-native-biometric-authenticatereact-native-bleccs-componentsreact-native-bluetooth-device-detectreact-native-bottom-tab-designsreact-native-bridge-packagereact-native-bubble-chartreact-native-build-vesion-getterreact-native-check-componentreact-native-chenaarreact-native-components-designreact-native-conekta-card-tokenizerreact-native-contact-listreact-native-coocaatvreact-native-cplusreact-native-create-video-thumbnailreact-native-ctp-odpreact-native-custom-poccomponentreact-native-custom-poccomponent-nextreact-native-datacapture-corereact-native-dff-components-demoreact-native-dhp-printerreact-native-dimensions-layoutreact-native-dishreact-native-dm-playerreact-native-dsphoto-modulereact-native-dummy-viewreact-native-escapereact-native-expendable-viewreact-native-expo-read-sms-ts-kfreact-native-fedlight-dsmreact-native-firebase-messagingreact-native-flyyreact-native-get-countriesreact-native-ghn-ekycreact-native-hlf-wrapperreact-native-innity-2react-native-innity-remasterreact-native-input-libraryreact-native-is7react-native-jsi-device-inforeact-native-kakao-mapsreact-native-klarify-iosreact-native-klarify-uireact-native-klcreact-native-lib-test-rn-1react-native-library-testing-422522react-native-line-login-androidreact-native-login-demo-testreact-native-lowlatencyreact-native-loyalty-platformsreact-native-macosreact-native-manh-testreact-native-manual-ios-sdkreact-native-meon-edocreact-native-meonsdkreact-native-meontoolreact-native-modal-progress-barreact-native-module-for-testingreact-native-multi-bluetooth-printerreact-native-multiplier-altroncosoreact-native-multiplier-componentreact-native-multiplier-demoreact-native-multiplier2react-native-multiplyreact-native-multiply-componentreact-native-multiselectorreact-native-mun-kitreact-native-my-first-try-arun-ramyareact-native-mybuttonlibraryreact-native-mymapreact-native-native-audio-enginereact-native-native-ios-test1react-native-nativewindreact-native-nghia-shareringreact-native-nice-learningreact-native-nyx-printerreact-native-offline-noticereact-native-okhttp-forkreact-native-onrampreact-native-otp-custom-libraryreact-native-patch-javareact-native-paynow-generatorreact-native-payu-paymentreact-native-payu-payment-testingreact-native-plugpag-wrapperreact-native-pme-loadingreact-native-priya-demo-buttonreact-native-progress-arrowreact-native-pulsator-nativereact-native-rabbitmq-allreact-native-radio-bic-group-libreact-native-reanimated-sortable-listreact-native-recent-framework-updatereact-native-remote-cloverreact-native-remote-updatereact-native-responsive-helperreact-native-responsive-sizereact-native-return-usb-datareact-native-reusableinputwithpaperreact-native-rn-common-components-examplereact-native-rn-icons-libraryreact-native-rn-tolkaplayerreact-native-rom-componentsreact-native-rtn-ips-poslin-testreact-native-s-airlinesreact-native-sandycomponentreact-native-savczuk-feature-libraryreact-native-sayhello-modulereact-native-screen-idle-timerreact-native-scroll-tab-to-indexreact-native-sfreact-native-shared-gesturereact-native-sharing-intentreact-native-simple-timelinereact-native-smartcall-videodemoreact-native-sp-test-commonreact-native-sunmi-printer-hkreact-native-superapis-transbank-posreact-native-swalreact-native-teads-sdk-modulereact-native-tejab41097-sample-libraryreact-native-teknoctrl-componentsreact-native-test-comlibraryreact-native-test-module-hhhreact-native-test-multiplier-libraryreact-native-test-tooltipreact-native-test-viewreact-native-testwebreact-native-ticker-tapereact-native-tone-frameworkreact-native-tone-testreact-native-tonesreact-native-trackierreact-native-transtracker-libraryreact-native-tvosreact-native-tvos-nzreact-native-ui-components-libraryreact-native-uvc-camera-androidreact-native-version-appreact-native-windowsreact-native-withframework-checkreact-native-wtfreact-native-xprinter-thermal-blereact-native-ytximkitreact-webpack-build-helperreact_native_pandey_marqueereactnativelyreat-native-multiplierkprredux-devtools-trace-monitorrenu-packrn-adyen-dropinrn-check-btnrn-circular-chartrn-counter-demorn-currency-formatterrn-flatlist-forkrn-horizontal-listrn-keyboard-avoiding-viewrn-my-libraryrn-pay-sdkrn-session-multiplier-demorn-tm-notifyrn-use-modal-hookrn_unique_device_idrnttlocksimple-library-react-nativesingularityui-tailersmart_one_connectsmile-ansi-to-reactstack-frame-overlaytest-haptik-libtest-library-123test-zeo-collecttimer-react-dev-utilstransformimeuserfetchuyun-react-dev-utilsvantiq-reactvision-camera-base64-resizedvision-camera-plugin-face-detectorvision-camera-plugin-scan-faceswebpack-isomorphic-dev-middlewarewebpack-universal-compilerwifi_configuration_packagewildev-react-nativeyarn-react-hook-formzc-react-dev-utilszf-rn-testaa