package/package.json 000644 0000001607 3560116604 011552 0 ustar 00 000000 000000 { "name": "turbocolor", "version": "2.6.1", "description": "Node.js library for colorizing text using ANSI escape sequences.", "main": "index.js", "types": "turbocolor.d.ts", "scripts": { "test": "nyc -r lcov testmatrix test/*.js", "release": "npm test && git commit -am $npm_package_version && git tag $npm_package_version && git push origin master && git push --tags && npm publish" }, "repository": { "type": "git", "url": "jorgebucaran/turbocolor" }, "files": [ "index.js", "turbocolor.d.ts" ], "keywords": [ "turbocolor", "terminal", "styles", "color", "ansi" ], "author": "Jorge Bucaran", "license": "MIT", "bugs": { "url": "https://github.com/jorgebucaran/turbocolor/issues" }, "homepage": "https://github.com/jorgebucaran/turbocolor", "devDependencies": { "nyc": "12.0.2", "testmatrix": "0.1.2" } } package/index.js 000644 0000004402 3560116604 010725 0 ustar 00 000000 000000 "use strict" const tc = { enabled: process.env.FORCE_COLOR || process.platform === "win32" || (process.stdout.isTTY && process.env.TERM && process.env.TERM !== "dumb") } const Styles = (tc.Styles = {}) const defineProp = Object.defineProperty const init = (style, open, close, re) => { let i, len = 1, seq = [(Styles[style] = { open, close, re })] const fn = s => { if (tc.enabled) { for (i = 0, s += ""; i < len; i++) { style = seq[i] s = (open = style.open) + (~s.indexOf((close = style.close), 4) // skip first \x1b[ ? s.replace(style.re, open) : s) + close } len = 1 } return s } defineProp(tc, style, { get: () => { for (let k in Styles) defineProp(fn, k, { get: () => ((seq[len++] = Styles[k]), fn) }) delete tc[style] return (tc[style] = fn) }, configurable: true }) } init("reset", "\x1b[0m", "\x1b[0m", /\x1b\[0m/g) init("bold", "\x1b[1m", "\x1b[22m", /\x1b\[22m/g) init("dim", "\x1b[2m", "\x1b[22m", /\x1b\[22m/g) init("italic", "\x1b[3m", "\x1b[23m", /\x1b\[23m/g) init("underline", "\x1b[4m", "\x1b[24m", /\x1b\[24m/g) init("inverse", "\x1b[7m", "\x1b[27m", /\x1b\[27m/g) init("hidden", "\x1b[8m", "\x1b[28m", /\x1b\[28m/g) init("strikethrough", "\x1b[9m", "\x1b[29m", /\x1b\[29m/g) init("black", "\x1b[30m", "\x1b[39m", /\x1b\[39m/g) init("red", "\x1b[31m", "\x1b[39m", /\x1b\[39m/g) init("green", "\x1b[32m", "\x1b[39m", /\x1b\[39m/g) init("yellow", "\x1b[33m", "\x1b[39m", /\x1b\[39m/g) init("blue", "\x1b[34m", "\x1b[39m", /\x1b\[39m/g) init("magenta", "\x1b[35m", "\x1b[39m", /\x1b\[39m/g) init("cyan", "\x1b[36m", "\x1b[39m", /\x1b\[39m/g) init("white", "\x1b[37m", "\x1b[39m", /\x1b\[39m/g) init("gray", "\x1b[90m", "\x1b[39m", /\x1b\[39m/g) init("bgBlack", "\x1b[40m", "\x1b[49m", /\x1b\[49m/g) init("bgRed", "\x1b[41m", "\x1b[49m", /\x1b\[49m/g) init("bgGreen", "\x1b[42m", "\x1b[49m", /\x1b\[49m/g) init("bgYellow", "\x1b[43m", "\x1b[49m", /\x1b\[49m/g) init("bgBlue", "\x1b[44m", "\x1b[49m", /\x1b\[49m/g) init("bgMagenta", "\x1b[45m", "\x1b[49m", /\x1b\[49m/g) init("bgCyan", "\x1b[46m", "\x1b[49m", /\x1b\[49m/g) init("bgWhite", "\x1b[47m", "\x1b[49m", /\x1b\[49m/g) module.exports = tc package/LICENSE.md 000644 0000002113 3560116604 010661 0 ustar 00 000000 000000 Copyright © 2015-present [Jorge Bucaran](https://github.com/jorgebucaran) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. package/README.md 000644 0000007446 3560116604 010552 0 ustar 00 000000 000000 # Turbocolor [](https://travis-ci.org/jorgebucaran/turbocolor) [](https://codecov.io/gh/jorgebucaran/turbocolor) [](https://www.npmjs.org/package/turbocolor) Turbocolor is a Node.js library for colorizing text using [ANSI escape sequences](https://en.wikipedia.org/wiki/ANSI_escape_code). ## Features - No dependencies - [Toggle color support](#color-support) on/off as needed - Use it as a drop-in replacement for [chalk](https://github.com/chalk/chalk), [ansi-colors](https://github.com/doowb/ansi-colors), [kleur](https://github.com/lukeed/kleur) - Need for speed? Turbocolor is the [_fastest_](#benchmarks) terminal colorizer for Node.js ## Installation
npm i turbocolor## Usage ```jsx const tc = require("turbocolor") ``` Using styles. ```jsx console.log(tc.red("Hello!")) ``` Chaining styles. ```jsx console.log(tc.red.bold("Turbo") + tc.bgRed.white("Color")) ``` Using [template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals). ```jsx console.log(` ${tc.bold("Score")}: ${100} Lives: ${tc.red.inverse(1)} Level: ${tc.bgCyan.black.inverse(2)} `) ``` Nesting styles. ```jsx console.log(`Normal ${tc.bold(`Bold ${tc.red("Bold/Red")} Bold`)} Normal`) ``` Using console.log [string substitution](https://nodejs.org/api/console.html#console_console_log_data_args). ```jsx console.log(tc.green("Total: $%f"), 1.99) ``` ## API ### tc.style[.style...](string) Every [style](#tc-styles) function can be chained or nested with one another and when invoked, will return the given string argument wrapped in the corresponding ANSI escape codes. Style precedence is determined by chaining order in a first-come, first-served basis. This means that `tc.red.green.blue` is reduced to `tc.red`. ### tc.Styles Turbocolor exports ANSI escape codes for each available style. Use them if you want to stylize console output manually. ```jsx const { Styles } = require("turbocolor") console.log(`${Styles.red.open}Red${Styles.red.close}`) ``` ### tc.enabled Color support is automatically enabled if your terminal supports it, but you can toggle it on/off as needed. ```js const tc = require("turbocolor") tc.enabled = false ``` ## Styles Turbocolor only supports the regular color set at the moment. If you want to use the high intensity variations or need 256 color/Truecolor support, please use [chalk](https://github.com/chalk/chalk) instead. | Colors | Background Colors | Modifiers | | ------- | ----------------- | ----------------- | | black | bgBlack | dim | | red | bgRed | **bold** | | green | bgGreen | hidden | | yellow | bgYellow | _italic_ | | blue | bgBlue | underline | | magenta | bgMagenta | inverse | | cyan | bgCyan | ~~strikethrough~~ | | white | bgWhite | reset | | gray | | | ## Benchmark Results All tests run on a 2.4GHz Intel Core i7 CPU with 16 GB memory. ``` npm i -C bench && node bench ```
# Using Styles chalk × 8,510 ops/sec kleur × 298,812 ops/sec ansi-colors × 299,145 ops/sec turbocolor × 606,180 ops/sec # Chaining Styles chalk × 1,881 ops/sec kleur × 43,187 ops/sec ansi-colors × 22,549 ops/sec turbocolor × 58,745 ops/sec # Nesting Styles chalk × 12,449 ops/sec kleur × 183,384 ops/sec ansi-colors × 123,488 ops/sec turbocolor × 197,616 ops/sec## License Turbocolor is MIT licensed. See [LICENSE](LICENSE.md). package/turbocolor.d.ts 000644 0000003366 3560116604 012254 0 ustar 00 000000 000000 interface Turbocolor { reset: Style bold: Style dim: Style italic: Style underline: Style inverse: Style hidden: Style strikethrough: Style black: Style red: Style green: Style yellow: Style blue: Style magenta: Style cyan: Style white: Style gray: Style bgBlack: Style bgRed: Style bgGreen: Style bgYellow: Style bgBlue: Style bgMagenta: Style bgCyan: Style bgWhite: Style } interface Style extends Turbocolor { (string: string): string } export const reset: Style export const bold: Style export const dim: Style export const italic: Style export const underline: Style export const inverse: Style export const hidden: Style export const strikethrough: Style export const black: Style export const red: Style export const green: Style export const yellow: Style export const blue: Style export const magenta: Style export const cyan: Style export const white: Style export const gray: Style export const bgBlack: Style export const bgRed: Style export const bgGreen: Style export const bgYellow: Style export const bgBlue: Style export const bgMagenta: Style export const bgCyan: Style export const bgWhite: Style interface StyleCode { open: string close: string } export const Styles: { reset: StyleCode bold: StyleCode dim: StyleCode italic: StyleCode underline: StyleCode inverse: StyleCode hidden: StyleCode strikethrough: StyleCode black: StyleCode red: StyleCode green: StyleCode yellow: StyleCode blue: StyleCode magenta: StyleCode cyan: StyleCode white: StyleCode gray: StyleCode bgBlack: StyleCode bgRed: StyleCode bgGreen: StyleCode bgYellow: StyleCode bgBlue: StyleCode bgMagenta: StyleCode bgCyan: StyleCode bgWhite: StyleCode } export let enabled: boolean