{"id":16296519,"url":"https://github.com/f1lt3r/ansi-parse","last_synced_at":"2025-04-09T13:36:23.123Z","repository":{"id":143748392,"uuid":"127760051","full_name":"F1LT3R/ansi-parse","owner":"F1LT3R","description":"🤖  Parse ANSI text into an array of ansi-tags and text-chunks.","archived":false,"fork":false,"pushed_at":"2018-04-07T04:16:14.000Z","size":49,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T10:09:53.886Z","etag":null,"topics":["ansi","chalk","character","close","color","escape","open","parse","parser","sequence","style","text"],"latest_commit_sha":null,"homepage":"https://f1lt3r.io","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/F1LT3R.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-04-02T13:29:48.000Z","updated_at":"2018-11-28T07:09:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"dad7dad3-85e1-42cf-b21f-d959e8437c56","html_url":"https://github.com/F1LT3R/ansi-parse","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/F1LT3R%2Fansi-parse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/F1LT3R%2Fansi-parse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/F1LT3R%2Fansi-parse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/F1LT3R%2Fansi-parse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/F1LT3R","download_url":"https://codeload.github.com/F1LT3R/ansi-parse/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248050163,"owners_count":21039335,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansi","chalk","character","close","color","escape","open","parse","parser","sequence","style","text"],"created_at":"2024-10-10T20:23:02.260Z","updated_at":"2025-04-09T13:36:23.093Z","avatar_url":"https://github.com/F1LT3R.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ansi-parse\n\n\u003e 🤖  Parse ansi into an array of ansi-tags and text-chunks.\n\n[![Build Status](https://travis-ci.org/F1LT3R/ansi-parse.svg?branch=master)](https://travis-ci.org/F1LT3R/ansi-parse)\n[![Coverage Status](https://coveralls.io/repos/github/F1LT3R/ansi-parse/badge.svg?branch=master)](https://coveralls.io/github/F1LT3R/ansi-parse?branch=master)\n[![NPM Version](https://img.shields.io/npm/v/@f1lt3r/ansi-parse.svg)](https://www.npmjs.com/package/@f1lt3r/ansi-parse)\n[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)\n\nANSI-Parse takes an ANSI string as input:\n\n```plain\nconst text = \"🤖\\u001B[31m DANGER\\u001B[0m Will Robbinson\"\nconsole.log(text)\n```\n\n![Danger Will Robbinson](danger-will-robbinson.png)\n\nWhen you run your text through the ANSI-Parse...\n\n```js\nconst ansiParse = require('ansi-parse')\nconst parsed = ansiParse(text)\nconsole.log(parsed)\n```\n\n...ANSI-Parse outputs value, position and style data.\n\n```js\n{\n    raw: '🤖\\u001B[31m DANGER\\u001B[0m Will Robbinson',    \n    plain: '🤖 DANGER Will Robbinson',\n    textArea: {columns: 24, rows: 1},\n    chunks: [{\n        type: 'text',\n        value: '🤖',\n        position: {x: 0, y: 0, n: 0, raw: 0},\n        style: {}\n    }, {\n        type: 'ansi',\n        value: {tag: 'red', ansi: '\\u001b[31m'},\n        position: {x: 2, y: 0, n: 2, raw: 2}\n    }, {\n        type: 'text',\n        value: ' DANGER',\n        position: {x: 2,y: 0,n: 2, raw: 7},\n        style: {\n            foregroundColor: 'red'\n        }\n    }, {\n        type: 'ansi',\n        value: {tag: 'reset', ansi: '\\u001b[0m'},\n        position: {x: 9, y: 0, n: 9, raw: 14}\n    }, {\n        type: 'text',\n        value: ' Will Robbinson',\n        position: {x: 9, y: 0, n: 9, raw: 18},\n        style: {}\n    }]\n}\n```\n\nThis data can be used to convert ANSI sequences to other formatsm such as HTML, Image, SVG, etc.\n\n## Chunk\n\nEach object in the output array is called a \"chunk\". Each chunk represents one or more of the following data types.\n\n1. `ansi` - ANSI escape sequence\n1. `newline` - Newline character\n1. `text` - Text chunk of like-styles\n\n## Style\n\nThe style object contains a list of styles associated with the current chunk. Each style represents an ANSI Escape sequence that is mapped to  friendly name called an `ANSI-Tag`.\n\n- Styles are only included in text chunks.\n- Styles that are off/closed, are not present in the style object. \n\nThe following style object describes a chunk of red text:\n\n```js\n{\n    foregroundColor: 'red'\n}\n```\n\nThis object shows alls styles in combination:\n\n```js\n{\n    backgroundColor: 'bgRed',\n    foregroundColor: 'white',\n    dim: true,\n    bold: true,\n    italic: true,\n    underline: true,\n    strikethrough: true,\n    inverse: true\n}\n```\n\nStyles that are closed or reset are not included in the style object. \n\nFor example:\n\n```js\n             // Turn on Bold\nconst text = '\\u001b[1m BOLD' +\n    // Turn off all styles\n    '\\u001b[0m NORMAL'\n\nconst parsed = ansiParse(text)\n\nconst styles = parsed\n    .filter(chunk =\u003e chunk.style)\n    .map(chunk =\u003e chunk.style)\n\nconsole.log(styles)\n```\n\nThe above code should log:\n\n```js\n[\n    // Turn on Bold\n    { bold: true },\n\n    // Turn off all styles\n    {}\n]\n```\n\n## Position\n\n```js\n{x: 2, y: 0, n: 2, raw: 2}\n```\n\nThe position object contains 4 kinds of position:\n\n1. `x` - Plain-text column at which the chunk starts\n1. `y` - Plain-text crow at which the chunk starts\n1. `n` - Linear, 1-dimensional plain-text position at which the chunk starts.\n1. `raw` - Linear 1-dimensional position at which the chunk starts for ANSI or plain-text. This is the real JavaScript position string position of the chunk.\n\n## Value\n\n### Text Value\n\nThe value of a `text` chunk is a JavaScript string. The value of a text chunk should never contain any ANSI escape sequences.\n\n```js\n{\n    type: 'text',\n    value: ' DANGER',\n}\n```\n\n### ANSI Value\n\nThe value of an `ansi` chunk is an object. \n\n- `value.tag` - Friendly-named ansi-tag.\n- `value.ansi` - Raw ANSI string value.\n\n```js\n{\n    type: 'ansi',\n    value: {\n        tag: 'red',\n        ansi: '\\u001b[31m'\n    }\n}\n```\n\nYou can find the list ansi-tags in [types/types.ansi-seqs-to-ansi-tags.js](types/types.ansi-seqs-to-ansi-tags.js).\n\n## Install\n\n```\n$ yarn add ansi-parse\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ff1lt3r%2Fansi-parse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ff1lt3r%2Fansi-parse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ff1lt3r%2Fansi-parse/lists"}