diff --git a/.gitattributes b/.gitattributes index 391f0a4..6313b56 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1 @@ -* text=auto -*.js text eol=lf +* text=auto eol=lf diff --git a/.github/funding.yml b/.github/funding.yml new file mode 100644 index 0000000..2aa563a --- /dev/null +++ b/.github/funding.yml @@ -0,0 +1,2 @@ +github: sindresorhus +tidelift: npm/ansi-styles diff --git a/.github/security.md b/.github/security.md new file mode 100644 index 0000000..5358dc5 --- /dev/null +++ b/.github/security.md @@ -0,0 +1,3 @@ +# Security Policy + +To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. diff --git a/.gitignore b/.gitignore index 3c3629e..239ecff 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +yarn.lock diff --git a/.travis.yml b/.travis.yml index 7d69d74..f98fed0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: node_js node_js: + - '12' + - '10' - '8' - - '6' - - '4' diff --git a/index.js b/index.js index 90a871c..4ea8acd 100644 --- a/index.js +++ b/index.js @@ -1,18 +1,18 @@ 'use strict'; const colorConvert = require('color-convert'); -const wrapAnsi16 = (fn, offset) => function () { - const code = fn.apply(colorConvert, arguments); +const wrapAnsi16 = (fn, offset) => (...args) => { + const code = fn(...args); return `\u001B[${code + offset}m`; }; -const wrapAnsi256 = (fn, offset) => function () { - const code = fn.apply(colorConvert, arguments); +const wrapAnsi256 = (fn, offset) => (...args) => { + const code = fn(...args); return `\u001B[${38 + offset};5;${code}m`; }; -const wrapAnsi16m = (fn, offset) => function () { - const rgb = fn.apply(colorConvert, arguments); +const wrapAnsi16m = (fn, offset) => (...args) => { + const rgb = fn(...args); return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`; }; @@ -39,9 +39,9 @@ function assembleStyles() { magenta: [35, 39], cyan: [36, 39], white: [37, 39], - gray: [90, 39], // Bright color + blackBright: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], @@ -72,15 +72,14 @@ function assembleStyles() { } }; - // Fix humans - styles.color.grey = styles.color.gray; - - for (const groupName of Object.keys(styles)) { - const group = styles[groupName]; - - for (const styleName of Object.keys(group)) { - const style = group[styleName]; + // Alias bright black as gray (and grey) + styles.color.gray = styles.color.blackBright; + styles.bgColor.bgGray = styles.bgColor.bgBlackBright; + styles.color.grey = styles.color.blackBright; + styles.bgColor.bgGrey = styles.bgColor.bgBlackBright; + for (const [groupName, group] of Object.entries(styles)) { + for (const [styleName, style] of Object.entries(group)) { styles[styleName] = { open: `\u001B[${style[0]}m`, close: `\u001B[${style[1]}m` @@ -128,13 +127,11 @@ function assembleStyles() { rgb: wrapAnsi16m(rgb2rgb, 10) }; - for (let key of Object.keys(colorConvert)) { - if (typeof colorConvert[key] !== 'object') { + for (let [key, suite] of Object.entries(colorConvert)) { + if (typeof suite !== 'object') { continue; } - const suite = colorConvert[key]; - if (key === 'ansi16') { key = 'ansi'; } diff --git a/package.json b/package.json index 65edb48..112aad3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ansi-styles", - "version": "3.2.1", + "version": "4.0.0", "description": "ANSI escape codes for styling strings in the terminal", "license": "MIT", "repository": "chalk/ansi-styles", @@ -10,7 +10,7 @@ "url": "sindresorhus.com" }, "engines": { - "node": ">=4" + "node": ">=8" }, "scripts": { "test": "xo && ava", @@ -42,15 +42,11 @@ "text" ], "dependencies": { - "color-convert": "^1.9.0" + "color-convert": "^2.0.0" }, "devDependencies": { - "ava": "*", - "babel-polyfill": "^6.23.0", + "ava": "^1.4.1", "svg-term-cli": "^2.1.1", - "xo": "*" - }, - "ava": { - "require": "babel-polyfill" + "xo": "^0.24.0" } } diff --git a/readme.md b/readme.md index 3158e2d..8a47aac 100644 --- a/readme.md +++ b/readme.md @@ -4,7 +4,7 @@ You probably want the higher-level [chalk](https://github.com/chalk/chalk) module for styling your strings. - + ## Install @@ -60,7 +60,7 @@ Each style has an `open` and `close` property. - `magenta` - `cyan` - `white` -- `gray` ("bright black") +- `blackBright` (alias: `gray`, `grey`) - `redBright` - `greenBright` - `yellowBright` @@ -79,7 +79,7 @@ Each style has an `open` and `close` property. - `bgMagenta` - `bgCyan` - `bgWhite` -- `bgBlackBright` +- `bgBlackBright` (alias: `bgGray`, `bgGrey`) - `bgRedBright` - `bgGreenBright` - `bgYellowBright` @@ -142,6 +142,14 @@ style.bgColor.ansi16m.hex('#C0FFEE'); // Hex (RGB) to 16 million color backgroun - [Josh Junon](https://github.com/qix-) -## License +--- -MIT +