8889841cindex.js000066600000006465150514454670006243 0ustar00import * as tty from "tty" const { env = {}, argv = [], platform = "", } = typeof process === "undefined" ? {} : process const isDisabled = "NO_COLOR" in env || argv.includes("--no-color") const isForced = "FORCE_COLOR" in env || argv.includes("--color") const isWindows = platform === "win32" const isDumbTerminal = env.TERM === "dumb" const isCompatibleTerminal = tty && tty.isatty && tty.isatty(1) && env.TERM && !isDumbTerminal const isCI = "CI" in env && ("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env) export const isColorSupported = !isDisabled && (isForced || (isWindows && !isDumbTerminal) || isCompatibleTerminal || isCI) const replaceClose = ( index, string, close, replace, head = string.substring(0, index) + replace, tail = string.substring(index + close.length), next = tail.indexOf(close) ) => head + (next < 0 ? tail : replaceClose(next, tail, close, replace)) const clearBleed = (index, string, open, close, replace) => index < 0 ? open + string + close : open + replaceClose(index, string, close, replace) + close const filterEmpty = (open, close, replace = open, at = open.length + 1) => (string) => string || !(string === "" || string === undefined) ? clearBleed( ("" + string).indexOf(close, at), string, open, close, replace ) : "" const init = (open, close, replace) => filterEmpty(`\x1b[${open}m`, `\x1b[${close}m`, replace) const colors = { reset: init(0, 0), bold: init(1, 22, "\x1b[22m\x1b[1m"), dim: init(2, 22, "\x1b[22m\x1b[2m"), italic: init(3, 23), underline: init(4, 24), inverse: init(7, 27), hidden: init(8, 28), strikethrough: init(9, 29), black: init(30, 39), red: init(31, 39), green: init(32, 39), yellow: init(33, 39), blue: init(34, 39), magenta: init(35, 39), cyan: init(36, 39), white: init(37, 39), gray: init(90, 39), bgBlack: init(40, 49), bgRed: init(41, 49), bgGreen: init(42, 49), bgYellow: init(43, 49), bgBlue: init(44, 49), bgMagenta: init(45, 49), bgCyan: init(46, 49), bgWhite: init(47, 49), blackBright: init(90, 39), redBright: init(91, 39), greenBright: init(92, 39), yellowBright: init(93, 39), blueBright: init(94, 39), magentaBright: init(95, 39), cyanBright: init(96, 39), whiteBright: init(97, 39), bgBlackBright: init(100, 49), bgRedBright: init(101, 49), bgGreenBright: init(102, 49), bgYellowBright: init(103, 49), bgBlueBright: init(104, 49), bgMagentaBright: init(105, 49), bgCyanBright: init(106, 49), bgWhiteBright: init(107, 49), } export const createColors = ({ useColor = isColorSupported } = {}) => useColor ? colors : Object.keys(colors).reduce( (colors, key) => ({ ...colors, [key]: String }), {} ) export const { reset, bold, dim, italic, underline, inverse, hidden, strikethrough, black, red, green, yellow, blue, magenta, cyan, white, gray, bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite, blackBright, redBright, greenBright, yellowBright, blueBright, magentaBright, cyanBright, whiteBright, bgBlackBright, bgRedBright, bgGreenBright, bgYellowBright, bgBlueBright, bgMagentaBright, bgCyanBright, bgWhiteBright, } = createColors() README.md000066600000010150150514454670006037 0ustar00# 🌈Colorette > Easily set your terminal text color & styles. - No dependecies - Automatic color support detection - Up to [2x faster](#benchmarks) than alternatives - TypeScript support - [`NO_COLOR`](https://no-color.org) friendly - Node >= `10` > [**Upgrading from Colorette `1.x`?**](https://github.com/jorgebucaran/colorette/issues/70) ## Quickstart ```js import { blue, bold, underline } from "colorette" console.log( blue("I'm blue"), bold(blue("da ba dee")), underline(bold(blue("da ba daa"))) ) ``` Here's an example using [template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals). ```js console.log(` There's a ${underline(blue("house"))}, With a ${bold(blue("window"))}, And a ${blue("corvette")} And everything is blue `) ``` You can also nest styles without breaking existing color sequences. ```js console.log(bold(`I'm ${blue(`da ba ${underline("dee")} da ba`)} daa`)) ``` Need to override terminal color detection? You can do that too. ```js import { createColors } from "colorette" const { blue } = createColors({ useColor: false }) console.log(blue("Blue? Nope, nah")) ``` ## Installation ```console npm install colorette ``` ## API ### \() > See all [supported colors](#supported-colors). ```js import { blue } from "colorette" blue("I'm blue") //=> \x1b[34mI'm blue\x1b[39m ``` ### createColors() Override terminal color detection via `createColors({ useColor })`. ```js import { createColors } from "colorette" const { blue } = createColors({ useColor: false }) ``` ### isColorSupported `true` if your terminal supports color, `false` otherwise. Used internally, but exposed for convenience. ## Environment You can override color detection from the CLI by setting the `--no-color` or `--color` flags. ```console $ ./example.js --no-color | ./consumer.js ``` Or if you can't use CLI flags, by setting the `NO_COLOR=` or `FORCE_COLOR=` environment variables. ```console $ NO_COLOR= ./example.js | ./consumer.js ``` ## Supported colors | Colors | Background Colors | Bright Colors | Bright Background Colors | Modifiers | | ------- | ----------------- | ------------- | ------------------------ | ----------------- | | black | bgBlack | blackBright | bgBlackBright | dim | | red | bgRed | redBright | bgRedBright | **bold** | | green | bgGreen | greenBright | bgGreenBright | hidden | | yellow | bgYellow | yellowBright | bgYellowBright | _italic_ | | blue | bgBlue | blueBright | bgBlueBright | underline | | magenta | bgMagenta | magentaBright | bgMagentaBright | ~~strikethrough~~ | | cyan | bgCyan | cyanBright | bgCyanBright | reset | | white | bgWhite | whiteBright | bgWhiteBright | | | gray | | | | | ## [Benchmarks](https://github.com/jorgebucaran/colorette/actions/workflows/bench.yml) ```console npm --prefix bench start ``` ```diff chalk 1,786,703 ops/sec kleur 1,618,960 ops/sec colors 646,823 ops/sec ansi-colors 786,149 ops/sec picocolors 2,871,758 ops/sec + colorette 3,002,751 ops/sec ``` ## Acknowledgments Colorette started out in 2015 by [@jorgebucaran](https://github.com/jorgebucaran) as a lightweight alternative to [Chalk](https://github.com/chalk/chalk) and was introduced originally as [Clor](https://github.com/jorgebucaran/colorette/commit/b01b5b9961ceb7df878583a3002e836fae9e37ce). Our terminal color detection logic borrows heavily from [@sindresorhus](https://github.com/sindresorhus) and [@Qix-](https://github.com/Qix-) work on Chalk. The idea of slicing strings to clear bleeding sequences was adapted from a similar technique used by [@alexeyraspopov](https://github.com/alexeyraspopov) in [picocolors](https://github.com/alexeyraspopov/picocolors). Thank you to all our contributors! <3 ## License [MIT](LICENSE.md) LICENSE.md000066600000002070150514454670006166 0ustar00Copyright © Jorge Bucaran <> 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. index.cjs000066600000012242150514454670006374 0ustar00'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var tty = require('tty'); function _interopNamespace(e) { if (e && e.__esModule) return e; var n = Object.create(null); if (e) { Object.keys(e).forEach(function (k) { if (k !== 'default') { var d = Object.getOwnPropertyDescriptor(e, k); Object.defineProperty(n, k, d.get ? d : { enumerable: true, get: function () { return e[k]; } }); } }); } n["default"] = e; return Object.freeze(n); } var tty__namespace = /*#__PURE__*/_interopNamespace(tty); const { env = {}, argv = [], platform = "", } = typeof process === "undefined" ? {} : process; const isDisabled = "NO_COLOR" in env || argv.includes("--no-color"); const isForced = "FORCE_COLOR" in env || argv.includes("--color"); const isWindows = platform === "win32"; const isDumbTerminal = env.TERM === "dumb"; const isCompatibleTerminal = tty__namespace && tty__namespace.isatty && tty__namespace.isatty(1) && env.TERM && !isDumbTerminal; const isCI = "CI" in env && ("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env); const isColorSupported = !isDisabled && (isForced || (isWindows && !isDumbTerminal) || isCompatibleTerminal || isCI); const replaceClose = ( index, string, close, replace, head = string.substring(0, index) + replace, tail = string.substring(index + close.length), next = tail.indexOf(close) ) => head + (next < 0 ? tail : replaceClose(next, tail, close, replace)); const clearBleed = (index, string, open, close, replace) => index < 0 ? open + string + close : open + replaceClose(index, string, close, replace) + close; const filterEmpty = (open, close, replace = open, at = open.length + 1) => (string) => string || !(string === "" || string === undefined) ? clearBleed( ("" + string).indexOf(close, at), string, open, close, replace ) : ""; const init = (open, close, replace) => filterEmpty(`\x1b[${open}m`, `\x1b[${close}m`, replace); const colors = { reset: init(0, 0), bold: init(1, 22, "\x1b[22m\x1b[1m"), dim: init(2, 22, "\x1b[22m\x1b[2m"), italic: init(3, 23), underline: init(4, 24), inverse: init(7, 27), hidden: init(8, 28), strikethrough: init(9, 29), black: init(30, 39), red: init(31, 39), green: init(32, 39), yellow: init(33, 39), blue: init(34, 39), magenta: init(35, 39), cyan: init(36, 39), white: init(37, 39), gray: init(90, 39), bgBlack: init(40, 49), bgRed: init(41, 49), bgGreen: init(42, 49), bgYellow: init(43, 49), bgBlue: init(44, 49), bgMagenta: init(45, 49), bgCyan: init(46, 49), bgWhite: init(47, 49), blackBright: init(90, 39), redBright: init(91, 39), greenBright: init(92, 39), yellowBright: init(93, 39), blueBright: init(94, 39), magentaBright: init(95, 39), cyanBright: init(96, 39), whiteBright: init(97, 39), bgBlackBright: init(100, 49), bgRedBright: init(101, 49), bgGreenBright: init(102, 49), bgYellowBright: init(103, 49), bgBlueBright: init(104, 49), bgMagentaBright: init(105, 49), bgCyanBright: init(106, 49), bgWhiteBright: init(107, 49), }; const createColors = ({ useColor = isColorSupported } = {}) => useColor ? colors : Object.keys(colors).reduce( (colors, key) => ({ ...colors, [key]: String }), {} ); const { reset, bold, dim, italic, underline, inverse, hidden, strikethrough, black, red, green, yellow, blue, magenta, cyan, white, gray, bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite, blackBright, redBright, greenBright, yellowBright, blueBright, magentaBright, cyanBright, whiteBright, bgBlackBright, bgRedBright, bgGreenBright, bgYellowBright, bgBlueBright, bgMagentaBright, bgCyanBright, bgWhiteBright, } = createColors(); exports.bgBlack = bgBlack; exports.bgBlackBright = bgBlackBright; exports.bgBlue = bgBlue; exports.bgBlueBright = bgBlueBright; exports.bgCyan = bgCyan; exports.bgCyanBright = bgCyanBright; exports.bgGreen = bgGreen; exports.bgGreenBright = bgGreenBright; exports.bgMagenta = bgMagenta; exports.bgMagentaBright = bgMagentaBright; exports.bgRed = bgRed; exports.bgRedBright = bgRedBright; exports.bgWhite = bgWhite; exports.bgWhiteBright = bgWhiteBright; exports.bgYellow = bgYellow; exports.bgYellowBright = bgYellowBright; exports.black = black; exports.blackBright = blackBright; exports.blue = blue; exports.blueBright = blueBright; exports.bold = bold; exports.createColors = createColors; exports.cyan = cyan; exports.cyanBright = cyanBright; exports.dim = dim; exports.gray = gray; exports.green = green; exports.greenBright = greenBright; exports.hidden = hidden; exports.inverse = inverse; exports.isColorSupported = isColorSupported; exports.italic = italic; exports.magenta = magenta; exports.magentaBright = magentaBright; exports.red = red; exports.redBright = redBright; exports.reset = reset; exports.strikethrough = strikethrough; exports.underline = underline; exports.white = white; exports.whiteBright = whiteBright; exports.yellow = yellow; exports.yellowBright = yellowBright; index.d.ts000066600000003774150514454670006477 0ustar00declare module "colorette" { type Color = (text: string | number) => string interface Colorette { reset: Color bold: Color dim: Color italic: Color underline: Color inverse: Color hidden: Color strikethrough: Color black: Color red: Color green: Color yellow: Color blue: Color magenta: Color cyan: Color white: Color gray: Color bgBlack: Color bgRed: Color bgGreen: Color bgYellow: Color bgBlue: Color bgMagenta: Color bgCyan: Color bgWhite: Color blackBright: Color redBright: Color greenBright: Color yellowBright: Color blueBright: Color magentaBright: Color cyanBright: Color whiteBright: Color bgBlackBright: Color bgRedBright: Color bgGreenBright: Color bgYellowBright: Color bgBlueBright: Color bgMagentaBright: Color bgCyanBright: Color bgWhiteBright: Color } const reset: Color const bold: Color const dim: Color const italic: Color const underline: Color const inverse: Color const hidden: Color const strikethrough: Color const black: Color const red: Color const green: Color const yellow: Color const blue: Color const magenta: Color const cyan: Color const white: Color const gray: Color const bgBlack: Color const bgRed: Color const bgGreen: Color const bgYellow: Color const bgBlue: Color const bgMagenta: Color const bgCyan: Color const bgWhite: Color const blackBright: Color const redBright: Color const greenBright: Color const yellowBright: Color const blueBright: Color const magentaBright: Color const cyanBright: Color const whiteBright: Color const bgBlackBright: Color const bgRedBright: Color const bgGreenBright: Color const bgYellowBright: Color const bgBlueBright: Color const bgMagentaBright: Color const bgCyanBright: Color const bgWhiteBright: Color const isColorSupported: boolean function createColors(options?: { useColor: boolean }): Colorette } package.json000066600000001737150514454670007061 0ustar00{ "name": "colorette", "version": "2.0.19", "type": "module", "main": "index.cjs", "module": "index.js", "types": "index.d.ts", "description": "🌈Easily set your terminal text color & styles.", "repository": "jorgebucaran/colorette", "license": "MIT", "exports": { "./package.json": "./package.json", ".": { "require": "./index.cjs", "import": "./index.js" } }, "files": [ "*.*(c)[tj]s*" ], "author": "Jorge Bucaran", "keywords": [ "terminal", "styles", "color", "ansi" ], "scripts": { "test": "c8 twist tests/*.js", "build": "npx rollup --format cjs --input index.js --file index.cjs", "deploy": "npm test && git commit --all --message $tag && git tag --sign $tag --message $tag && git push && git push --tags", "release": "tag=$npm_package_version npm run deploy && npm publish --access public", "prepare": "npm run build" }, "devDependencies": { "c8": "*", "twist": "*" } }