pax_global_header00006660000000000000000000000064142561251410014513gustar00rootroot0000000000000052 comment=fa3454483899ddab550d08c18c028e6db1aab0e5 kleur-4.1.5/000077500000000000000000000000001425612514100126445ustar00rootroot00000000000000kleur-4.1.5/.editorconfig000066400000000000000000000003231425612514100153170ustar00rootroot00000000000000# http://editorconfig.org root = true [*] indent_size = 2 indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.{json,yml,md}] indent_style = space kleur-4.1.5/.github/000077500000000000000000000000001425612514100142045ustar00rootroot00000000000000kleur-4.1.5/.github/FUNDING.yml000066400000000000000000000000171425612514100160170ustar00rootroot00000000000000github: lukeed kleur-4.1.5/.github/workflows/000077500000000000000000000000001425612514100162415ustar00rootroot00000000000000kleur-4.1.5/.github/workflows/ci.yml000066400000000000000000000013471425612514100173640ustar00rootroot00000000000000name: CI on: [push, pull_request] jobs: test: name: Node.js v${{ matrix.nodejs }} runs-on: ubuntu-latest strategy: matrix: nodejs: [10, 12, 14] steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 with: node-version: ${{ matrix.nodejs }} - name: Install run: | npm install npm install -g c8 - name: Test w/ Coverage run: c8 npm test - name: Test w/ Environment run: npm run build && ./test/env.sh - name: Report if: matrix.nodejs >= 14 run: | c8 report --reporter=text-lcov > coverage.lcov bash <(curl -s https://codecov.io/bash) env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} kleur-4.1.5/.gitignore000066400000000000000000000001171425612514100146330ustar00rootroot00000000000000node_modules .DS_Store *-lock.* *.lock *.log # generated /colors.js /index.js kleur-4.1.5/bench/000077500000000000000000000000001425612514100137235ustar00rootroot00000000000000kleur-4.1.5/bench/colors.js000077500000000000000000000055331425612514100155730ustar00rootroot00000000000000const chalk = require('chalk'); const ansi = require('ansi-colors'); const { Suite } = require('benchmark'); const colors = require('../colors'); const kleur = require('../index'); // All color/method names const names = ['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']; function bench(name) { console.log(`\n# ${name}`); const suite = new Suite(); const previous = suite.add.bind(suite); suite.on('cycle', e => console.log(' ' + e.target)); suite.add = (name, runner) => previous(name.padEnd(16), runner); return suite; } bench('All Colors') .add('ansi-colors', () => { names.forEach(name => ansi[name]('foo')); }) .add('chalk', () => { names.forEach(name => chalk[name]('foo')); }) .add('kleur', () => { names.forEach(name => kleur[name]('foo')); }) .add('kleur/colors', () => { names.forEach(name => colors[name]('foo')); }) .run(); bench('Stacked colors') .add('ansi-colors', () => { names.forEach(name => ansi[name].bold.underline.italic('foo')); }) .add('chalk', () => { names.forEach(name => chalk[name].bold.underline.italic('foo')); }) .add('kleur', () => { names.forEach(name => kleur[name]().bold().underline().italic('foo')); }) .add('kleur/colors', () => { names.forEach(name => colors[name](colors.bold(colors.underline(colors.italic('foo'))))); }) .run(); bench('Nested colors') .add('ansi-colors', () => fixture(ansi)) .add('chalk', () => fixture(chalk)) .add('kleur', () => fixture(kleur)) .add('kleur/colors', () => fixture(colors)) .run(); function fixture(lib) { return lib.red(`a red ${lib.white('red')} red ${lib.red('red')} red ${lib.gray('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.blue('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')}red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')}red ${lib.green('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.magenta('red')} red ${lib.red('red')}red ${lib.red('red')} red ${lib.cyan('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.yellow('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} red ${lib.red('red')} message`); } kleur-4.1.5/bench/dryrun.js000077500000000000000000000041011425612514100156030ustar00rootroot00000000000000const libs = { chalk: require('chalk'), ansi: require('ansi-colors'), colors: require('../colors'), kleur: require('../index') }; const color = libs[process.argv[2] || 'kleur']; [ 'black', 'blue', 'cyan', 'green', 'magenta', 'red', 'white', 'yellow', 'dim', 'gray', 'bgBlack', 'bgBlue', 'bgCyan', 'bgGreen', 'bgMagenta', 'bgRed', 'bgWhite', 'bgYellow', 'hidden', 'inverse', 'bold', 'italic', 'reset', 'strikethrough', 'underline' ].forEach(str => { console.log(color[str]('~foobar~')); }); console.log(); console.log(color.bold(color.cyan('[info]')), color.cyan('This is some information')); console.log(color.bold(color.yellow('[warning]')), color.yellow('This is a warning')); console.log(color.bold(color.red('[ERROR]')), color.red('Danger! There was an error!')); console.log(); console.log(color.red(`a red ${color.white('white')} red ${color.red('red')} red ${color.gray('gray')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.blue('blue')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')}red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')}red ${color.green('green')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.magenta('red')} red ${color.red('red')}red ${color.red('red')} red ${color.cyan('cyan')} red ${color.red('red')} red ${color.red('red')} red ${color.yellow('yellow')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.blue('blue')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} red ${color.red('red')} message`).toString()); kleur-4.1.5/bench/index.js000077500000000000000000000000461425612514100153730ustar00rootroot00000000000000module.exports = require('./colors'); kleur-4.1.5/bench/load.js000077500000000000000000000005571425612514100152120ustar00rootroot00000000000000console.time('chalk'); const chalk = require('chalk'); console.timeEnd('chalk'); console.time('kleur'); const kleur = require('../index'); console.timeEnd('kleur'); console.time('kleur/colors'); const colors = require('../colors'); console.timeEnd('kleur/colors'); console.time('ansi-colors'); const color = require('ansi-colors'); console.timeEnd('ansi-colors'); kleur-4.1.5/bench/package.json000077500000000000000000000001751425612514100162170ustar00rootroot00000000000000{ "private": true, "devDependencies": { "ansi-colors": "4.1.1", "benchmark": "2.1.4", "chalk": "4.0.0" } } kleur-4.1.5/build/000077500000000000000000000000001425612514100137435ustar00rootroot00000000000000kleur-4.1.5/build/index.js000066400000000000000000000006741425612514100154170ustar00rootroot00000000000000const fs = require('fs'); function transform(file, next) { console.log('convert "%s" ~> "%s"', file, next); let code = fs.readFileSync(file, 'utf8'); code = code.replace('export default', 'module.exports ='); code = code.replace(/export const /g, 'exports.'); code = code.replace('exports.$ =', 'const $ = exports.$ ='); fs.writeFileSync(next, code, 'utf8'); } transform('index.mjs', 'index.js'); transform('colors.mjs', 'colors.js'); kleur-4.1.5/colors.d.ts000066400000000000000000000024241425612514100147410ustar00rootroot00000000000000declare function print(input: string | boolean | number): string; declare function print(input: undefined | void): undefined; declare function print(input: null): null; type Colorize = typeof print; export declare const $: { enabled: boolean }; // Colors export declare const black: Colorize; export declare const red: Colorize; export declare const green: Colorize; export declare const yellow: Colorize; export declare const blue: Colorize; export declare const magenta: Colorize; export declare const cyan: Colorize; export declare const white: Colorize; export declare const gray: Colorize; export declare const grey: Colorize; // Backgrounds export declare const bgBlack: Colorize; export declare const bgRed: Colorize; export declare const bgGreen: Colorize; export declare const bgYellow: Colorize; export declare const bgBlue: Colorize; export declare const bgMagenta: Colorize; export declare const bgCyan: Colorize; export declare const bgWhite: Colorize; // Modifiers export declare const reset: Colorize; export declare const bold: Colorize; export declare const dim: Colorize; export declare const italic: Colorize; export declare const underline: Colorize; export declare const inverse: Colorize; export declare const hidden: Colorize; export declare const strikethrough: Colorize; kleur-4.1.5/colors.mjs000066400000000000000000000031551425612514100146640ustar00rootroot00000000000000let FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM, isTTY=true; if (typeof process !== 'undefined') { ({ FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM } = process.env || {}); isTTY = process.stdout && process.stdout.isTTY; } export const $ = { enabled: !NODE_DISABLE_COLORS && NO_COLOR == null && TERM !== 'dumb' && ( FORCE_COLOR != null && FORCE_COLOR !== '0' || isTTY ) } function init(x, y) { let rgx = new RegExp(`\\x1b\\[${y}m`, 'g'); let open = `\x1b[${x}m`, close = `\x1b[${y}m`; return function (txt) { if (!$.enabled || txt == null) return txt; return open + (!!~(''+txt).indexOf(close) ? txt.replace(rgx, close + open) : txt) + close; }; } // modifiers export const reset = init(0, 0); export const bold = init(1, 22); export const dim = init(2, 22); export const italic = init(3, 23); export const underline = init(4, 24); export const inverse = init(7, 27); export const hidden = init(8, 28); export const strikethrough = init(9, 29); // colors export const black = init(30, 39); export const red = init(31, 39); export const green = init(32, 39); export const yellow = init(33, 39); export const blue = init(34, 39); export const magenta = init(35, 39); export const cyan = init(36, 39); export const white = init(37, 39); export const gray = init(90, 39); export const grey = init(90, 39); // background colors export const bgBlack = init(40, 49); export const bgRed = init(41, 49); export const bgGreen = init(42, 49); export const bgYellow = init(43, 49); export const bgBlue = init(44, 49); export const bgMagenta = init(45, 49); export const bgCyan = init(46, 49); export const bgWhite = init(47, 49); kleur-4.1.5/index.d.ts000066400000000000000000000014551425612514100145520ustar00rootroot00000000000000// Originally by: Rogier Schouten // Adapted by: Madhav Varshney declare namespace kleur { interface Color { (x: string | number): string; (): Kleur; } interface Kleur { // Colors black: Color; red: Color; green: Color; yellow: Color; blue: Color; magenta: Color; cyan: Color; white: Color; gray: Color; grey: Color; // Backgrounds bgBlack: Color; bgRed: Color; bgGreen: Color; bgYellow: Color; bgBlue: Color; bgMagenta: Color; bgCyan: Color; bgWhite: Color; // Modifiers reset: Color; bold: Color; dim: Color; italic: Color; underline: Color; inverse: Color; hidden: Color; strikethrough: Color; } } declare let kleur: kleur.Kleur & { enabled: boolean }; export = kleur; kleur-4.1.5/index.mjs000066400000000000000000000052671425612514100145000ustar00rootroot00000000000000'use strict'; let FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM, isTTY=true; if (typeof process !== 'undefined') { ({ FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM } = process.env || {}); isTTY = process.stdout && process.stdout.isTTY; } const $ = { enabled: !NODE_DISABLE_COLORS && NO_COLOR == null && TERM !== 'dumb' && ( FORCE_COLOR != null && FORCE_COLOR !== '0' || isTTY ), // modifiers reset: init(0, 0), bold: init(1, 22), dim: init(2, 22), italic: init(3, 23), underline: init(4, 24), inverse: init(7, 27), hidden: init(8, 28), strikethrough: init(9, 29), // colors 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), grey: init(90, 39), // background colors 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) }; function run(arr, str) { let i=0, tmp, beg='', end=''; for (; i < arr.length; i++) { tmp = arr[i]; beg += tmp.open; end += tmp.close; if (!!~str.indexOf(tmp.close)) { str = str.replace(tmp.rgx, tmp.close + tmp.open); } } return beg + str + end; } function chain(has, keys) { let ctx = { has, keys }; ctx.reset = $.reset.bind(ctx); ctx.bold = $.bold.bind(ctx); ctx.dim = $.dim.bind(ctx); ctx.italic = $.italic.bind(ctx); ctx.underline = $.underline.bind(ctx); ctx.inverse = $.inverse.bind(ctx); ctx.hidden = $.hidden.bind(ctx); ctx.strikethrough = $.strikethrough.bind(ctx); ctx.black = $.black.bind(ctx); ctx.red = $.red.bind(ctx); ctx.green = $.green.bind(ctx); ctx.yellow = $.yellow.bind(ctx); ctx.blue = $.blue.bind(ctx); ctx.magenta = $.magenta.bind(ctx); ctx.cyan = $.cyan.bind(ctx); ctx.white = $.white.bind(ctx); ctx.gray = $.gray.bind(ctx); ctx.grey = $.grey.bind(ctx); ctx.bgBlack = $.bgBlack.bind(ctx); ctx.bgRed = $.bgRed.bind(ctx); ctx.bgGreen = $.bgGreen.bind(ctx); ctx.bgYellow = $.bgYellow.bind(ctx); ctx.bgBlue = $.bgBlue.bind(ctx); ctx.bgMagenta = $.bgMagenta.bind(ctx); ctx.bgCyan = $.bgCyan.bind(ctx); ctx.bgWhite = $.bgWhite.bind(ctx); return ctx; } function init(open, close) { let blk = { open: `\x1b[${open}m`, close: `\x1b[${close}m`, rgx: new RegExp(`\\x1b\\[${close}m`, 'g') }; return function (txt) { if (this !== void 0 && this.has !== void 0) { !!~this.has.indexOf(open) || (this.has.push(open),this.keys.push(blk)); return txt === void 0 ? this : $.enabled ? run(this.keys, txt+'') : txt+''; } return txt === void 0 ? chain([open], [blk]) : $.enabled ? run([blk], txt+'') : txt+''; }; } export default $; kleur-4.1.5/license000066400000000000000000000021321425612514100142070ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) Luke Edwards (lukeed.com) 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. kleur-4.1.5/package.json000066400000000000000000000017361425612514100151410ustar00rootroot00000000000000{ "name": "kleur", "version": "4.1.5", "repository": "lukeed/kleur", "description": "The fastest Node.js library for formatting terminal text with ANSI colors~!", "module": "index.mjs", "types": "index.d.ts", "main": "index.js", "license": "MIT", "exports": { ".": { "types": "./index.d.ts", "import": "./index.mjs", "require": "./index.js" }, "./colors": { "types": "./colors.d.ts", "import": "./colors.mjs", "require": "./colors.js" } }, "files": [ "*.d.ts", "colors.*", "index.*" ], "author": { "name": "Luke Edwards", "email": "luke.edwards05@gmail.com", "url": "https://lukeed.com" }, "scripts": { "build": "node build", "test": "uvu -r esm -i utils -i xyz" }, "engines": { "node": ">=6" }, "keywords": [ "ansi", "cli", "color", "colors", "console", "terminal" ], "devDependencies": { "esm": "3.2.25", "uvu": "0.3.3" } } kleur-4.1.5/readme.md000066400000000000000000000163241425612514100144310ustar00rootroot00000000000000
kleur
version CI downloads install size
The fastest Node.js library for formatting terminal text with ANSI colors~!
## Features * No dependencies * Super [lightweight](#load-time) & [performant](#performance) * Supports [nested](#nested-methods) & [chained](#chained-methods) colors * No `String.prototype` modifications * Conditional [color support](#conditional-support) * [Fully treeshakable](#individual-colors) * Familiar [API](#api) --- As of `v3.0` the Chalk-style syntax (magical getter) is no longer used.
Please visit [History](#history) for migration paths supporting that syntax. --- ## Install ``` $ npm install --save kleur ``` ## Usage ```js import kleur from 'kleur'; // basic usage kleur.red('red text'); // chained methods kleur.blue().bold().underline('howdy partner'); // nested methods kleur.bold(`${ white().bgRed('[ERROR]') } ${ kleur.red().italic('Something happened')}`); ``` ### Chained Methods ```js const { bold, green } = require('kleur'); console.log(bold().red('this is a bold red message')); console.log(bold().italic('this is a bold italicized message')); console.log(bold().yellow().bgRed().italic('this is a bold yellow italicized message')); console.log(green().bold().underline('this is a bold green underlined message')); ``` ### Nested Methods ```js const { yellow, red, cyan } = require('kleur'); console.log(yellow(`foo ${red().bold('red')} bar ${cyan('cyan')} baz`)); console.log(yellow('foo ' + red().bold('red') + ' bar ' + cyan('cyan') + ' baz')); ``` ### Conditional Support Toggle color support as needed; `kleur` includes simple auto-detection which may not cover all cases. > **Note:** Both `kleur` and `kleur/colors` share the same detection logic. ```js import kleur from 'kleur'; // manually disable kleur.enabled = false; // or use another library to detect support kleur.enabled = require('color-support').level > 0; console.log(kleur.red('I will only be colored red if the terminal supports colors')); ``` > **Important:**
Colors will be disabled automatically in non [TTY contexts](https://nodejs.org/api/process.html#process_a_note_on_process_i_o). For example, spawning another process or piping output into another process will disable colorization automatically. To force colors in your piped output, you may do so with the `FORCE_COLOR=1` environment variable: ```sh $ node app.js #=> COLORS $ node app.js > log.txt #=> NO COLORS $ FORCE_COLOR=1 node app.js > log.txt #=> COLORS $ FORCE_COLOR=0 node app.js > log.txt #=> NO COLORS ``` ## API Any `kleur` method returns a `String` when invoked with input; otherwise chaining is expected. > It's up to the developer to pass the output to destinations like `console.log`, `process.stdout.write`, etc. The methods below are grouped by type for legibility purposes only. They each can be [chained](#chained-methods) or [nested](#nested-methods) with one another. ***Colors:*** > black — red — green — yellow — blue — magenta — cyan — white — gray — grey ***Backgrounds:*** > bgBlack — bgRed — bgGreen — bgYellow — bgBlue — bgMagenta — bgCyan — bgWhite ***Modifiers:*** > reset — bold — dim — italic* — underline — inverse — hidden — strikethrough* * Not widely supported ## Individual Colors When you only need a few colors, it doesn't make sense to import _all_ of `kleur` because, as small as it is, `kleur` is not treeshakeable, and so most of its code will be doing nothing. In order to fix this, you can import from the `kleur/colors` submodule which _fully_ supports tree-shaking. The caveat with this approach is that color functions **are not** chainable~!
Each function receives and colorizes its input. You may combine colors, backgrounds, and modifiers by nesting function calls within other functions. ```js // or: import * as kleur from 'kleur/colors'; import { red, underline, bgWhite } from 'kleur/colors'; red('red text'); //~> kleur.red('red text'); underline(red('red underlined text')); //~> kleur.underline().red('red underlined text'); bgWhite(underline(red('red underlined text w/ white background'))); //~> kleur.bgWhite().underline().red('red underlined text w/ white background'); ``` > **Note:** All the same [colors, backgrounds, and modifiers](#api) are available. ***Conditional Support*** The `kleur/colors` submodule also allows you to toggle color support, as needed.
It includes the same initial assumptions as `kleur`, in an attempt to have colors enabled by default. Unlike `kleur`, this setting exists as `kleur.$.enabled` instead of `kleur.enabled`: ```js import * as kleur from 'kleur/colors'; // or: import { $, red } from 'kleur/colors'; // manually disabled kleur.$.enabled = false; // or use another library to detect support kleur.$.enabled = require('color-support').level > 0; console.log(red('I will only be colored red if the terminal supports colors')); ``` ## Benchmarks > Using Node v10.13.0 ### Load time ``` chalk :: 5.303ms kleur :: 0.488ms kleur/colors :: 0.369ms ansi-colors :: 1.504ms ``` ### Performance ``` # All Colors ansi-colors x 177,625 ops/sec ±1.47% (92 runs sampled) chalk x 611,907 ops/sec ±0.20% (92 runs sampled) kleur x 742,509 ops/sec ±1.47% (93 runs sampled) kleur/colors x 881,742 ops/sec ±0.19% (98 runs sampled) # Stacked colors ansi-colors x 23,331 ops/sec ±1.81% (94 runs sampled) chalk x 337,178 ops/sec ±0.20% (98 runs sampled) kleur x 78,299 ops/sec ±1.01% (97 runs sampled) kleur/colors x 104,431 ops/sec ±0.22% (97 runs sampled) # Nested colors ansi-colors x 67,181 ops/sec ±1.15% (92 runs sampled) chalk x 116,361 ops/sec ±0.63% (94 runs sampled) kleur x 139,514 ops/sec ±0.76% (95 runs sampled) kleur/colors x 145,716 ops/sec ±0.97% (97 runs sampled) ``` ## History This project originally forked [`ansi-colors`](https://github.com/doowb/ansi-colors). Beginning with `kleur@3.0`, the Chalk-style syntax (magical getter) has been replaced with function calls per key: ```js // Old: c.red.bold.underline('old'); // New: c.red().bold().underline('new'); ``` > As I work more with Rust, the newer syntax feels so much better & more natural! If you prefer the old syntax, you may migrate to `ansi-colors` or newer `chalk` releases.
Versions below `kleur@3.0` have been officially deprecated. ## License MIT © [Luke Edwards](https://lukeed.com) kleur-4.1.5/shots/000077500000000000000000000000001425612514100140045ustar00rootroot00000000000000kleur-4.1.5/shots/1.png000077500000000000000000000252241425612514100146620ustar00rootroot00000000000000PNG  IHDRBBcPLTE(*6\W\WZ(*FZ(*;<)6h>~\R['5ΙWU0M+6OeV94`po\Z[V\]huWmV*1jTUBRK<_XIj`TYːNjW]lYha()TS݁Ԝ\b_?BRz|EguV>9;G.\WYU0\W%2GFl|?"=c.K=-eHg7?'sjT׏/*6wfC)5q&4sPBf'5dʌdEOܢgV87[|MuKc }67%v]XSP+0}LٿX)VE%3[ɊenXdUX\OJ֡˄[Y*<:[FH>:64gvR*t֖XNU=>WJ2ޜF((~Zv()rkkE;\e.jOUTMW*q8ȃ}%pWLK?gD76~}sRUwFL%ݎڀaiܑØtJf)cMDEW8^t464z_egnXiIII޳EZ`WS=tNp6m纆\HSdʋRRNAmn51xWwWˍBGMJD`>n_P\v9Z4VpMFW+8ۈrspc?ͩî됫{ȎɎ[H}'UIDATxfjVӈpηt) t'pD>@7L;wBƭ`VA0&ϑx2^[~-|9s<瞟;FDDDDd3Ȗ(aϳ,Do};C4t{AѦ`x ;u :dZ}-9ҿ,qz}} 4>A +mbG'BE8SxP KAguqi,d'Y09޼sY7£ )E!)<ɂ}D4~4M)WNJUm٘@x^xPu5 Ax1RA͟<(IeP&:s=v^+vY_Eqe6뎸_v7EIkWB=a̗yk 5}5MU } #.=أzQu27e(

|fyM ~Zzܕ,*"졶t-."㫔=pg*P=y*!V@t`iB//FC4и|n$J ӌeR5!x/ g WzJFA {GZClS3)d[ݍ'\y̹ MHJ(\T,j:) @=8U='WH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[ԵS"L{⨬K[5V?Ouz5 iCHb[ըY[E! oCm+@^meN bLuv ]| Qx뢶8PWZeeW|)bN"<.mz\"m5k 3mc[_[jMJ/լ-7tOʭT[HA{h[ڪ_'O"m5k˦v\!gCZŌxEX[m8)We3f-/Kx*Eyծ-H+%W2=DT[]$u[[L*`嫁H[ڲD!n?][m1!^tVɛeH[Mzҋ /Fʺ3޺-^ngե-z2O3kFʻ3C*h{*j V 3ciEwg"BۆSJ/++.myR;?+[0{nkН9qaouhҋ"mi>^B w嵶 mqU:"m]0 鸱ܪJgם< 7B_ DŎ)ɭ2bm>g7 u}m AAAۋ j⫁H[N[؅TԱ )d6%ꋹ#՝31^?ۡ]${-+@2t4t Ê'Kg&T1oYERwf`7<b]F-/3N|@ iE#|L#0vBLl A?ݙ= aoK\EĮ`ߞK ; b'ng,A<;AA Qj?A8;AiAjQJMo٨2S]Ao@TUUUUUUUUUUUUUUUUUUUUUUUUUUUU@TUUUUUUUUUUUUUUUUUUUUUUUUUU IENDB`kleur-4.1.5/test/000077500000000000000000000000001425612514100136235ustar00rootroot00000000000000kleur-4.1.5/test/colors.js000066400000000000000000000101061425612514100154600ustar00rootroot00000000000000import { test } from 'uvu'; import * as assert from 'uvu/assert'; import { ANSI, CODES } from './utils'; import * as kleur from '../colors.mjs'; test('kleur', () => { assert.type(kleur, 'object', 'exports an object'); assert.type(kleur.$, 'object', 'exports a "$" object'); assert.is(kleur.$.enabled, true, '~> colors enabled by default'); }); test('codes', () => { let k, tmp, val; for (k in CODES) { tmp = CODES[k]; val = kleur[k]('~foobar~'); assert.type(kleur[k], 'function', `is a function`); assert.is(kleur[k](), undefined, '~> returns immediately'); assert.type(val, 'string', 'returns a string value'); assert.is(val, ANSI(tmp[0]) + '~foobar~' + ANSI(tmp[1]), '~> matches expected'); } }); test('wrappings', () => { let { yellow, red, bold, cyan, bgRed, dim, italic, underline } = CODES; assert.is( kleur.red(kleur.bold('~foo~')), //~> kleur.red().bold(val) ANSI(red[0]) + ANSI(bold[0]) + '~foo~' + ANSI(bold[1]) + ANSI(red[1]) ); assert.is( kleur.bold(kleur.yellow(kleur.bgRed(kleur.italic('~foo~')))), //~> kleur.bold().yellow().bgRed().italic(val) ANSI(bold[0]) + ANSI(yellow[0]) + ANSI(bgRed[0]) + ANSI(italic[0]) + '~foo~' + ANSI(italic[1]) + ANSI(bgRed[1]) + ANSI(yellow[1]) + ANSI(bold[1]) ); assert.is( kleur.cyan(kleur.bold(kleur.underline('~foo~'))), //~> kleur.cyan().bold().underline('~foo~') ANSI(cyan[0]) + ANSI(bold[0]) + ANSI(underline[0]) + '~foo~' + ANSI(underline[1]) + ANSI(bold[1]) + ANSI(cyan[1]) ); assert.is( kleur.red(`foo ${kleur.yellow('bar')} baz`), ANSI(red[0]) + 'foo ' + ANSI(yellow[0]) + 'bar' + ANSI(yellow[1]) + ANSI(red[0]) + ' baz' + ANSI(red[1]) ); assert.is( kleur.bold(`foo ${kleur.red(kleur.dim('bar'))} baz`), ANSI(bold[0]) + 'foo ' + ANSI(red[0]) + ANSI(dim[0]) + 'bar' + ANSI(dim[1]) + ANSI(bold[0]) + ANSI(red[1]) + ' baz' + ANSI(bold[1]) ); assert.is( kleur.yellow(`foo ${kleur.red(kleur.bold('red'))} bar ${kleur.cyan('cyan')} baz`), ANSI(yellow[0]) + 'foo ' + ANSI(red[0]) + ANSI(bold[0]) + 'red' + ANSI(bold[1]) + ANSI(red[1]) + ANSI(yellow[0]) + ' bar ' + ANSI(cyan[0]) + 'cyan' + ANSI(cyan[1]) + ANSI(yellow[0]) + ' baz' + ANSI(yellow[1]) ); }); test('integer', () => { let { red, blue, italic } = CODES; assert.is( kleur.blue(-1), ANSI(blue[0]) + '-1' + ANSI(blue[1]), '~> negative' ); assert.is( kleur.blue(123), ANSI(blue[0]) + '123' + ANSI(blue[1]), '~> positive' ); assert.is( kleur.blue(0), ANSI(blue[0]) + '0' + ANSI(blue[1]), '~> zero' ); assert.is( kleur.red(kleur.italic(0)), //~> kleur.red().italic(0) ANSI(red[0]) + ANSI(italic[0]) + '0' + ANSI(italic[1]) + ANSI(red[1]), '~> zero (chain)' ); assert.is( kleur.italic(`${kleur.red(123)} ${kleur.blue(0)}`), ANSI(italic[0]) + ANSI(red[0]) + '123' + ANSI(red[1]) + ' ' + ANSI(blue[0]) + '0' + ANSI(blue[1]) + ANSI(italic[1]), '~> positive (chain w/ nested)' ); }); test('nullish', () => { assert.is(kleur.red(), undefined); assert.is(kleur.red(null), null); }); test('boolean', () => { let { red } = CODES; assert.is(kleur.red(false), ANSI(red[0]) + 'false' + ANSI(red[1])); assert.is(kleur.red(true), ANSI(red[0]) + 'true' + ANSI(red[1])); }); // test('multiline', () => { // let { blue, bold, red, italic } = CODES; // assert.is(c.blue('hello\nworld'), ANSI(blue[0]) + 'hello' + ANSI(blue[1]) + '\n' + ANSI(blue[0]) + 'world' + ANSI(blue[1]), '~> basic'); // assert.is(c.blue.bold('hello\nworld'), ANSI(bold[0]) + ANSI(blue[0]) + 'hello' + ANSI(blue[1]) + ANSI(bold[1]) + '\n' + ANSI(bold[0]) + ANSI(blue[0]) + 'world' + ANSI(blue[1]) + ANSI(bold[1]), '~> simple chain'); // assert.is(c.italic.bold(`${c.red('hello')}\n${c.blue('world')}`), ANSI(bold[0]) + ANSI(italic[0]) + ANSI(red[0]) + 'hello' + ANSI(red[1]) + ANSI(italic[1]) + ANSI(bold[1]) + '\n' + ANSI(bold[0]) + ANSI(italic[0]) + ANSI(blue[0]) + 'world' + ANSI(blue[1]) + ANSI(italic[1]) + ANSI(bold[1]), '~> chain w/ nested'); // }); test('toggle support', () => { let { red } = CODES; kleur.$.enabled = false; assert.is(kleur.red('foo'), 'foo'); kleur.$.enabled = true; assert.is(kleur.red('foo'), ANSI(red[0]) + 'foo' + ANSI(red[1])); }); test.run(); kleur-4.1.5/test/env.sh000077500000000000000000000051551425612514100147600ustar00rootroot00000000000000#!/usr/bin/env bash code=0 fail() { printf "\x1b[31m[FAIL]\x1b[39m %s\n" "$@" >&2 code=1 } colors() { printf "\x1b[33m[DEBUG]\x1b[39m \"%s\" :: %s \n" "$2" "$1" [ "$1" != "foo" ] || fail "$2" } nocolor() { printf "\x1b[33m[DEBUG]\x1b[39m \"%s\" :: %s \n" "$2" "$1" [[ "$1" =~ foo* ]] || fail "$2" } faketty() { script -qfc "$(printf "%q " "$@")" /dev/null } # process.stdout.isTTY = undefined; printf "\nprocess.stdout.isTTY = %s;\n" `node -p "process.stdout.isTTY"` nocolor `node -p "require('.').red('foo')"` "FORCE_COLOR=?" nocolor `FORCE_COLOR=0 node -p "require('.').red('foo')"` "FORCE_COLOR=0" nocolor `NODE_DISABLE_COLORS=1 node -p "require('.').red('foo')"` "NODE_DISABLE_COLORS=1" nocolor `NODE_DISABLE_COLORS=1 FORCE_COLOR=1 node -p "require('.').red('foo')"` "NODE_DISABLE_COLORS=1; FORCE_COLOR=1" nocolor `NO_COLOR=1 node -p "require('.').red('foo')"` "NO_COLOR=1" nocolor `NO_COLOR=1 FORCE_COLOR=1 node -p "require('.').red('foo')"` "NO_COLOR=1; FORCE_COLOR=1" nocolor `NO_COLOR= FORCE_COLOR=1 node -p "require('.').red('foo')"` "NO_COLOR=; FORCE_COLOR=1" colors `FORCE_COLOR=1 node -p "require('.').red('foo')"` "FORCE_COLOR=1" colors `FORCE_COLOR= node -p "require('.').red('foo')"` "FORCE_COLOR=" nocolor `TERM=dumb FORCE_COLOR=1 node -p "require('.').red('foo')"` "TERM=dumb; FORCE_COLOR=1" nocolor `TERM=dumb node -p "require('.').red('foo')"` "TERM=dumb" # process.stdout.isTTY = true; printf "\n(faketty) process.stdout.isTTY = %s;\n" `faketty node -p "process.stdout.isTTY"` colors `faketty node -p "require('.').red('foo')"` "FORCE_COLOR=?" colors `FORCE_COLOR=0 faketty node -p "require('.').red('foo')"` "FORCE_COLOR=0" nocolor `NODE_DISABLE_COLORS=1 faketty node -p "require('.').red('foo')"` "NODE_DISABLE_COLORS=1" nocolor `NODE_DISABLE_COLORS=1 FORCE_COLOR=1 faketty node -p "require('.').red('foo')"` "NODE_DISABLE_COLORS=1; FORCE_COLOR=1" nocolor `NO_COLOR=1 faketty node -p "require('.').red('foo')"` "NO_COLOR=1" nocolor `NO_COLOR=1 FORCE_COLOR=1 faketty node -p "require('.').red('foo')"` "NO_COLOR=1; FORCE_COLOR=1" nocolor `NO_COLOR= faketty node -p "require('.').red('foo')"` "NO_COLOR=" nocolor `NO_COLOR= FORCE_COLOR=1 faketty node -p "require('.').red('foo')"` "NO_COLOR=; FORCE_COLOR=1" nocolor `TERM=dumb FORCE_COLOR=1 faketty node -p "require('.').red('foo')"` "TERM=dumb; FORCE_COLOR=1" colors `FORCE_COLOR=1 faketty node -p "require('.').red('foo')"` "FORCE_COLOR=1" colors `FORCE_COLOR= faketty node -p "require('.').red('foo')"` "FORCE_COLOR=" nocolor `TERM=dumb node -r esm test/xyz.js` "TERM=dumb" if [ "$code" == "0" ]; then printf "\x1b[32m[PASS]\x1b[39m $.enabled updates correctly \n" fi exit $code kleur-4.1.5/test/index.js000066400000000000000000000141061425612514100152720ustar00rootroot00000000000000import { test } from 'uvu'; import * as assert from 'uvu/assert'; import { ANSI, CODES } from './utils'; import kleur from '../index.mjs'; test('kleur', () => { assert.type(kleur, 'object', 'exports an object'); assert.ok(kleur.enabled, 'colors enabled by default'); }); test('codes', () => { let k, tmp, val; for (k in CODES) { tmp = CODES[k]; val = kleur[k]('~foobar~'); assert.type(kleur[k], 'function', `is a function`); assert.type(kleur[k]().bold, 'function', '~> and is chainable'); assert.type(val, 'string', 'returns a string value'); assert.is(val, ANSI(tmp[0]) + '~foobar~' + ANSI(tmp[1]), '~> matches expected'); } }); test('chains', () => { let val = '~foobar~'; let { bold, underline, italic, bgRed, red, green, yellow } = CODES; assert.is(kleur.red().bold(val), ANSI(red[0]) + ANSI(bold[0]) + val + ANSI(red[1]) + ANSI(bold[1])); assert.is(kleur.bold().yellow().bgRed().italic(val), ANSI(bold[0]) + ANSI(yellow[0]) + ANSI(bgRed[0]) + ANSI(italic[0]) + val + ANSI(bold[1]) + ANSI(yellow[1]) + ANSI(bgRed[1]) + ANSI(italic[1])); assert.is(kleur.green().bold().underline(val), ANSI(green[0]) + ANSI(bold[0]) + ANSI(underline[0]) + val + ANSI(green[1]) + ANSI(bold[1]) + ANSI(underline[1])); }); test('nested', () => { let { yellow, red, bold, cyan, dim } = CODES; assert.is( kleur.red(`foo ${kleur.yellow('bar')} baz`), ANSI(red[0]) + 'foo ' + ANSI(yellow[0]) + 'bar' + ANSI(yellow[1]) + ANSI(red[0]) + ' baz' + ANSI(red[1]) ); assert.is( kleur.bold(`foo ${kleur.red().dim('bar')} baz`), ANSI(bold[0]) + 'foo ' + ANSI(red[0]) + ANSI(dim[0]) + 'bar' + ANSI(red[1]) + ANSI(dim[1]) + ANSI(bold[0]) + ' baz' + ANSI(bold[1]) ); assert.is( kleur.yellow(`foo ${kleur.red().bold('red')} bar ${kleur.cyan('cyan')} baz`), ANSI(yellow[0]) + 'foo ' + ANSI(red[0]) + ANSI(bold[0]) + 'red' + ANSI(red[1]) + ANSI(yellow[0]) + ANSI(bold[1]) + ' bar ' + ANSI(cyan[0]) + 'cyan' + ANSI(cyan[1]) + ANSI(yellow[0]) + ' baz' + ANSI(yellow[1]) ); }); test('integer', () => { let { red, blue, italic } = CODES; assert.is(kleur.blue(123), ANSI(blue[0]) + '123' + ANSI(blue[1]), '~> basic'); assert.is(kleur.red().italic(0), ANSI(red[0]) + ANSI(italic[0]) + '0' + ANSI(red[1]) + ANSI(italic[1]), '~> chain w/ 0'); assert.is(kleur.italic(`${kleur.red(123)} ${kleur.blue(0)}`), ANSI(italic[0]) + ANSI(red[0]) + '123' + ANSI(red[1]) + ' ' + ANSI(blue[0]) + '0' + ANSI(blue[1]) + ANSI(italic[1]), '~> chain w/ nested & 0'); assert.is(kleur.blue(-1), ANSI(blue[0]) + '-1' + ANSI(blue[1]), '~> basic w/ negatives'); }); // test('multiline', () => { // let { blue, bold, red, italic } = CODES; // assert.is(c.blue('hello\nworld'), ANSI(blue[0]) + 'hello' + ANSI(blue[1]) + '\n' + ANSI(blue[0]) + 'world' + ANSI(blue[1]), '~> basic'); // assert.is(c.blue.bold('hello\nworld'), ANSI(bold[0]) + ANSI(blue[0]) + 'hello' + ANSI(blue[1]) + ANSI(bold[1]) + '\n' + ANSI(bold[0]) + ANSI(blue[0]) + 'world' + ANSI(blue[1]) + ANSI(bold[1]), '~> simple chain'); // assert.is(c.italic.bold(`${c.red('hello')}\n${c.blue('world')}`), ANSI(bold[0]) + ANSI(italic[0]) + ANSI(red[0]) + 'hello' + ANSI(red[1]) + ANSI(italic[1]) + ANSI(bold[1]) + '\n' + ANSI(bold[0]) + ANSI(italic[0]) + ANSI(blue[0]) + 'world' + ANSI(blue[1]) + ANSI(italic[1]) + ANSI(bold[1]), '~> chain w/ nested'); // }); test('partial require', () => { let { red, bold, italic } = CODES; let r = kleur.red; let b = kleur.bold; let i = kleur.italic; assert.is(r('foo'), ANSI(red[0]) + 'foo' + ANSI(red[1]), '~> red()'); assert.is(b('bar'), ANSI(bold[0]) + 'bar' + ANSI(bold[1]), '~> bold()'); assert.is(i('baz'), ANSI(italic[0]) + 'baz' + ANSI(italic[1]), '~> italic()'); assert.is(r().bold().italic('foo'), ANSI(red[0]) + ANSI(bold[0]) + ANSI(italic[0]) + 'foo' + ANSI(red[1]) + ANSI(bold[1]) + ANSI(italic[1]), '~> red().bold().italic()'); assert.is(r().bold().italic('foo'), ANSI(red[0]) + ANSI(bold[0]) + ANSI(italic[0]) + 'foo' + ANSI(red[1]) + ANSI(bold[1]) + ANSI(italic[1]), '~> red().bold().italic() – repeat'); assert.is(b().italic().red('bar'), ANSI(bold[0]) + ANSI(italic[0]) + ANSI(red[0]) + 'bar' + ANSI(bold[1]) + ANSI(italic[1]) + ANSI(red[1]), '~> bold().italic().red()'); assert.is(b().italic().red('bar'), ANSI(bold[0]) + ANSI(italic[0]) + ANSI(red[0]) + 'bar' + ANSI(bold[1]) + ANSI(italic[1]) + ANSI(red[1]), '~> bold().italic().red() – repeat'); assert.is(i().red().bold('baz'), ANSI(italic[0]) + ANSI(red[0]) + ANSI(bold[0]) + 'baz' + ANSI(italic[1]) + ANSI(red[1]) + ANSI(bold[1]), '~> italic().red().bold()'); assert.is(i().red().bold('baz'), ANSI(italic[0]) + ANSI(red[0]) + ANSI(bold[0]) + 'baz' + ANSI(italic[1]) + ANSI(red[1]) + ANSI(bold[1]), '~> italic().red().bold() – repeat'); assert.is(r('foo'), ANSI(red[0]) + 'foo' + ANSI(red[1]), '~> red() – clean'); assert.is(b('bar'), ANSI(bold[0]) + 'bar' + ANSI(bold[1]), '~> bold() – clean'); assert.is(i('baz'), ANSI(italic[0]) + 'baz' + ANSI(italic[1]), '~> italic() – clean'); }); test('named chains', () => { let { red, bold, italic } = CODES; let foo = kleur.red().bold; let bar = kleur.bold().italic().red; assert.is(kleur.red('foo'), ANSI(red[0]) + 'foo' + ANSI(red[1]), '~> c.red() – clean'); assert.is(kleur.bold('bar'), ANSI(bold[0]) + 'bar' + ANSI(bold[1]), '~> c.bold() – clean'); assert.is(foo('foo'), ANSI(red[0]) + ANSI(bold[0]) + 'foo' + ANSI(red[1]) + ANSI(bold[1]), '~> foo()'); assert.is(foo('foo'), ANSI(red[0]) + ANSI(bold[0]) + 'foo' + ANSI(red[1]) + ANSI(bold[1]), '~> foo() – repeat'); assert.is(bar('bar'), ANSI(bold[0]) + ANSI(italic[0]) + ANSI(red[0]) + 'bar' + ANSI(bold[1]) + ANSI(italic[1]) + ANSI(red[1]), '~> bar()'); assert.is(bar('bar'), ANSI(bold[0]) + ANSI(italic[0]) + ANSI(red[0]) + 'bar' + ANSI(bold[1]) + ANSI(italic[1]) + ANSI(red[1]), '~> bar() – repeat'); assert.is(kleur.red('foo'), ANSI(red[0]) + 'foo' + ANSI(red[1]), '~> c.red() – clean'); assert.is(kleur.bold('bar'), ANSI(bold[0]) + 'bar' + ANSI(bold[1]), '~> c.bold() – clean'); }); test('disabled', () => { kleur.enabled = false; assert.is(kleur.red('foo'), 'foo', '~> raw text only'); assert.is(kleur.red().italic().bold('foobar'), 'foobar', '~> chaining okay'); }); test.run(); kleur-4.1.5/test/utils.js000066400000000000000000000011631425612514100153220ustar00rootroot00000000000000export const ANSI = x => `\x1b[${x}m`; export const CODES = { // modifiers reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29], // colors black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], gray: [90, 39], grey: [90, 39], // background colors bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], } kleur-4.1.5/test/xyz.js000066400000000000000000000001011425612514100150030ustar00rootroot00000000000000import kleur from '../index.mjs'; console.log(kleur.red('foo'));