pax_global_header00006660000000000000000000000064135070345230014514gustar00rootroot0000000000000052 comment=2f354b71bdbad9d3f5d705c78966378f83e5e080 ansi-colors-4.1.1/000077500000000000000000000000001350703452300137505ustar00rootroot00000000000000ansi-colors-4.1.1/.editorconfig000066400000000000000000000004411350703452300164240ustar00rootroot00000000000000# http://editorconfig.org/ root = true [*] charset = utf-8 end_of_line = lf indent_size = 2 indent_style = space insert_final_newline = true trim_trailing_whitespace = true [{**/{actual,fixtures,expected,templates}/**,*.md}] trim_trailing_whitespace = false insert_final_newline = false ansi-colors-4.1.1/.eslintrc.json000066400000000000000000000073251350703452300165530ustar00rootroot00000000000000{ "extends": [ "eslint:recommended" ], "env": { "browser": false, "es6": true, "node": true, "mocha": true }, "parserOptions":{ "ecmaVersion": 9, "sourceType": "module", "ecmaFeatures": { "modules": true, "experimentalObjectRestSpread": true } }, "globals": { "document": false, "navigator": false, "window": false }, "rules": { "accessor-pairs": 2, "arrow-spacing": [2, { "before": true, "after": true }], "block-spacing": [2, "always"], "brace-style": [2, "1tbs", { "allowSingleLine": true }], "comma-dangle": [2, "never"], "comma-spacing": [2, { "before": false, "after": true }], "comma-style": [2, "last"], "constructor-super": 2, "curly": [2, "multi-line"], "dot-location": [2, "property"], "eol-last": 2, "eqeqeq": [2, "allow-null"], "generator-star-spacing": [2, { "before": true, "after": true }], "handle-callback-err": [2, "^(err|error)$" ], "indent": [2, 2, { "SwitchCase": 1 }], "key-spacing": [2, { "beforeColon": false, "afterColon": true }], "keyword-spacing": [2, { "before": true, "after": true }], "new-cap": [2, { "newIsCap": true, "capIsNew": false }], "new-parens": 2, "no-array-constructor": 2, "no-caller": 2, "no-class-assign": 2, "no-cond-assign": 2, "no-const-assign": 2, "no-control-regex": 2, "no-debugger": 2, "no-delete-var": 2, "no-dupe-args": 2, "no-dupe-class-members": 2, "no-dupe-keys": 2, "no-duplicate-case": 2, "no-empty-character-class": 2, "no-eval": 2, "no-ex-assign": 2, "no-extend-native": 2, "no-extra-bind": 2, "no-extra-boolean-cast": 2, "no-extra-parens": [2, "functions"], "no-fallthrough": 2, "no-floating-decimal": 2, "no-func-assign": 2, "no-implied-eval": 2, "no-inner-declarations": [2, "functions"], "no-invalid-regexp": 2, "no-irregular-whitespace": 2, "no-iterator": 2, "no-label-var": 2, "no-labels": 2, "no-lone-blocks": 2, "no-mixed-spaces-and-tabs": 2, "no-multi-spaces": 2, "no-multi-str": 2, "no-multiple-empty-lines": [2, { "max": 1 }], "no-native-reassign": 0, "no-negated-in-lhs": 2, "no-new": 2, "no-new-func": 2, "no-new-object": 2, "no-new-require": 2, "no-new-wrappers": 2, "no-obj-calls": 2, "no-octal": 2, "no-octal-escape": 2, "no-proto": 0, "no-redeclare": 2, "no-regex-spaces": 2, "no-return-assign": 2, "no-self-compare": 2, "no-sequences": 2, "no-shadow-restricted-names": 2, "no-spaced-func": 2, "no-sparse-arrays": 2, "no-this-before-super": 2, "no-throw-literal": 2, "no-trailing-spaces": 0, "no-undef": 2, "no-undef-init": 2, "no-unexpected-multiline": 2, "no-unneeded-ternary": [2, { "defaultAssignment": false }], "no-unreachable": 2, "no-unused-vars": [2, { "vars": "all", "args": "none" }], "no-useless-call": 0, "no-with": 2, "one-var": [0, { "initialized": "never" }], "operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }], "padded-blocks": [0, "never"], "quotes": [2, "single", "avoid-escape"], "radix": 2, "semi": [2, "always"], "semi-spacing": [2, { "before": false, "after": true }], "space-before-blocks": [2, "always"], "space-before-function-paren": [2, "never"], "space-in-parens": [2, "never"], "space-infix-ops": 2, "space-unary-ops": [2, { "words": true, "nonwords": false }], "spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }], "use-isnan": 2, "valid-typeof": 2, "wrap-iife": [2, "any"], "yoda": [2, "never"] } } ansi-colors-4.1.1/.gitattributes000066400000000000000000000002001350703452300166330ustar00rootroot00000000000000# Enforce Unix newlines * text eol=lf # binaries *.ai binary *.psd binary *.jpg binary *.gif binary *.png binary *.jpeg binary ansi-colors-4.1.1/.gitignore000066400000000000000000000004561350703452300157450ustar00rootroot00000000000000# always ignore files *.DS_Store .idea .vscode *.sublime-* # test related, or directories generated by tests test/actual actual coverage .nyc* # npm node_modules npm-debug.log # yarn yarn.lock yarn-error.log # misc _gh_pages _draft _drafts bower_components vendor temp tmp TODO.md package-lock.jsonansi-colors-4.1.1/.npmrc000066400000000000000000000000231350703452300150630ustar00rootroot00000000000000package-lock=false ansi-colors-4.1.1/.travis.yml000066400000000000000000000002151350703452300160570ustar00rootroot00000000000000sudo: false os: - linux - osx - windows language: node_js node_js: - node - '12' - '11' - '10' - '9' - '8' - '7' - '6' ansi-colors-4.1.1/.verb.md000066400000000000000000000142311350703452300153070ustar00rootroot00000000000000![image](https://user-images.githubusercontent.com/383994/39635445-8a98a3a6-4f8b-11e8-89c1-068c45d4fff8.png) ## Why use this? ansi-colors is _the fastest Node.js library for terminal styling_. A more performant drop-in replacement for chalk, with no dependencies. * _Blazing fast_ - Fastest terminal styling library in node.js, 10-20x faster than chalk! - _Drop-in replacement_ for [chalk](https://github.com/chalk/chalk). - _No dependencies_ (Chalk has 7 dependencies in its tree!) * _Safe_ - Does not modify the `String.prototype` like [colors][]. * Supports [nested colors](#nested-colors), **and does not have the [nested styling bug](#nested-styling-bug) that is present in [colorette][], [chalk][], and [kleur][]**. * Supports [chained colors](#chained-colors). * [Toggle color support](#toggle-color-support) on or off. ## Usage ```js const c = require('{%= name %}'); console.log(c.red('This is a red string!')); console.log(c.green('This is a red string!')); console.log(c.cyan('This is a cyan string!')); console.log(c.yellow('This is a yellow string!')); ``` ![image](https://user-images.githubusercontent.com/383994/39653848-a38e67da-4fc0-11e8-89ae-98c65ebe9dcf.png) ## Chained colors ```js console.log(c.bold.red('this is a bold red message')); console.log(c.bold.yellow.italic('this is a bold yellow italicized message')); console.log(c.green.bold.underline('this is a bold green underlined message')); ``` ![image](https://user-images.githubusercontent.com/383994/39635780-7617246a-4f8c-11e8-89e9-05216cc54e38.png) ## Nested colors ```js console.log(c.yellow(`foo ${c.red.bold('red')} bar ${c.cyan('cyan')} baz`)); ``` ![image](https://user-images.githubusercontent.com/383994/39635817-8ed93d44-4f8c-11e8-8afd-8c3ea35f5fbe.png) ### Nested styling bug `ansi-colors` does not have the nested styling bug found in [colorette][], [chalk][], and [kleur][]. ```js const { bold, red } = require('ansi-styles'); console.log(bold(`foo ${red.dim('bar')} baz`)); const colorette = require('colorette'); console.log(colorette.bold(`foo ${colorette.red(colorette.dim('bar'))} baz`)); const kleur = require('kleur'); console.log(kleur.bold(`foo ${kleur.red.dim('bar')} baz`)); const chalk = require('chalk'); console.log(chalk.bold(`foo ${chalk.red.dim('bar')} baz`)); ``` **Results in the following** (sans icons and labels) ![image](https://user-images.githubusercontent.com/383994/47280326-d2ee0580-d5a3-11e8-9611-ea6010f0a253.png) ## Toggle color support Easily enable/disable colors. ```js const c = require('ansi-colors'); // disable colors manually c.enabled = false; // or use a library to automatically detect support c.enabled = require('color-support').hasBasic; console.log(c.red('I will only be colored red if the terminal supports colors')); ``` ## Strip ANSI codes Use the `.unstyle` method to strip ANSI codes from a string. ```js console.log(c.unstyle(c.blue.bold('foo bar baz'))); //=> 'foo bar baz' ``` ## Available styles **Note** that bright and bright-background colors are not always supported. | Colors | Background Colors | Bright Colors | Bright Background Colors | | ------- | ----------------- | ------------- | ------------------------ | | black | bgBlack | blackBright | bgBlackBright | | red | bgRed | redBright | bgRedBright | | green | bgGreen | greenBright | bgGreenBright | | yellow | bgYellow | yellowBright | bgYellowBright | | blue | bgBlue | blueBright | bgBlueBright | | magenta | bgMagenta | magentaBright | bgMagentaBright | | cyan | bgCyan | cyanBright | bgCyanBright | | white | bgWhite | whiteBright | bgWhiteBright | | gray | | | | | grey | | | | _(`gray` is the U.S. spelling, `grey` is more commonly used in the Canada and U.K.)_ ### Style modifiers - dim - **bold** - hidden - _italic_ - underline - inverse - ~~strikethrough~~ - reset ## Aliases Create custom aliases for styles. ```js const colors = require('ansi-colors'); colors.alias('primary', colors.yellow); colors.alias('secondary', colors.bold); console.log(colors.primary.secondary('Foo')); ``` ## Themes A theme is an object of custom aliases. ```js const colors = require('ansi-colors'); colors.theme({ danger: colors.red, dark: colors.dim.gray, disabled: colors.gray, em: colors.italic, heading: colors.bold.underline, info: colors.cyan, muted: colors.dim, primary: colors.blue, strong: colors.bold, success: colors.green, underline: colors.underline, warning: colors.yellow }); // Now, we can use our custom styles alongside the built-in styles! console.log(colors.danger.strong.em('Error!')); console.log(colors.warning('Heads up!')); console.log(colors.info('Did you know...')); console.log(colors.success.bold('It worked!')); ``` ## Performance **Libraries tested** - ansi-colors v3.0.4 - chalk v2.4.1 ### Mac > MacBook Pro, Intel Core i7, 2.3 GHz, 16 GB. **Load time** Time it takes to load the first time `require()` is called: - ansi-colors - `1.915ms` - chalk - `12.437ms` **Benchmarks** ``` # All Colors ansi-colors x 173,851 ops/sec ±0.42% (91 runs sampled) chalk x 9,944 ops/sec ±2.53% (81 runs sampled))) # Chained colors ansi-colors x 20,791 ops/sec ±0.60% (88 runs sampled) chalk x 2,111 ops/sec ±2.34% (83 runs sampled) # Nested colors ansi-colors x 59,304 ops/sec ±0.98% (92 runs sampled) chalk x 4,590 ops/sec ±2.08% (82 runs sampled) ``` ### Windows > Windows 10, Intel Core i7-7700k CPU @ 4.2 GHz, 32 GB **Load time** Time it takes to load the first time `require()` is called: - ansi-colors - `1.494ms` - chalk - `11.523ms` **Benchmarks** ``` # All Colors ansi-colors x 193,088 ops/sec ±0.51% (95 runs sampled)) chalk x 9,612 ops/sec ±3.31% (77 runs sampled))) # Chained colors ansi-colors x 26,093 ops/sec ±1.13% (94 runs sampled) chalk x 2,267 ops/sec ±2.88% (80 runs sampled)) # Nested colors ansi-colors x 67,747 ops/sec ±0.49% (93 runs sampled) chalk x 4,446 ops/sec ±3.01% (82 runs sampled)) ```ansi-colors-4.1.1/LICENSE000066400000000000000000000021031350703452300147510ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2015-present, Brian Woodward. 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. ansi-colors-4.1.1/README.md000066400000000000000000000234531350703452300152360ustar00rootroot00000000000000# ansi-colors [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=W8YFZ425KND68) [![NPM version](https://img.shields.io/npm/v/ansi-colors.svg?style=flat)](https://www.npmjs.com/package/ansi-colors) [![NPM monthly downloads](https://img.shields.io/npm/dm/ansi-colors.svg?style=flat)](https://npmjs.org/package/ansi-colors) [![NPM total downloads](https://img.shields.io/npm/dt/ansi-colors.svg?style=flat)](https://npmjs.org/package/ansi-colors) [![Linux Build Status](https://img.shields.io/travis/doowb/ansi-colors.svg?style=flat&label=Travis)](https://travis-ci.org/doowb/ansi-colors) > Easily add ANSI colors to your text and symbols in the terminal. A faster drop-in replacement for chalk, kleur and turbocolor (without the dependencies and rendering bugs). Please consider following this project's author, [Brian Woodward](https://github.com/doowb), and consider starring the project to show your :heart: and support. ## Install Install with [npm](https://www.npmjs.com/): ```sh $ npm install --save ansi-colors ``` ![image](https://user-images.githubusercontent.com/383994/39635445-8a98a3a6-4f8b-11e8-89c1-068c45d4fff8.png) ## Why use this? ansi-colors is _the fastest Node.js library for terminal styling_. A more performant drop-in replacement for chalk, with no dependencies. * _Blazing fast_ - Fastest terminal styling library in node.js, 10-20x faster than chalk! * _Drop-in replacement_ for [chalk](https://github.com/chalk/chalk). * _No dependencies_ (Chalk has 7 dependencies in its tree!) * _Safe_ - Does not modify the `String.prototype` like [colors](https://github.com/Marak/colors.js). * Supports [nested colors](#nested-colors), **and does not have the [nested styling bug](#nested-styling-bug) that is present in [colorette](https://github.com/jorgebucaran/colorette), [chalk](https://github.com/chalk/chalk), and [kleur](https://github.com/lukeed/kleur)**. * Supports [chained colors](#chained-colors). * [Toggle color support](#toggle-color-support) on or off. ## Usage ```js const c = require('ansi-colors'); console.log(c.red('This is a red string!')); console.log(c.green('This is a red string!')); console.log(c.cyan('This is a cyan string!')); console.log(c.yellow('This is a yellow string!')); ``` ![image](https://user-images.githubusercontent.com/383994/39653848-a38e67da-4fc0-11e8-89ae-98c65ebe9dcf.png) ## Chained colors ```js console.log(c.bold.red('this is a bold red message')); console.log(c.bold.yellow.italic('this is a bold yellow italicized message')); console.log(c.green.bold.underline('this is a bold green underlined message')); ``` ![image](https://user-images.githubusercontent.com/383994/39635780-7617246a-4f8c-11e8-89e9-05216cc54e38.png) ## Nested colors ```js console.log(c.yellow(`foo ${c.red.bold('red')} bar ${c.cyan('cyan')} baz`)); ``` ![image](https://user-images.githubusercontent.com/383994/39635817-8ed93d44-4f8c-11e8-8afd-8c3ea35f5fbe.png) ### Nested styling bug `ansi-colors` does not have the nested styling bug found in [colorette](https://github.com/jorgebucaran/colorette), [chalk](https://github.com/chalk/chalk), and [kleur](https://github.com/lukeed/kleur). ```js const { bold, red } = require('ansi-styles'); console.log(bold(`foo ${red.dim('bar')} baz`)); const colorette = require('colorette'); console.log(colorette.bold(`foo ${colorette.red(colorette.dim('bar'))} baz`)); const kleur = require('kleur'); console.log(kleur.bold(`foo ${kleur.red.dim('bar')} baz`)); const chalk = require('chalk'); console.log(chalk.bold(`foo ${chalk.red.dim('bar')} baz`)); ``` **Results in the following** (sans icons and labels) ![image](https://user-images.githubusercontent.com/383994/47280326-d2ee0580-d5a3-11e8-9611-ea6010f0a253.png) ## Toggle color support Easily enable/disable colors. ```js const c = require('ansi-colors'); // disable colors manually c.enabled = false; // or use a library to automatically detect support c.enabled = require('color-support').hasBasic; console.log(c.red('I will only be colored red if the terminal supports colors')); ``` ## Strip ANSI codes Use the `.unstyle` method to strip ANSI codes from a string. ```js console.log(c.unstyle(c.blue.bold('foo bar baz'))); //=> 'foo bar baz' ``` ## Available styles **Note** that bright and bright-background colors are not always supported. | Colors | Background Colors | Bright Colors | Bright Background Colors | | ------- | ----------------- | ------------- | ------------------------ | | black | bgBlack | blackBright | bgBlackBright | | red | bgRed | redBright | bgRedBright | | green | bgGreen | greenBright | bgGreenBright | | yellow | bgYellow | yellowBright | bgYellowBright | | blue | bgBlue | blueBright | bgBlueBright | | magenta | bgMagenta | magentaBright | bgMagentaBright | | cyan | bgCyan | cyanBright | bgCyanBright | | white | bgWhite | whiteBright | bgWhiteBright | | gray | | | | | grey | | | | _(`gray` is the U.S. spelling, `grey` is more commonly used in the Canada and U.K.)_ ### Style modifiers * dim * **bold** * hidden * _italic_ * underline * inverse * ~~strikethrough~~ * reset ## Aliases Create custom aliases for styles. ```js const colors = require('ansi-colors'); colors.alias('primary', colors.yellow); colors.alias('secondary', colors.bold); console.log(colors.primary.secondary('Foo')); ``` ## Themes A theme is an object of custom aliases. ```js const colors = require('ansi-colors'); colors.theme({ danger: colors.red, dark: colors.dim.gray, disabled: colors.gray, em: colors.italic, heading: colors.bold.underline, info: colors.cyan, muted: colors.dim, primary: colors.blue, strong: colors.bold, success: colors.green, underline: colors.underline, warning: colors.yellow }); // Now, we can use our custom styles alongside the built-in styles! console.log(colors.danger.strong.em('Error!')); console.log(colors.warning('Heads up!')); console.log(colors.info('Did you know...')); console.log(colors.success.bold('It worked!')); ``` ## Performance **Libraries tested** * ansi-colors v3.0.4 * chalk v2.4.1 ### Mac > MacBook Pro, Intel Core i7, 2.3 GHz, 16 GB. **Load time** Time it takes to load the first time `require()` is called: * ansi-colors - `1.915ms` * chalk - `12.437ms` **Benchmarks** ``` # All Colors ansi-colors x 173,851 ops/sec ±0.42% (91 runs sampled) chalk x 9,944 ops/sec ±2.53% (81 runs sampled))) # Chained colors ansi-colors x 20,791 ops/sec ±0.60% (88 runs sampled) chalk x 2,111 ops/sec ±2.34% (83 runs sampled) # Nested colors ansi-colors x 59,304 ops/sec ±0.98% (92 runs sampled) chalk x 4,590 ops/sec ±2.08% (82 runs sampled) ``` ### Windows > Windows 10, Intel Core i7-7700k CPU @ 4.2 GHz, 32 GB **Load time** Time it takes to load the first time `require()` is called: * ansi-colors - `1.494ms` * chalk - `11.523ms` **Benchmarks** ``` # All Colors ansi-colors x 193,088 ops/sec ±0.51% (95 runs sampled)) chalk x 9,612 ops/sec ±3.31% (77 runs sampled))) # Chained colors ansi-colors x 26,093 ops/sec ±1.13% (94 runs sampled) chalk x 2,267 ops/sec ±2.88% (80 runs sampled)) # Nested colors ansi-colors x 67,747 ops/sec ±0.49% (93 runs sampled) chalk x 4,446 ops/sec ±3.01% (82 runs sampled)) ``` ## About
Contributing Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
Running Tests Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command: ```sh $ npm install && npm test ```
Building docs _(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_ To generate the readme, run the following command: ```sh $ npm install -g verbose/verb#dev verb-generate-readme && verb ```
### Related projects You might also be interested in these projects: * [ansi-wrap](https://www.npmjs.com/package/ansi-wrap): Create ansi colors by passing the open and close codes. | [homepage](https://github.com/jonschlinkert/ansi-wrap "Create ansi colors by passing the open and close codes.") * [strip-color](https://www.npmjs.com/package/strip-color): Strip ANSI color codes from a string. No dependencies. | [homepage](https://github.com/jonschlinkert/strip-color "Strip ANSI color codes from a string. No dependencies.") ### Contributors | **Commits** | **Contributor** | | --- | --- | | 48 | [jonschlinkert](https://github.com/jonschlinkert) | | 42 | [doowb](https://github.com/doowb) | | 6 | [lukeed](https://github.com/lukeed) | | 2 | [Silic0nS0ldier](https://github.com/Silic0nS0ldier) | | 1 | [dwieeb](https://github.com/dwieeb) | | 1 | [jorgebucaran](https://github.com/jorgebucaran) | | 1 | [madhavarshney](https://github.com/madhavarshney) | | 1 | [chapterjason](https://github.com/chapterjason) | ### Author **Brian Woodward** * [GitHub Profile](https://github.com/doowb) * [Twitter Profile](https://twitter.com/doowb) * [LinkedIn Profile](https://linkedin.com/in/woodwardbrian) ### License Copyright © 2019, [Brian Woodward](https://github.com/doowb). Released under the [MIT License](LICENSE). *** _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on July 01, 2019._ansi-colors-4.1.1/bench/000077500000000000000000000000001350703452300150275ustar00rootroot00000000000000ansi-colors-4.1.1/bench/.npmrc000066400000000000000000000000231350703452300161420ustar00rootroot00000000000000package-lock=false ansi-colors-4.1.1/bench/colors.js000066400000000000000000000050711350703452300166710ustar00rootroot00000000000000'use strict'; const { Suite } = require('benchmark'); const chalk = require('chalk'); const colors = require('..'); 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' ]; const cycle = (e, newline) => { process.stdout.write('\u001b[G'); process.stdout.write(` ${e.target}` + (newline ? '\n' : '')); }; function bench(name) { console.log(`\n# ${name}`); const suite = new Suite(); const res = { run: suite.run.bind(suite), add: (key, fn) => { suite.add(key, { onCycle: e => cycle(e), onComplete: e => cycle(e, true), fn: fn }); return res; } }; return res; } bench('All Colors') .add('ansi-colors', () => { names.forEach(name => colors[name]('foo')); }) .add('chalk', () => { names.forEach(name => chalk[name]('foo')); }) .run(); bench('Chained colors') .add('ansi-colors', () => { names.forEach(name => colors[name].bold.underline.italic('foo')); }) .add('chalk', () => { names.forEach(name => chalk[name].bold.underline.italic('foo')); }) .run(); bench('Nested colors') .add('ansi-colors', () => fixture(colors)) .add('chalk', () => fixture(chalk)) .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`); } ansi-colors-4.1.1/bench/dryrun.js000066400000000000000000000060051350703452300167110ustar00rootroot00000000000000const lib = process.argv[2] || 'colors'; const libs = { chalk: require('chalk'), colors: require('..') }; const color = libs[lib]; console.log('bgBlack:', color.bgBlack('some string')); console.log('bgBlue:', color.bgBlue('some string')); console.log('bgCyan:', color.bgCyan('some string')); console.log('bgGreen:', color.bgGreen('some string')); console.log('bgMagenta:', color.bgMagenta('some string')); console.log('bgRed:', color.bgRed('some string')); console.log('bgWhite:', color.bgWhite('some string')); console.log('bgYellow:', color.bgYellow('some string')); console.log('black:', color.black('some string')); console.log('blue:', color.blue('some string')); console.log('bold:', color.bold('some string')); console.log('cyan:', color.cyan('some string')); console.log('dim:', color.dim('some string')); console.log('gray:', color.gray('some string')); console.log('green:', color.green('some string')); console.log('hidden:', color.hidden('some string')); console.log('inverse:', color.inverse('some string')); console.log('italic:', color.italic('some string')); console.log('magenta:', color.magenta('some string')); console.log('red:', color.red('some string')); console.log('reset:', color.reset('some string')); console.log('strikethrough:', color.strikethrough('some string')); console.log('underline:', color.underline('some string')); console.log('white:', color.white('some string')); console.log('yellow:', color.yellow('some string')); 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()); ansi-colors-4.1.1/bench/index.js000066400000000000000000000000461350703452300164740ustar00rootroot00000000000000module.exports = require('./colors'); ansi-colors-4.1.1/bench/load-ansi-colors.js000066400000000000000000000001141350703452300205270ustar00rootroot00000000000000console.time('ansi-colors'); require('..'); console.timeEnd('ansi-colors'); ansi-colors-4.1.1/bench/load-chalk.js000066400000000000000000000001031350703452300173560ustar00rootroot00000000000000console.time('chalk'); require('chalk'); console.timeEnd('chalk'); ansi-colors-4.1.1/bench/package.json000066400000000000000000000004131350703452300173130ustar00rootroot00000000000000{ "name": "benchmarks", "private": true, "dependencies": { "benchmark": "^2.1.4", "chalk": "^2.4.0", "clorox": "^2.2.0" }, "lintDeps": { "dependencies": { "files": { "patterns": [ "*.js" ] } } } } ansi-colors-4.1.1/examples/000077500000000000000000000000001350703452300155665ustar00rootroot00000000000000ansi-colors-4.1.1/examples/alias.js000066400000000000000000000002271350703452300172160ustar00rootroot00000000000000const colors = require('..'); colors.alias('primary', colors.yellow); colors.alias('strong', colors.bold); console.log(colors.primary.strong('Foo')); ansi-colors-4.1.1/examples/chained.js000066400000000000000000000010361350703452300175170ustar00rootroot00000000000000 const util = require('util'); console.time('time'); const colors = require('..'); colors.success = (...args) => colors.bold.green(util.format(...args)); colors.ok = (...args) => `${colors.success('✔')} ${colors.bold(util.format(...args))}`; console.log(colors.yellow('this is a message')) console.log(colors.bold.underline.red('foo')); console.log(colors.yellow.bold.underline.italic('foo')); console.log(colors.success('Hi, %s!', 'Brian')); console.log(colors.ok('File "%s" was written to "/%s"', 'foo', 'bar')); console.timeEnd('time'); ansi-colors-4.1.1/examples/colors.js000066400000000000000000000002661350703452300174310ustar00rootroot00000000000000 const colors = require('..'); console.log(colors.unstyle(colors.green('this is not green!'))); const cyan = colors.cyan; const key = cyan.underline('a'); console.log(cyan('foo')); ansi-colors-4.1.1/examples/nested.js000066400000000000000000000071321350703452300174110ustar00rootroot00000000000000console.time('grand total'); console.time('module loaded'); const colors = require('..'); // const colors = require('clorox'); // const colors = require('chalk'); console.timeEnd('module loaded'); colors.enabled = true; console.time('colors total'); console.time('diff'); console.log(colors.red('a red message')); console.timeEnd('diff'); console.time('diff'); console.log(colors.red('a red message')); console.timeEnd('diff'); console.time('diff'); console.log(colors.red('a red message')); console.timeEnd('diff'); console.time('diff'); console.log(colors.red('a red message')); console.timeEnd('diff'); console.time('diff'); console.log(colors.red('a red message')); console.timeEnd('diff'); console.time('diff'); console.log(colors.red('a red message')); console.timeEnd('diff'); console.time('diff'); console.log(colors.red('a red message')); console.timeEnd('diff'); console.time('diff'); console.log(colors.red('a red message')); console.timeEnd('diff'); console.time('diff'); console.log(colors.red('a red message')); console.timeEnd('diff'); console.time('diff'); console.log(colors.red('a red message')); console.timeEnd('diff'); console.time('diff'); console.log(colors.red('a red message')); console.timeEnd('diff'); console.time('diff'); console.log(colors.red('a red message')); console.timeEnd('diff'); console.time('diff'); console.log(colors.red.bold('a red bold message')); console.timeEnd('diff'); console.time('diff'); console.log(colors.cyan.bold('a cyan bold message')); console.timeEnd('diff'); console.time('diff'); console.log(colors.blue.bold('a blue bold message')); console.timeEnd('diff'); console.time('diff'); console.log(colors.bold.green('a bold green message')); console.timeEnd('diff'); console.time('diff'); console.log(colors.red(`a red ${colors.blue('and blue')} message`)); console.timeEnd('diff'); console.time('diff'); console.log(colors.red(`a red ${colors.bold.yellow('and bold yellow')} message`)); console.timeEnd('diff'); console.time('diff'); console.log(colors.bold.green(`a bold green ${colors.bold.yellow('and bold yellow')} message`)); console.timeEnd('diff'); console.time('diff'); console.log(colors.red(`a red ${colors.white('white')} red ${colors.red('red')} red ${colors.gray('gray')} red ${colors.red('red')} red ${colors.red('red')} red ${colors.red('red')} red ${colors.red('red')} red ${colors.red('red')} red ${colors.blue('blue')} red ${colors.red('red')} red ${colors.red('red')} red ${colors.red('red')} red ${colors.red('red')}red ${colors.red('red')} red ${colors.red('red')} red ${colors.red('red')} red ${colors.red('red')} red ${colors.red('red')} red ${colors.red('red')} red ${colors.red('red')} red ${colors.red('red')} red ${colors.red('red')} red ${colors.red('red')} red ${colors.red('red')} red ${colors.red('red')} red ${colors.red('red')}red ${colors.cyan('cyan')} red ${colors.red('red')} red ${colors.red('red')} red ${colors.red('red')} red ${colors.red('red')} red ${colors.red('red')} red ${colors.red('red')} red ${colors.red('red')} red ${colors.red('red')} red ${colors.red('red')} red ${colors.red('red')} red ${colors.red('red')} red ${colors.red('red')}red ${colors.red('red')} red ${colors.yellow('yellow')} red ${colors.red('red')} red ${colors.red('red')} red ${colors.red('red')} red ${colors.red('red')} red ${colors.red('red')} red ${colors.red('red')} red ${colors.green('green')} red ${colors.red('red')} red ${colors.red('red')} red ${colors.red('red')} red ${colors.red('red')} message`)); console.timeEnd('diff'); console.timeEnd('colors total'); console.timeEnd('grand total'); console.log(colors.yellow(`foo ${colors.red.bold('red')} bar ${colors.cyan('cyan')} baz`)); ansi-colors-4.1.1/examples/nesting-bug.js000066400000000000000000000011561350703452300203510ustar00rootroot00000000000000console.log(); const { bold, cyan, gray, green, red, symbols } = require('./'); const good = green(symbols.check); const bad = red(symbols.cross); console.log(bold(`foo ${cyan.dim('bar')} baz`), good, gray('(ansi-colors)')); const colorette = require('colorette'); console.log(colorette.bold(`foo ${colorette.cyan(colorette.dim('bar'))} baz`), bad, gray('(colorette)')); const kleur = require('kleur'); console.log(kleur.bold(`foo ${kleur.cyan.dim('bar')} baz`), bad, gray('(kleur)')); const chalk = require('chalk'); console.log(chalk.bold(`foo ${chalk.cyan.dim('bar')} baz`), bad, gray('(chalk)')); console.log(); ansi-colors-4.1.1/examples/ok.js000066400000000000000000000001761350703452300165410ustar00rootroot00000000000000 const log = require('..'); log.ok = msg => `${log.green(log.symbols.check)} ${log.bold(msg)}`; console.log(log.ok('done!')); ansi-colors-4.1.1/examples/readme-examples.js000066400000000000000000000024361350703452300212020ustar00rootroot00000000000000'use strict'; const util = require('util'); const c = require('..'); console.log(c); console.log(); console.log('nested colors'); console.log(); console.log(c.yellow(`foo ${c.red.bold('red')} bar ${c.cyan('cyan')} baz`)); console.log(c.yellow('foo', c.red.bold('red'), 'bar', c.cyan('cyan'), 'baz')); console.log(); console.log(); console.log('chained colors'); console.log(); console.log(c.bold.red('this is a bold red message')); console.log(c.bold.italic('this is a bold italicized message')); console.log(c.bold.yellow.italic('this is a bold yellow italicized message')); console.log(c.green.bold.underline('this is a bold green underlined message')); console.log(); console.log(); console.log('printf-like formatting'); console.log(); console.log(c.bold.red(util.format('%s:%s', 'foo', 'bar', 'baz'))); console.log(); console.log(); console.log(c.bold.bold(util.format('%s:%s:%s', 'foo', c.red('bar'), 'baz'))); console.log(); console.log(); console.log('features'); console.log(); console.log(c.red('Some', 'red', 'text', 'to', 'display')); console.log(); console.log(); console.log(c.red(' This is a red string!')); console.log(c.green(' This is a red string!')); console.log(c.cyan(' This is a cyan string!')); console.log(c.yellow(' This is a yellow string!')); console.log(); console.log(); ansi-colors-4.1.1/examples/screenshot-table.js000066400000000000000000000013151350703452300213660ustar00rootroot00000000000000'use strict'; const table = require('text-table'); const colors = require('..'); const styles = colors.styles; let arr = [[]]; let idx = 0; /** * this is inspired by and modified from the * screenshot code and concept from chalk */ for (const key of Object.keys(styles)) { let prop = key; if (key === 'reset' || key === 'hidden' || key === 'grey' || key === 'verbose') { continue; } if (/bright/i.test(key)) { continue; } if (/^bg[^B]/.test(key)) { prop = colors.black(prop); } arr[arr.length - 1].push(colors[key](prop)); if (idx++ >= 3) { arr.push([]); idx = 0; } } const stringLength = str => colors.unstyle(str).length; console.log(table(arr, { stringLength })) ansi-colors-4.1.1/examples/screenshot.js000066400000000000000000000012161350703452300203010ustar00rootroot00000000000000'use strict'; const colors = require('..'); const justified = require('justified'); let str = ''; /** * this is inspired by and modified from the * screenshot code and concept from chalk */ for (const key of Object.keys(colors.styles)) { let res = key; if (key === 'reset' || key === 'hidden' || key === 'grey' || key === 'verbose') { continue; } if (/bright/i.test(key)) { continue; } if (/^bg[^B]/.test(key)) { res = colors.black(res); } str += colors[key](res) + ' '; } console.log(); console.log(); console.log(justified(str, { width: 60, format: colors.unstyle, indent: ' ' })); console.log(); console.log(); ansi-colors-4.1.1/examples/styles.js000066400000000000000000000023461350703452300174540ustar00rootroot00000000000000 const util = require('util'); const c = require('..'); c.info = (...args) => { return c.bold(c.cyan('[info] ')) + c.cyan(...args); }; console.log(c.info('This is some information')); console.log(c.bold(c.yellow('[warning]')), c.yellow('This is a warning')); console.error(c.bold(c.red('[ERROR]')), c.red('Danger! There was an error!')); console.log(c.yellow.bold.underline.italic('foo')); console.log(c.white('foo')); console.log(c.red(`a red ${c.bold.yellow('and bold yellow')} message`)); console.log(c.bold.green(`a bold green ${c.bold.yellow('and bold yellow')} message`)); console.log(c.yellow(`foo ${c.red.bold('red')} bar ${c.cyan('cyan')} baz`)); console.log(c.yellow('foo', c.red.bold('red'), 'bar', c.cyan('cyan'), 'baz')); console.log(c.bold.red('this is a bold red message')); console.log(c.bold.italic('this is a bold italicized message')); console.log(c.bold.yellow.italic('this is a bold yellow italicized message')); console.log(c.green.bold.underline('this is a bold green underlined message')); console.log(c.bold.red(util.format('%s:%s', 'foo', 'bar', 'baz'))); console.log(c.bold.bold(util.format('%s:%s:%s', 'foo', c.red('bar'), 'baz'))); console.log(c.red('Some', 'red', 'text', 'to', 'display')); // // console.log(colors); ansi-colors-4.1.1/examples/theme-custom-fn.js000066400000000000000000000015431350703452300211420ustar00rootroot00000000000000const colors = require('..'); colors.theme({ success: 'blue', em: 'italic', strong: 'bold', s: 'strikethrough', u: 'underline', ok(message) { let { unstyle, success, symbols } = colors; let plain = unstyle(message); let match = plain.match(/^( +)(.*)$/); let prefix = match ? ' '.repeat(match[1].length) : ''; let rest = match ? match[2] : message; if (rest !== message) { rest = message.replace(plain, rest); } return prefix + success(symbols.check) + ' ' + rest; } }); const { ok, em, s, u } = colors; console.log(ok(' Success!')); console.log(ok.em.s(' Success!')); console.log(em.ok.s(' Success!')); console.log(em.ok.u(' Success!')); console.log(em.s.ok(' Success!')); console.log(s.ok.em(' Success!')); console.log(s.em.ok(' Success!')); console.log(u.em.ok(' Success!')); ansi-colors-4.1.1/examples/theme.js000066400000000000000000000025341350703452300172320ustar00rootroot00000000000000const colors = require('..'); colors.theme({ primary: 'yellow', error: colors.red, strong: 'bold', em: 'underline' }); colors.theme({ secondary: 'primary', warning: 'error' }); const { primary, error, strong, red, bold, yellow, underline, secondary, warning } = colors; console.log(colors.primary.bold('Foo')); console.log(colors.error.strong.em('Foo')); console.log('---'); console.log(primary.bold('Foo')); console.log(error.strong.em('Foo')); console.log(strong.em('Foo')); console.log('---'); console.log(yellow.bold('Foo')); console.log(red.bold.underline('Foo')); console.log(bold.underline('Foo')); console.log('---'); console.log(secondary('Foo')); console.log(secondary.bold('Foo')); console.log(secondary.strong('Foo')); console.log(warning('Foo')); console.log(warning.underline('Foo')); console.log('---'); colors.alias('warning', colors.green); console.log(bold.warning('Foo')); console.log(colors.warning('Foo')); console.log('---'); colors.warning = colors.red; console.log(warning.bold('Foo')); console.log(bold.underline.warning('Foo')); console.log(colors.warning('Foo')); console.log('---'); colors.yellow = colors.blue; colors.bold = colors.dim; colors.dim = bold; console.log(yellow.bold('Foo')); console.log(colors.yellow.dim('Foo')); console.log(red.bold.underline('Foo')); console.log(bold.underline('Foo')); console.log('---'); ansi-colors-4.1.1/examples/theme2.js000066400000000000000000000007431350703452300173140ustar00rootroot00000000000000const colors = require('..'); colors.theme({ danger: colors.red, dark: colors.dim.gray, disabled: colors.gray, em: colors.italic, heading: colors.bold.underline, info: colors.cyan, muted: colors.dim, primary: colors.blue, strong: colors.bold, success: colors.green, underline: colors.underline, warning: colors.yellow }); console.log(colors.danger.strong.em('Error!')); console.log(colors.warning('Heads up!')); console.log(colors.info('Did you know...')); ansi-colors-4.1.1/examples/unstyle.js000066400000000000000000000005201350703452300176240ustar00rootroot00000000000000const colors = require('..'); console.log(colors.unstyle(colors.green('This should NOT be green!'))); console.log(colors.red(colors.green('This SHOULD be GREEN!'))); console.log(); console.log(colors.red.unstyle(colors.green('This SHOULD be RED!'))); console.log(colors.unstyle.red.bold(colors.green('This SHOULD be RED and BOLD!'))); ansi-colors-4.1.1/index.js000066400000000000000000000133621350703452300154220ustar00rootroot00000000000000'use strict'; const isObject = val => val !== null && typeof val === 'object' && !Array.isArray(val); const identity = val => val; /* eslint-disable no-control-regex */ // this is a modified version of https://github.com/chalk/ansi-regex (MIT License) const ANSI_REGEX = /[\u001b\u009b][[\]#;?()]*(?:(?:(?:[^\W_]*;?[^\W_]*)\u0007)|(?:(?:[0-9]{1,4}(;[0-9]{0,4})*)?[~0-9=<>cf-nqrtyA-PRZ]))/g; const create = () => { const colors = { enabled: true, visible: true, styles: {}, keys: {} }; if ('FORCE_COLOR' in process.env) { colors.enabled = process.env.FORCE_COLOR !== '0'; } const ansi = style => { let open = style.open = `\u001b[${style.codes[0]}m`; let close = style.close = `\u001b[${style.codes[1]}m`; let regex = style.regex = new RegExp(`\\u001b\\[${style.codes[1]}m`, 'g'); style.wrap = (input, newline) => { if (input.includes(close)) input = input.replace(regex, close + open); let output = open + input + close; // see https://github.com/chalk/chalk/pull/92, thanks to the // chalk contributors for this fix. However, we've confirmed that // this issue is also present in Windows terminals return newline ? output.replace(/\r*\n/g, `${close}$&${open}`) : output; }; return style; }; const wrap = (style, input, newline) => { return typeof style === 'function' ? style(input) : style.wrap(input, newline); }; const style = (input, stack) => { if (input === '' || input == null) return ''; if (colors.enabled === false) return input; if (colors.visible === false) return ''; let str = '' + input; let nl = str.includes('\n'); let n = stack.length; if (n > 0 && stack.includes('unstyle')) { stack = [...new Set(['unstyle', ...stack])].reverse(); } while (n-- > 0) str = wrap(colors.styles[stack[n]], str, nl); return str; }; const define = (name, codes, type) => { colors.styles[name] = ansi({ name, codes }); let keys = colors.keys[type] || (colors.keys[type] = []); keys.push(name); Reflect.defineProperty(colors, name, { configurable: true, enumerable: true, set(value) { colors.alias(name, value); }, get() { let color = input => style(input, color.stack); Reflect.setPrototypeOf(color, colors); color.stack = this.stack ? this.stack.concat(name) : [name]; return color; } }); }; define('reset', [0, 0], 'modifier'); define('bold', [1, 22], 'modifier'); define('dim', [2, 22], 'modifier'); define('italic', [3, 23], 'modifier'); define('underline', [4, 24], 'modifier'); define('inverse', [7, 27], 'modifier'); define('hidden', [8, 28], 'modifier'); define('strikethrough', [9, 29], 'modifier'); define('black', [30, 39], 'color'); define('red', [31, 39], 'color'); define('green', [32, 39], 'color'); define('yellow', [33, 39], 'color'); define('blue', [34, 39], 'color'); define('magenta', [35, 39], 'color'); define('cyan', [36, 39], 'color'); define('white', [37, 39], 'color'); define('gray', [90, 39], 'color'); define('grey', [90, 39], 'color'); define('bgBlack', [40, 49], 'bg'); define('bgRed', [41, 49], 'bg'); define('bgGreen', [42, 49], 'bg'); define('bgYellow', [43, 49], 'bg'); define('bgBlue', [44, 49], 'bg'); define('bgMagenta', [45, 49], 'bg'); define('bgCyan', [46, 49], 'bg'); define('bgWhite', [47, 49], 'bg'); define('blackBright', [90, 39], 'bright'); define('redBright', [91, 39], 'bright'); define('greenBright', [92, 39], 'bright'); define('yellowBright', [93, 39], 'bright'); define('blueBright', [94, 39], 'bright'); define('magentaBright', [95, 39], 'bright'); define('cyanBright', [96, 39], 'bright'); define('whiteBright', [97, 39], 'bright'); define('bgBlackBright', [100, 49], 'bgBright'); define('bgRedBright', [101, 49], 'bgBright'); define('bgGreenBright', [102, 49], 'bgBright'); define('bgYellowBright', [103, 49], 'bgBright'); define('bgBlueBright', [104, 49], 'bgBright'); define('bgMagentaBright', [105, 49], 'bgBright'); define('bgCyanBright', [106, 49], 'bgBright'); define('bgWhiteBright', [107, 49], 'bgBright'); colors.ansiRegex = ANSI_REGEX; colors.hasColor = colors.hasAnsi = str => { colors.ansiRegex.lastIndex = 0; return typeof str === 'string' && str !== '' && colors.ansiRegex.test(str); }; colors.alias = (name, color) => { let fn = typeof color === 'string' ? colors[color] : color; if (typeof fn !== 'function') { throw new TypeError('Expected alias to be the name of an existing color (string) or a function'); } if (!fn.stack) { Reflect.defineProperty(fn, 'name', { value: name }); colors.styles[name] = fn; fn.stack = [name]; } Reflect.defineProperty(colors, name, { configurable: true, enumerable: true, set(value) { colors.alias(name, value); }, get() { let color = input => style(input, color.stack); Reflect.setPrototypeOf(color, colors); color.stack = this.stack ? this.stack.concat(fn.stack) : fn.stack; return color; } }); }; colors.theme = custom => { if (!isObject(custom)) throw new TypeError('Expected theme to be an object'); for (let name of Object.keys(custom)) { colors.alias(name, custom[name]); } return colors; }; colors.alias('unstyle', str => { if (typeof str === 'string' && str !== '') { colors.ansiRegex.lastIndex = 0; return str.replace(colors.ansiRegex, ''); } return ''; }); colors.alias('noop', str => str); colors.none = colors.clear = colors.noop; colors.stripColor = colors.unstyle; colors.symbols = require('./symbols'); colors.define = define; return colors; }; module.exports = create(); module.exports.create = create; ansi-colors-4.1.1/package.json000066400000000000000000000041031350703452300162340ustar00rootroot00000000000000{ "name": "ansi-colors", "description": "Easily add ANSI colors to your text and symbols in the terminal. A faster drop-in replacement for chalk, kleur and turbocolor (without the dependencies and rendering bugs).", "version": "4.1.1", "homepage": "https://github.com/doowb/ansi-colors", "author": "Brian Woodward (https://github.com/doowb)", "contributors": [ "Brian Woodward (https://twitter.com/doowb)", "Jason Schilling (https://sourecode.de)", "Jon Schlinkert (http://twitter.com/jonschlinkert)", "Jordan (https://github.com/Silic0nS0ldier)" ], "repository": "doowb/ansi-colors", "bugs": { "url": "https://github.com/doowb/ansi-colors/issues" }, "license": "MIT", "files": [ "index.js", "symbols.js", "types/index.d.ts" ], "main": "index.js", "types": "./types/index.d.ts", "engines": { "node": ">=6" }, "scripts": { "test": "mocha" }, "devDependencies": { "decache": "^4.5.1", "gulp-format-md": "^2.0.0", "justified": "^1.0.1", "mocha": "^6.1.4", "text-table": "^0.2.0" }, "keywords": [ "ansi", "bgblack", "bgBlack", "bgblue", "bgBlue", "bgcyan", "bgCyan", "bggreen", "bgGreen", "bgmagenta", "bgMagenta", "bgred", "bgRed", "bgwhite", "bgWhite", "bgyellow", "bgYellow", "black", "blue", "bold", "clorox", "colors", "cyan", "dim", "gray", "green", "grey", "hidden", "inverse", "italic", "kleur", "magenta", "red", "reset", "strikethrough", "underline", "white", "yellow" ], "verb": { "toc": false, "layout": "default", "tasks": [ "readme" ], "data": { "author": { "linkedin": "woodwardbrian", "twitter": "doowb" } }, "plugins": [ "gulp-format-md" ], "lint": { "reflinks": true }, "related": { "list": [ "ansi-wrap", "strip-color" ] }, "reflinks": [ "chalk", "colorette", "colors", "kleur" ] } } ansi-colors-4.1.1/symbols.js000066400000000000000000000031131350703452300157740ustar00rootroot00000000000000'use strict'; const isHyper = process.env.TERM_PROGRAM === 'Hyper'; const isWindows = process.platform === 'win32'; const isLinux = process.platform === 'linux'; const common = { ballotDisabled: '☒', ballotOff: '☐', ballotOn: '☑', bullet: '•', bulletWhite: '◦', fullBlock: '█', heart: '❤', identicalTo: '≡', line: '─', mark: '※', middot: '·', minus: '-', multiplication: '×', obelus: '÷', pencilDownRight: '✎', pencilRight: '✏', pencilUpRight: '✐', percent: '%', pilcrow2: '❡', pilcrow: '¶', plusMinus: '±', section: '§', starsOff: '☆', starsOn: '★', upDownArrow: '↕' }; const windows = Object.assign({}, common, { check: '√', cross: '×', ellipsisLarge: '...', ellipsis: '...', info: 'i', question: '?', questionSmall: '?', pointer: '>', pointerSmall: '»', radioOff: '( )', radioOn: '(*)', warning: '‼' }); const other = Object.assign({}, common, { ballotCross: '✘', check: '✔', cross: '✖', ellipsisLarge: '⋯', ellipsis: '…', info: 'ℹ', question: '?', questionFull: '?', questionSmall: '﹖', pointer: isLinux ? '▸' : '❯', pointerSmall: isLinux ? '‣' : '›', radioOff: '◯', radioOn: '◉', warning: '⚠' }); module.exports = (isWindows && !isHyper) ? windows : other; Reflect.defineProperty(module.exports, 'common', { enumerable: false, value: common }); Reflect.defineProperty(module.exports, 'windows', { enumerable: false, value: windows }); Reflect.defineProperty(module.exports, 'other', { enumerable: false, value: other }); ansi-colors-4.1.1/test.js000066400000000000000000000206411350703452300152700ustar00rootroot00000000000000'use strict'; require('mocha'); const assert = require('assert'); const decache = require('decache'); const colors = require('./'); describe('ansi-colors', () => { it('should wrap a string with ansi codes:', () => { assert.equal(colors.bgBlack('string'), '\u001b[40mstring\u001b[49m'); assert.equal(colors.bgBlue('string'), '\u001b[44mstring\u001b[49m'); assert.equal(colors.bgCyan('string'), '\u001b[46mstring\u001b[49m'); assert.equal(colors.bgGreen('string'), '\u001b[42mstring\u001b[49m'); assert.equal(colors.bgMagenta('string'), '\u001b[45mstring\u001b[49m'); assert.equal(colors.bgRed('string'), '\u001b[41mstring\u001b[49m'); assert.equal(colors.bgWhite('string'), '\u001b[47mstring\u001b[49m'); assert.equal(colors.bgYellow('string'), '\u001b[43mstring\u001b[49m'); assert.equal(colors.black('string'), '\u001b[30mstring\u001b[39m'); assert.equal(colors.blue('string'), '\u001b[34mstring\u001b[39m'); assert.equal(colors.bold('string'), '\u001b[1mstring\u001b[22m'); assert.equal(colors.cyan('string'), '\u001b[36mstring\u001b[39m'); assert.equal(colors.dim('string'), '\u001b[2mstring\u001b[22m'); assert.equal(colors.gray('string'), '\u001b[90mstring\u001b[39m'); assert.equal(colors.green('string'), '\u001b[32mstring\u001b[39m'); assert.equal(colors.hidden('string'), '\u001b[8mstring\u001b[28m'); assert.equal(colors.inverse('string'), '\u001b[7mstring\u001b[27m'); assert.equal(colors.italic('string'), '\u001b[3mstring\u001b[23m'); assert.equal(colors.magenta('string'), '\u001b[35mstring\u001b[39m'); assert.equal(colors.red('string'), '\u001b[31mstring\u001b[39m'); assert.equal(colors.reset('string'), '\u001b[0mstring\u001b[0m'); assert.equal(colors.strikethrough('string'), '\u001b[9mstring\u001b[29m'); assert.equal(colors.underline('string'), '\u001b[4mstring\u001b[24m'); assert.equal(colors.white('string'), '\u001b[37mstring\u001b[39m'); assert.equal(colors.yellow('string'), '\u001b[33mstring\u001b[39m'); }); it('should wrap a string with bold ansi codes:', () => { assert.equal(colors.black.bold('string'), '\u001b[30m\u001b[1mstring\u001b[22m\u001b[39m'); assert.equal(colors.blue.bold('string'), '\u001b[34m\u001b[1mstring\u001b[22m\u001b[39m'); assert.equal(colors.cyan.bold('string'), '\u001b[36m\u001b[1mstring\u001b[22m\u001b[39m'); assert.equal(colors.dim.bold('string'), '\u001b[2m\u001b[1mstring\u001b[22m\u001b[2m\u001b[22m'); assert.equal(colors.gray.bold('string'), '\u001b[90m\u001b[1mstring\u001b[22m\u001b[39m'); assert.equal(colors.green.bold('string'), '\u001b[32m\u001b[1mstring\u001b[22m\u001b[39m'); assert.equal(colors.magenta.bold('string'), '\u001b[35m\u001b[1mstring\u001b[22m\u001b[39m'); assert.equal(colors.red.bold('string'), '\u001b[31m\u001b[1mstring\u001b[22m\u001b[39m'); assert.equal(colors.white.bold('string'), '\u001b[37m\u001b[1mstring\u001b[22m\u001b[39m'); assert.equal(colors.yellow.bold('string'), '\u001b[33m\u001b[1mstring\u001b[22m\u001b[39m'); assert.equal(colors.bold.black('string'), '\u001b[1m\u001b[30mstring\u001b[39m\u001b[22m'); assert.equal(colors.bold.blue('string'), '\u001b[1m\u001b[34mstring\u001b[39m\u001b[22m'); assert.equal(colors.bold.cyan('string'), '\u001b[1m\u001b[36mstring\u001b[39m\u001b[22m'); assert.equal(colors.bold.dim('string'), '\u001b[1m\u001b[2mstring\u001b[22m\u001b[1m\u001b[22m'); assert.equal(colors.bold.gray('string'), '\u001b[1m\u001b[90mstring\u001b[39m\u001b[22m'); assert.equal(colors.bold.green('string'), '\u001b[1m\u001b[32mstring\u001b[39m\u001b[22m'); assert.equal(colors.bold.magenta('string'), '\u001b[1m\u001b[35mstring\u001b[39m\u001b[22m'); assert.equal(colors.bold.red('string'), '\u001b[1m\u001b[31mstring\u001b[39m\u001b[22m'); assert.equal(colors.bold.white('string'), '\u001b[1m\u001b[37mstring\u001b[39m\u001b[22m'); assert.equal(colors.bold.yellow('string'), '\u001b[1m\u001b[33mstring\u001b[39m\u001b[22m'); }); describe('chaining', () => { it('should create a color stack for chained colors', () => { let dim = colors.dim; assert.deepEqual(dim.stack, ['dim']); assert.deepEqual(dim.gray.stack, ['dim', 'gray']); assert.deepEqual(dim.gray.underline.stack, ['dim', 'gray', 'underline']); }); it('should correctly reset the color stack on bound colors', () => { let dim = colors.dim; let foo = dim('FOO'); let codes = dim.gray.underline('FOO'); assert.equal(dim('FOO'), foo); assert.equal(dim.gray.underline('FOO'), codes); assert.equal(dim('FOO'), foo); assert.equal(dim.gray.underline('FOO'), codes); assert.equal(dim('FOO'), foo); }); it('should correctly reset the color stack on chained _bound_ colors', () => { let dimRed = colors.dim.red; let dim = colors.dim; let underline = dimRed.underline; let foo = dim('FOO'); let codes = dimRed.underline('FOO'); assert.equal(dim('FOO'), foo); assert.equal(dimRed.underline('FOO'), codes); assert.equal(dim('FOO'), foo); assert.equal(dimRed.underline('FOO'), codes); assert.equal(dim('FOO'), foo); assert.equal(underline('foo'), colors.dim.red.underline('foo')); let redBold = colors.red.bold; let blueBold = colors.red.blue.bold('Blue Bold'); assert.equal(blueBold, '\u001b[31m\u001b[34m\u001b[1mBlue Bold\u001b[22m\u001b[39m\u001b[31m\u001b[39m'); assert.equal(redBold('Red Bold'), '\u001b[31m\u001b[1mRed Bold\u001b[22m\u001b[39m'); assert.equal(colors.red.bold('Red Bold'), '\u001b[31m\u001b[1mRed Bold\u001b[22m\u001b[39m'); }); }); describe('nesting', () => { it('should correctly wrap the colors on nested colors', () => { assert.equal(colors.red(`R${colors.green(`G${colors.blue('B')}G`)}R`), '\u001b[31mR\u001b[32mG\u001b[34mB\u001b[39m\u001b[31m\u001b[32mG\u001b[39m\u001b[31mR\u001b[39m'); }); }); describe('newlines', () => { it('should correctly wrap colors around newlines', () => { assert.equal(colors.bgRed('foo\nbar') + 'baz qux', '\u001b[41mfoo\u001b[49m\n\u001b[41mbar\u001b[49mbaz qux'); }); }); describe('enabled', () => { it('should disable ansi styling when colors.enabled is false', () => { colors.enabled = false; assert.equal(colors.red('foo bar'), 'foo bar'); assert.equal(colors.blue('foo bar'), 'foo bar'); assert.equal(colors.bold('foo bar'), 'foo bar'); colors.enabled = true; }); }); describe('FORCE_COLOR', () => { beforeEach(() => { delete process.env.FORCE_COLOR; decache('./'); }); it('should be enabled if FORCE_COLOR is not set', () => { const colors = require('./'); assert.equal(colors.enabled, true); }); it('should be enabled if FORCE_COLOR is set to 1', () => { process.env.FORCE_COLOR = '1'; const colors = require('./'); assert.equal(colors.enabled, true); }); it('should be disabled if FORCE_COLOR is set to 0', () => { process.env.FORCE_COLOR = '0'; const colors = require('./'); assert.equal(colors.enabled, false); }); }); describe('visible', () => { it('should mute output when colors.visible is false', () => { colors.visible = false; assert.equal(colors.red('foo bar'), ''); assert.equal(colors.blue('foo bar'), ''); assert.equal(colors.bold('foo bar'), ''); colors.visible = true; }); }); describe('unstyle', () => { it('should strip ANSI codes', () => { assert.equal(colors.unstyle(colors.blue.bold('foo bar baz')), 'foo bar baz'); assert.equal(colors.stripColor(colors.blue.bold('foo bar baz')), 'foo bar baz'); }); }); describe('hasColor', () => { it('should return true if a string has ansi styling', () => { assert(colors.hasColor(colors.blue.bold('foo bar baz'))); assert(colors.hasAnsi(colors.blue.bold('foo bar baz'))); }); it('should return false if a string does not have ansi styling', () => { assert(!colors.hasColor('foo bar baz')); assert(!colors.hasAnsi('foo bar baz')); }); it('should return true when used multiple times', () => { assert(colors.hasColor(colors.blue.bold('foo bar baz'))); assert(colors.hasColor(colors.blue.bold('foo bar baz'))); assert(colors.hasColor(colors.blue.bold('foo bar baz'))); assert(colors.hasColor(colors.blue.bold('foo bar baz'))); assert(colors.hasColor(colors.blue.bold('foo bar baz'))); }); }); }); ansi-colors-4.1.1/types/000077500000000000000000000000001350703452300151145ustar00rootroot00000000000000ansi-colors-4.1.1/types/index.d.ts000066400000000000000000000071341350703452300170220ustar00rootroot00000000000000// Imported from DefinitelyTyped project. // TypeScript definitions for ansi-colors // Definitions by: Rogier Schouten // Integrated by: Jordan Mele interface SymbolsType { check: string; cross: string; info: string; line: string; pointer: string; pointerSmall: string; question: string; warning: string; } type StyleArrayStructure = [number, number]; interface StyleArrayProperties { open: string; close: string; closeRe: string; } type StyleType = StyleArrayStructure & StyleArrayProperties; export interface StyleFunction extends StylesType { (s: string): string; } interface StylesType { // modifiers reset: T; bold: T; dim: T; italic: T; underline: T; inverse: T; hidden: T; strikethrough: T; // colors black: T; red: T; green: T; yellow: T; blue: T; magenta: T; cyan: T; white: T; gray: T; grey: T; // bright colors blackBright: T; redBright: T; greenBright: T; yellowBright: T; blueBright: T; magentaBright: T; cyanBright: T; whiteBright: T; // background colors bgBlack: T; bgRed: T; bgGreen: T; bgYellow: T; bgBlue: T; bgMagenta: T; bgCyan: T; bgWhite: T; // bright background colors bgBlackBright: T; bgRedBright: T; bgGreenBright: T; bgYellowBright: T; bgBlueBright: T; bgMagentaBright: T; bgCyanBright: T; bgWhiteBright: T; } // modifiers export const reset: StyleFunction; export const bold: StyleFunction; export const dim: StyleFunction; export const italic: StyleFunction; export const underline: StyleFunction; export const inverse: StyleFunction; export const hidden: StyleFunction; export const strikethrough: StyleFunction; // colors export const black: StyleFunction; export const red: StyleFunction; export const green: StyleFunction; export const yellow: StyleFunction; export const blue: StyleFunction; export const magenta: StyleFunction; export const cyan: StyleFunction; export const white: StyleFunction; export const gray: StyleFunction; export const grey: StyleFunction; // bright colors export const blackBright: StyleFunction; export const redBright: StyleFunction; export const greenBright: StyleFunction; export const yellowBright: StyleFunction; export const blueBright: StyleFunction; export const magentaBright: StyleFunction; export const cyanBright: StyleFunction; export const whiteBright: StyleFunction; // background colors export const bgBlack: StyleFunction; export const bgRed: StyleFunction; export const bgGreen: StyleFunction; export const bgYellow: StyleFunction; export const bgBlue: StyleFunction; export const bgMagenta: StyleFunction; export const bgCyan: StyleFunction; export const bgWhite: StyleFunction; // bright background colors export const bgBlackBright: StyleFunction; export const bgRedBright: StyleFunction; export const bgGreenBright: StyleFunction; export const bgYellowBright: StyleFunction; export const bgBlueBright: StyleFunction; export const bgMagentaBright: StyleFunction; export const bgCyanBright: StyleFunction; export const bgWhiteBright: StyleFunction; export let enabled: boolean; export let visible: boolean; export const ansiRegex: RegExp; /** * Remove styles from string */ export function stripColor(s: string): string; /** * Remove styles from string */ export function strip(s: string): string; /** * Remove styles from string */ export function unstyle(s: string): string; export const styles: StylesType; export const symbols: SymbolsType; /** * Outputs a string with check-symbol as prefix */ export function ok(...args: string[]): string; ansi-colors-4.1.1/types/test.ts000066400000000000000000000031221350703452300164410ustar00rootroot00000000000000// Imported from DefinitelyTyped project. import * as colors from '../'; let s: string; s = colors.reset("hello"); s = colors.bold("hello"); s = colors.dim("hello"); s = colors.italic("hello"); s = colors.underline("hello"); s = colors.inverse("hello"); s = colors.hidden("hello"); s = colors.strikethrough("hello"); // colors s = colors.black("hello"); s = colors.red("hello"); s = colors.green("hello"); s = colors.yellow("hello"); s = colors.blue("hello"); s = colors.magenta("hello"); s = colors.cyan("hello"); s = colors.white("hello"); s = colors.gray("hello"); s = colors.grey("hello"); // bright colors s = colors.blackBright("hello"); s = colors.redBright("hello"); s = colors.greenBright("hello"); s = colors.yellowBright("hello"); s = colors.blueBright("hello"); s = colors.magentaBright("hello"); s = colors.cyanBright("hello"); s = colors.whiteBright("hello"); // background colors s = colors.bgBlack("hello"); s = colors.bgRed("hello"); s = colors.bgGreen("hello"); s = colors.bgYellow("hello"); s = colors.bgBlue("hello"); s = colors.bgMagenta("hello"); s = colors.bgCyan("hello"); s = colors.bgWhite("hello"); // bright background colors s = colors.bgBlackBright("hello"); s = colors.bgRedBright("hello"); s = colors.bgGreenBright("hello"); s = colors.bgYellowBright("hello"); s = colors.bgBlueBright("hello"); s = colors.bgMagentaBright("hello"); s = colors.bgCyanBright("hello"); s = colors.bgRed.white.bold.underline("test"); s = colors.stripColor(colors.red("hello")); s = colors.unstyle(colors.red("hello")); s = colors.strip(colors.red("hello")); s = colors.ok("deployment succeeded!"); ansi-colors-4.1.1/types/tsconfig.json000066400000000000000000000007251350703452300176270ustar00rootroot00000000000000{ // Imported from DefinitelyTyped project. "compilerOptions": { "module": "commonjs", "lib": [ "es6" ], "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ "../" ], "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true, "esModuleInterop": true }, "files": [ "index.d.ts", "test.ts" ] }