{"_id":"prismjs-terminal","_rev":"4063370","name":"prismjs-terminal","description":"PrismaJS syntax highlighting for the terminal","dist-tags":{"latest":"1.2.3"},"maintainers":[{"name":"isaacs","email":""}],"time":{"modified":"2025-09-24T04:26:45.000Z","created":"2023-06-04T17:35:29.389Z","1.2.3":"2023-09-15T19:07:33.752Z","1.2.2":"2023-06-17T18:18:13.726Z","1.2.1":"2023-06-04T22:16:38.293Z","1.2.0":"2023-06-04T19:00:54.841Z","1.0.0":"2023-06-04T17:35:29.389Z"},"users":{},"author":{"name":"Isaac Z. Schlueter","email":"i@izs.me","url":"https://blog.izs.me"},"repository":{"type":"git","url":"git+https://github.com/isaacs/prismajs-terminal.git"},"versions":{"1.2.3":{"name":"prismjs-terminal","version":"1.2.3","description":"PrismaJS syntax highlighting for the terminal","keywords":["terminal","code","syntax","highlight","highlighter","highlighting","hilite","cli"],"author":{"name":"Isaac Z. Schlueter","email":"i@izs.me","url":"https://blog.izs.me"},"type":"module","module":"./dist/index.js","exports":{"./package.json":{"import":"./package.json","require":"./package.json"},".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"./themes":{"import":{"types":"./dist/themes/index.d.ts","default":"./dist/themes/index.js"}}},"license":"BlueOak-1.0.0","scripts":{"preversion":"npm test","postversion":"npm publish","prepublishOnly":"git push origin --follow-tags","prepare":"tsc && bash ./scripts/fixup.sh","pretest":"npm run prepare","presnap":"npm run prepare","test":"c8 tap","snap":"c8 tap","format":"prettier --write . --loglevel warn","typedoc":"typedoc ./src/*.ts"},"prettier":{"semi":false,"printWidth":75,"tabWidth":2,"useTabs":false,"singleQuote":true,"jsxSingleQuote":false,"bracketSameLine":true,"arrowParens":"avoid","endOfLine":"lf"},"tap":{"color":true,"coverage":false,"test-env":["FORCE_COLOR=3"],"test-arg":["--color=full"],"node-arg":["--no-warnings","--loader","ts-node/esm"],"ts":false},"devDependencies":{"@types/node":"^20.1.5","@types/prismjs":"^1.26.0","@types/tap":"^15.0.8","c8":"^7.14.0","prettier":"^2.8.6","tap":"16","ts-node":"^10.9.1","typedoc":"^0.24.7","typescript":"^5.0.2"},"engines":{"node":">=16"},"funding":{"url":"https://github.com/sponsors/isaacs"},"repository":{"type":"git","url":"git+https://github.com/isaacs/prismajs-terminal.git"},"dependencies":{"chalk":"^5.2.0","prismjs":"^1.29.0","string-length":"^6.0.0"},"_id":"prismjs-terminal@1.2.3","gitHead":"c38a20966908e669ef8da17981b17e0dc5659717","bugs":{"url":"https://github.com/isaacs/prismajs-terminal/issues"},"homepage":"https://github.com/isaacs/prismajs-terminal#readme","_nodeVersion":"20.6.1","_npmVersion":"9.8.1","dist":{"shasum":"ece78c1c19fe73694ca609a7aee2b3d4de926d4c","size":16932,"noattachment":false,"key":"/prismjs-terminal/-/prismjs-terminal-1.2.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/prismjs-terminal/download/prismjs-terminal-1.2.3.tgz"},"_npmUser":{"name":"isaacs","email":"i@izs.me"},"directories":{},"maintainers":[{"name":"isaacs","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/prismjs-terminal_1.2.3_1694804853508_0.8465920779173295"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2023-09-15T19:07:33.752Z","publish_time":1694804853752,"_source_registry_name":"default","_cnpm_publish_time":1694804853752},"1.2.2":{"name":"prismjs-terminal","version":"1.2.2","description":"PrismaJS syntax highlighting for the terminal","keywords":["terminal","code","syntax","highlight","highlighter","highlighting","hilite","cli"],"author":{"name":"Isaac Z. Schlueter","email":"i@izs.me","url":"https://blog.izs.me"},"type":"module","module":"./dist/index.js","exports":{"./package.json":{"import":"./package.json","require":"./package.json"},".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"./themes":{"import":{"types":"./dist/themes/index.d.ts","default":"./dist/themes/index.js"}}},"license":"BlueOak-1.0.0","scripts":{"preversion":"npm test","postversion":"npm publish","prepublishOnly":"git push origin --follow-tags","prepare":"tsc && bash ./scripts/fixup.sh","pretest":"npm run prepare","presnap":"npm run prepare","test":"c8 tap","snap":"c8 tap","format":"prettier --write . --loglevel warn","typedoc":"typedoc ./src/*.ts"},"prettier":{"semi":false,"printWidth":75,"tabWidth":2,"useTabs":false,"singleQuote":true,"jsxSingleQuote":false,"bracketSameLine":true,"arrowParens":"avoid","endOfLine":"lf"},"tap":{"color":true,"coverage":false,"test-env":["FORCE_COLOR=3"],"test-arg":["--color=full"],"node-arg":["--no-warnings","--loader","ts-node/esm"],"ts":false},"devDependencies":{"@types/node":"^20.1.5","@types/prismjs":"^1.26.0","@types/tap":"^15.0.8","c8":"^7.14.0","prettier":"^2.8.6","tap":"16","ts-node":"^10.9.1","typedoc":"^0.24.7","typescript":"^5.0.2"},"engines":{"node":">=16"},"funding":{"url":"https://github.com/sponsors/isaacs"},"repository":{"type":"git","url":"git+https://github.com/isaacs/prismajs-terminal.git"},"dependencies":{"chalk":"^5.2.0","prismjs":"^1.29.0","string-length":"^6.0.0"},"gitHead":"a1934e83bb45dc98242c576f5b5d3d2a1eb890fe","bugs":{"url":"https://github.com/isaacs/prismajs-terminal/issues"},"homepage":"https://github.com/isaacs/prismajs-terminal#readme","_id":"prismjs-terminal@1.2.2","_nodeVersion":"18.16.0","_npmVersion":"9.5.1","dist":{"shasum":"1a8bb26e60fd4c5baf89ed6287def6ba50d75cd7","size":16821,"noattachment":false,"key":"/prismjs-terminal/-/prismjs-terminal-1.2.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/prismjs-terminal/download/prismjs-terminal-1.2.2.tgz"},"_npmUser":{"name":"isaacs","email":"i@izs.me"},"directories":{},"maintainers":[{"name":"isaacs","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/prismjs-terminal_1.2.2_1687025893526_0.4772362455491117"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2023-06-17T18:18:13.726Z","publish_time":1687025893726,"_source_registry_name":"default","_cnpm_publish_time":1687025893726},"1.2.1":{"name":"prismjs-terminal","version":"1.2.1","description":"PrismaJS syntax highlighting for the terminal","keywords":["terminal","code","syntax","highlight","highlighter","highlighting","hilite","cli"],"author":{"name":"Isaac Z. Schlueter","email":"i@izs.me","url":"https://blog.izs.me"},"type":"module","module":"./dist/index.js","exports":{"./package.json":{"import":"./package.json","require":"./package.json"},".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"./themes":{"import":{"types":"./dist/themes/index.d.ts","default":"./dist/themes/index.js"}}},"license":"BlueOak-1.0.0","scripts":{"preversion":"npm test","postversion":"npm publish","prepublishOnly":"git push origin --follow-tags","prepare":"tsc && bash ./scripts/fixup.sh","pretest":"npm run prepare","presnap":"npm run prepare","test":"c8 tap","snap":"c8 tap","format":"prettier --write . --loglevel warn","typedoc":"typedoc ./src/*.ts"},"prettier":{"semi":false,"printWidth":75,"tabWidth":2,"useTabs":false,"singleQuote":true,"jsxSingleQuote":false,"bracketSameLine":true,"arrowParens":"avoid","endOfLine":"lf"},"tap":{"color":true,"coverage":false,"test-env":["FORCE_COLOR=3"],"test-arg":["--color=full"],"node-arg":["--no-warnings","--loader","ts-node/esm"],"ts":false},"devDependencies":{"@types/node":"^20.1.5","@types/prismjs":"^1.26.0","@types/tap":"^15.0.8","c8":"^7.14.0","prettier":"^2.8.6","tap":"16","ts-node":"^10.9.1","typedoc":"^0.24.7","typescript":"^5.0.2"},"engines":{"node":">=16"},"funding":{"url":"https://github.com/sponsors/isaacs"},"repository":{"type":"git","url":"git+https://github.com/isaacs/prismajs-terminal.git"},"dependencies":{"chalk":"^5.2.0","prismjs":"^1.29.0","string-length":"^5.0.1"},"gitHead":"96b16e6255df806a788d9dbca4186da5f9e674cf","bugs":{"url":"https://github.com/isaacs/prismajs-terminal/issues"},"homepage":"https://github.com/isaacs/prismajs-terminal#readme","_id":"prismjs-terminal@1.2.1","_nodeVersion":"18.16.0","_npmVersion":"9.6.7","dist":{"shasum":"eeb0cea18601d6b161fee65e83baadede0a86e88","size":16819,"noattachment":false,"key":"/prismjs-terminal/-/prismjs-terminal-1.2.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/prismjs-terminal/download/prismjs-terminal-1.2.1.tgz"},"_npmUser":{"name":"isaacs","email":"i@izs.me"},"directories":{},"maintainers":[{"name":"isaacs","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/prismjs-terminal_1.2.1_1685916998042_0.11213063536386847"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2023-06-04T22:16:38.293Z","publish_time":1685916998293,"_source_registry_name":"default","_cnpm_publish_time":1685916998293},"1.2.0":{"name":"prismjs-terminal","version":"1.2.0","description":"PrismaJS syntax highlighting for the terminal","keywords":["terminal","code","syntax","highlight","highlighter","highlighting","hilite","cli"],"author":{"name":"Isaac Z. Schlueter","email":"i@izs.me","url":"https://blog.izs.me"},"type":"module","module":"./dist/index.js","exports":{"./package.json":{"import":"./package.json","require":"./package.json"},".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"./themes":{"import":{"types":"./dist/themes/index.d.ts","default":"./dist/themes/index.js"}}},"license":"BlueOak-1.0.0","scripts":{"preversion":"npm test","postversion":"npm publish","prepublishOnly":"git push origin --follow-tags","prepare":"tsc && bash ./scripts/fixup.sh","pretest":"npm run prepare","presnap":"npm run prepare","test":"c8 tap","snap":"c8 tap","format":"prettier --write . --loglevel warn","typedoc":"typedoc --tsconfig tsconfig-esm.json ./src/*.ts"},"prettier":{"semi":false,"printWidth":75,"tabWidth":2,"useTabs":false,"singleQuote":true,"jsxSingleQuote":false,"bracketSameLine":true,"arrowParens":"avoid","endOfLine":"lf"},"tap":{"color":true,"coverage":false,"test-env":["FORCE_COLOR=3"],"test-arg":["--color=full"],"node-arg":["--no-warnings","--loader","ts-node/esm"],"ts":false},"devDependencies":{"@types/node":"^20.1.5","@types/prismjs":"^1.26.0","@types/tap":"^15.0.8","c8":"^7.14.0","prettier":"^2.8.6","tap":"16","ts-node":"^10.9.1","typedoc":"^0.24.7","typescript":"^5.0.2"},"engines":{"node":">=14"},"funding":{"url":"https://github.com/sponsors/isaacs"},"repository":{"type":"git","url":"git+https://github.com/isaacs/prismajs-term.git"},"dependencies":{"chalk":"^5.2.0","prismjs":"^1.29.0","string-length":"^5.0.1"},"gitHead":"7ec32d183f9d71a2b2c68a68a8cff751e4dcf247","bugs":{"url":"https://github.com/isaacs/prismajs-term/issues"},"homepage":"https://github.com/isaacs/prismajs-term#readme","_id":"prismjs-terminal@1.2.0","_nodeVersion":"18.16.0","_npmVersion":"9.6.7","dist":{"shasum":"ac9fb5ca4bdcea32e8e6da30aeda7becee1c9b72","size":15823,"noattachment":false,"key":"/prismjs-terminal/-/prismjs-terminal-1.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/prismjs-terminal/download/prismjs-terminal-1.2.0.tgz"},"_npmUser":{"name":"isaacs","email":"i@izs.me"},"directories":{},"maintainers":[{"name":"isaacs","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/prismjs-terminal_1.2.0_1685905254655_0.13698757582138166"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2023-06-04T19:00:54.841Z","publish_time":1685905254841,"_source_registry_name":"default","_cnpm_publish_time":1685905254841},"1.0.0":{"name":"prismjs-terminal","version":"1.0.0","description":"PrismaJS syntax highlighting for the terminal","keywords":["terminal","code","syntax","highlight","highlighter","highlighting","hilite","cli"],"author":{"name":"Isaac Z. Schlueter","email":"i@izs.me","url":"https://blog.izs.me"},"type":"module","module":"./dist/index.js","exports":{"./package.json":{"import":"./package.json","require":"./package.json"},".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"./themes":{"import":{"types":"./dist/themes/index.d.ts","default":"./dist/themes/index.js"}}},"license":"BlueOak-1.0.0","scripts":{"preversion":"npm test","postversion":"npm publish","prepublishOnly":"git push origin --follow-tags","prepare":"tsc && bash ./scripts/fixup.sh","pretest":"npm run prepare","presnap":"npm run prepare","test":"c8 tap","snap":"c8 tap","format":"prettier --write . --loglevel warn","typedoc":"typedoc --tsconfig tsconfig-esm.json ./src/*.ts"},"prettier":{"semi":false,"printWidth":75,"tabWidth":2,"useTabs":false,"singleQuote":true,"jsxSingleQuote":false,"bracketSameLine":true,"arrowParens":"avoid","endOfLine":"lf"},"tap":{"color":true,"coverage":false,"test-env":["FORCE_COLOR=3"],"test-arg":["--color=full"],"node-arg":["--no-warnings","--loader","ts-node/esm"],"ts":false},"devDependencies":{"@types/node":"^20.1.5","@types/prismjs":"^1.26.0","@types/tap":"^15.0.8","c8":"^7.14.0","prettier":"^2.8.6","tap":"16","ts-node":"^10.9.1","typedoc":"^0.24.7","typescript":"^5.0.2"},"engines":{"node":">=14"},"funding":{"url":"https://github.com/sponsors/isaacs"},"repository":{"type":"git","url":"git+https://github.com/isaacs/prismajs-term.git"},"dependencies":{"chalk":"^5.2.0","prismjs":"^1.29.0","string-length":"^5.0.1"},"gitHead":"e8b9501d138d128ef1cae190ce736a79c603bb1d","bugs":{"url":"https://github.com/isaacs/prismajs-term/issues"},"homepage":"https://github.com/isaacs/prismajs-term#readme","_id":"prismjs-terminal@1.0.0","_nodeVersion":"18.16.0","_npmVersion":"9.6.7","dist":{"shasum":"9ce069bafe4d19af0c351d9dfa5cb3e1e01d9cbc","size":15284,"noattachment":false,"key":"/prismjs-terminal/-/prismjs-terminal-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/prismjs-terminal/download/prismjs-terminal-1.0.0.tgz"},"_npmUser":{"name":"isaacs","email":"i@izs.me"},"directories":{},"maintainers":[{"name":"isaacs","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/prismjs-terminal_1.0.0_1685900129187_0.5178668973962761"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2023-06-04T17:35:29.389Z","publish_time":1685900129389,"_source_registry_name":"default","_cnpm_publish_time":1685900129389}},"readme":"# prismjs-terminal\n\n[PrismJS](https://prismjs.com), but for terminal output.\n\n## USAGE\n\n```js\n// ESM only, sorry, blame chalk\n// But less reason to use CommonJS for new CLI apps anyway\nimport { highlight } from 'prismjs-terminal'\n\n// get some code somehow\nimport { readFileSync } from 'fs'\nconst code = readFileSync('some-file.ts', 'utf8')\n\n// highlight it\nconsole.log(highlight(code, 'typescript'))\n```\n\n## Custom Themes\n\nInstead of CSS, themes are defined using an object with\nstyling functions that take a string and return a string.\n\nThe `_` style rule applies to the block as a whole, and is used\nas the default style. This is where you'd usually port a PrismJS\ntheme's `code[class*=\"language-\"]` css rule.\n\nThe `lineNumber` style rule will apply to line numbers, if they\nare used.\n\nThe semantics are similar to CSS, where a nested property will be\napplied to nodes within that nesting stack with a higher\npriority the more tags that match, and later rules taking\nprecedence over earlier ones. It's _not_ a full CSS selector\nsyntax though, so things like `.token.italic.bold` aren't\nsupported. Just individual token class names, possibly nested.\nAlso, chalk is not CSS, and a terminal is not a browser, so\nthere are some differences and limitations of course.\n\nAliases are also not supported, styles have to be applied to the\nactual parsed class names PrismJS provides.\n\nFor example:\n\n```js\nimport { defaultTheme, Theme } from 'prismjs-terminal'\nimport chalk from 'chalk'\nconst theme: Theme = {\n  // any (s:string)=>string function is allowed\n  comment: chalk.hex('#d75fff').italic,\n\n  // can provide multiple functions, which is useful if they\n  // aren't chainable chalk methods\n  function: [chalk.hex('#f08'), s => ` >${s}< `],\n\n  // nest by separating with a space\n  // will turn `/abc/gm` into:\n  // chalk.bold('/' + chalk.green('abc') + '/' + chalk.blue('gm'))\n  regex: chalk.bold,\n  'regex regex-source': chalk.green,\n  'regex regex-flags': chalk.blue,\n\n  // apply one style to multiple token names by separating with `,`\n  'string, number': chalk.green,\n\n  // See the defaultTheme export for more examples.\n}\nconsole.log(highlight(code, 'typescript', { theme }))\n\n// can also use one of the included ones\nconsole.log(highlight(code, 'typescript', { theme: 'xonokai' }))\n```\n\nSee [the themes directory in this repo](./themes) for more\nexamples.\n\n## API\n\n- interface `PrismJSTerminalOpts`\n\n  - `theme` The theme to use. Either a Theme object, or a\n    string identifying one of the built-in themes. Defaults to\n    `'moria'`.\n  - `language` The language of the supplied code to highlight.\n    Defaults to `tsx` if no filename is provided, or else\n    tries to infer the language from the filename. You must\n    have previously called `loadLanguages([...])` from\n    `PrismJS` in order to highlight a given language, if you\n    want something that is not automatically included when\n    `tsx` and `typescript` are included.\n  - `minWidth` The minimum width to make the block on the\n    screen. Defaults to `0`.\n  - `maxWidth` The maximum width to make the block on the\n    screen. Defaults to `process.stdout.columns` or `80`.\n  - `padding` How many spaces to horizontally pad the code\n    block. Defaults to `1`.\n  - `lineNumbers` Whether or not to prepend a line number to each\n    line. Defaults to `false`.\n\n- `highlight(code: string, opts?: PrismJSTerminalOpts): string`\n\n  Highlight the string of code provided, returning the string of\n  highlighted code.\n\n- `highlightFile(filename: string, opts?: PrismJSTerminalOpts): Promise<string>`\n\n  Read the filename provided, and highlight its code. If a\n  language is not provided in the opts, it will attempt to infer\n  from the filename.\n\n- `highlightFileSync(filename: string, opts?: PrismJSTerminalOpts): string`\n\n  Synchronous `highlightFile`.\n\n- Themes:\n\n  More are welcome! If you have a PrismJS theme you like, do\n  send a PR. Of course not everything translates, but it's quite\n  straightforward to take a PrismJS CSS file and turn all the\n  `color: #...` lines into `chalk.hex('#...')` calls.\n\n  Theme objects can be either a Map or object where the keys are\n  the selectors and the values are either a styling function or\n  an array of styling functions to be applied in order.\n\n  - `debug` This just dumps the code wrapped in `<tag>...</tag>`\n    to see what the token names are. Useful for tests and such.\n  - `plain` No styling, just the code as plain text.\n  - `github` Port of GHColors prismjs theme.\n  - `moria` Inspired by Vim Moria color scheme.\n  - `prismDark` Port of the `prism-dark` PrismJS theme.\n  - `xonokai` Port of the `xonokai` PrismJS theme.\n","_attachments":{},"homepage":"https://github.com/isaacs/prismajs-terminal#readme","bugs":{"url":"https://github.com/isaacs/prismajs-terminal/issues"},"license":"BlueOak-1.0.0"}