{"name":"ansi-sequence-parser","description":"A parser for ANSI escape sequences","repository":{"type":"git","url":"git+https://github.com/blake-mealey/ansi-sequence-parser.git"},"homepage":"https://github.com/blake-mealey/ansi-sequence-parser#readme","version":"1.1.3","type":"module","main":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"require":"./dist/index.cjs","import":"./dist/index.js"}},"keywords":["ansi","sequences","parser"],"author":{"name":"blake-mealey"},"license":"MIT","devDependencies":{"@changesets/cli":"^2.26.0","chalk":"^5.4.1","tsup":"^6.5.0","typescript":"^4.9.4","vitest":"^0.28.3"},"packageManager":"pnpm@8.15.1","scripts":{"build":"tsup src/index.ts --format cjs,esm --dts --clean","prepublish":"pnpm build","test":"FORCE_COLOR=true vitest","changeset":"changeset"},"bugs":{"url":"https://github.com/blake-mealey/ansi-sequence-parser/issues"},"_id":"ansi-sequence-parser@1.1.3","_integrity":"sha512-+fksAx9eG3Ab6LDnLs3ZqZa8KVJ/jYnX+D4Qe1azX+LFGFAXqynCQLOdLpNYN/l9e7l6hMWwZbrnctqr6eSQSw==","_resolved":"/private/var/folders/15/hv9mrt8n23nfjtxmh46sm0zr0000gn/T/dfa1f5b80c84e037879f033cb8e80df6/ansi-sequence-parser-1.1.3.tgz","_from":"file:ansi-sequence-parser-1.1.3.tgz","_nodeVersion":"16.16.0","_npmVersion":"8.11.0","dist":{"integrity":"sha512-+fksAx9eG3Ab6LDnLs3ZqZa8KVJ/jYnX+D4Qe1azX+LFGFAXqynCQLOdLpNYN/l9e7l6hMWwZbrnctqr6eSQSw==","shasum":"f2cefb8b681aeb72b7cd50aebc00d509eba64d4c","tarball":"http://registry-npm.ywwl.com/ansi-sequence-parser/download/ansi-sequence-parser-1.1.3.tgz","fileCount":6,"unpackedSize":22785,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIE1JKZ5uj5zMFS25f15uq5uUB3KVUDZ2qwVWmAC6PPueAiEA3XIa+nMuMouFkbxKEYxbQyRIVZ9HU+NFnCK1TwCoqfE="}],"size":4600,"noattachment":false,"key":"/ansi-sequence-parser/-/ansi-sequence-parser-1.1.3.tgz"},"_npmUser":{"name":"bmealey","email":"blakemealey@gmail.com"},"directories":{},"maintainers":[{"name":"bmealey","email":"blakemealey@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/ansi-sequence-parser_1.1.3_1739114828593_0.045637607597390994"},"_hasShrinkwrap":false,"readme":"# `ansi-sequence-parser`\n\nParse ANSI escape sequences into a readable format for things like generating pretty HTML.\n\nInstall with your favourite package manager:\n\n```sh\npnpm install ansi-sequence-parser\nyarn add ansi-sequence-parser\nnpm install ansi-sequence-parser\n```\n\n## Parsing\n\nToken format:\n\n```ts\ninterface ParseToken {\n  // The text content of the token\n  value: string;\n  // The foreground color\n  foreground: Color | null;\n  // The background color\n  background: Color | null;\n  // A Set of the applied decorations\n  decorations: Set<DecorationType>;\n}\n```\n\nParse full input at once:\n\n```ts\nimport { parseAnsiSequences } from 'ansi-sequence-parser';\n\nconst tokens = parseAnsiSequences(input);\n```\n\nIf you want to parse your input in multiple chunks, make sure to create a parser so that you can maintain\nstate between chunks:\n\n```ts\nimport { createAnsiSequenceParser } from 'ansi-sequence-parser';\n\nconst parser = createAnsiSequenceParser();\n\nconst tokensByLine = input.split(/\\r?\\n/).map((line) => parser.parse(line));\n```\n\n## Colors\n\nColors format:\n\n```ts\n// A named ANSI color, e.g. `magenta` or `brightBlue`\nexport interface NamedColor {\n  type: 'named';\n  name: ColorName;\n}\n\n// A color-table lookup\nexport interface TableColor {\n  type: 'table';\n  index: number;\n}\n\n// An RGB color\nexport interface RgbColor {\n  type: 'rgb';\n  rgb: [number, number, number];\n}\n\nexport type Color = NamedColor | TableColor | RgbColor;\n```\n\nIn order to interpret all of the above color types as a hex code, you can create a color palette:\n\n```ts\nimport { parseAnsiSequences, createColorPalette } from 'ansi-sequence-parser';\n\nconst tokens = parseAnsiSequences(input);\nconst colorPalette = createColorPalette();\n\nfor (const token of tokens) {\n  if (token.foreground) {\n    const foregroundValue = colorPalette.value(token.foreground);\n  }\n  if (token.background) {\n    const backgroundValue = colorPalette.value(token.background);\n  }\n}\n```\n\nYou can also specify a custom named colors map:\n\n```ts\nimport { parseAnsiSequences, createColorPalette } from 'ansi-sequence-parser';\n\nconst tokens = parseAnsiSequences(input);\nconst colorPalette = createColorPalette({\n  black: '#000000',\n  red: '#bb0000',\n  green: '#00bb00',\n  yellow: '#bbbb00',\n  blue: '#0000bb',\n  magenta: '#ff00ff',\n  cyan: '#00bbbb',\n  white: '#eeeeee',\n  brightBlack: '#555555',\n  brightRed: '#ff5555',\n  brightGreen: '#00ff00',\n  brightYellow: '#ffff55',\n  brightBlue: '#5555ff',\n  brightMagenta: '#ff55ff',\n  brightCyan: '#55ffff',\n  brightWhite: '#ffffff',\n});\n```\n\nIf you want to modify the default named colors map, you can import the `defaultNamedColorsMap`:\n\n```ts\nimport {\n  parseAnsiSequences,\n  createColorPalette,\n  defaultNamedColorsMap,\n} from 'ansi-sequence-parser';\n\nconst tokens = parseAnsiSequences(input);\nconst colorPalette = createColorPalette({\n  ...defaultNamedColorsMap,\n  blue: '#0000cc',\n});\n```\n","publish_time":1739114828787,"_cnpm_publish_time":1739114828787,"dist-tags":{"latest":"1.1.3"}}