Socket
Socket
Sign inDemoInstall

ansicolor

Package Overview
Dependencies
0
Maintainers
2
Versions
94
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.68 to 1.1.68

.vscode/settings.json

114

ansicolor.js

@@ -7,18 +7,30 @@ "use strict";

/* ------------------------------------------------------------------------ */
/* See https://misc.flogisoft.com/bash/tip_colors_and_formatting
------------------------------------------------------------------------ */
const
const colorCodes = [ 'black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'lightGray', '', 'default']
, colorCodesLight = ['darkGray', 'lightRed', 'lightGreen', 'lightYellow', 'lightBlue', 'lightMagenta', 'lightCyan', 'white', '']
, styleCodes = ['', 'bright', 'dim', 'italic', 'underline', '', '', 'inverse']
colorCodes = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', '', 'default'],
styleCodes = ['', 'bright', 'dim', 'italic', 'underline', '', '', 'inverse'],
types = { 0: 'style',
, asBright = { 'red': 'lightRed',
'green': 'lightGreen',
'yellow': 'lightYellow',
'blue': 'lightBlue',
'magenta': 'lightMagenta',
'cyan': 'lightCyan',
'black': 'darkGray',
'lightGray': 'white' }
, types = { 0: 'style',
2: 'unstyle',
3: 'color',
9: 'colorLight',
4: 'bgColor',
10: 'bgColorBright' },
10: 'bgColorLight' }
subtypes = { color: colorCodes,
, subtypes = { color: colorCodes,
colorLight: colorCodesLight,
bgColor: colorCodes,
bgColorBright: colorCodes,
bgColorLight: colorCodesLight,
style: styleCodes,

@@ -41,3 +53,3 @@ unstyle: styleCodes }

this.background = background
this.name = name
this.name = name
this.brightness = brightness

@@ -65,6 +77,7 @@ }

const prop = (color.background ? 'background:' : 'color:'),
rgb = ((this.brightness === Code.bright) ? Colors.rgbBright : Colors.rgb)[color.name]
const rgbName = ((color.brightness === Code.bright) && asBright[color.name]) || color.name
const alpha = (this.brightness === Code.dim) ? 0.5 : 1
const prop = (color.background ? 'background:' : 'color:')
, rgb = Colors.rgb[rgbName]
, alpha = (this.brightness === Code.dim) ? 0.5 : 1

@@ -117,4 +130,2 @@ return rgb

const camel = (a, b) => a + b.charAt (0).toUpperCase () + b.slice (1)
const replaceAll = (str, a, b) => str.split (a).join (b)

@@ -143,2 +154,5 @@

const camel = (a, b) => a + b.charAt (0).toUpperCase () + b.slice (1)
const stringWrappingMethods = (() => [

@@ -148,7 +162,19 @@

[k, 30 + i, Code.noColor],
[camel ('bg', k), 40 + i, Code.noBgColor],
[camel ('bgBright', k), 100 + i, Code.noBgColor]
[k, 30 + i, Code.noColor],
[camel ('bg', k), 40 + i, Code.noBgColor],
]),
...colorCodesLight.map ((k, i) => !k ? [] : [ // light color methods
[k, 90 + i, Code.noColor],
[camel ('bg', k), 100 + i, Code.noBgColor],
]),
/* THIS ONE IS FOR BACKWARDS COMPATIBILITY WITH PREVIOUS VERSIONS (had 'bright' instead of 'light' for backgrounds)
*/
...['', 'BrightRed', 'BrightGreen', 'BrightYellow', 'BrightBlue', 'BrightMagenta', 'BrightCyan'].map ((k, i) => !k ? [] : [
['bg' + k, 100 + i, Code.noBgColor],
]),
...styleCodes.map ((k, i) => !k ? [] : [ // style methods

@@ -228,5 +254,5 @@

const styledSpan = O.assign (
{ css: bold + italic + underline + foreColor.css (inverted) + bgColor.css (inverted) },
{ css: bold + italic + underline + foreColor.css (inverted) + bgColor.css (inverted) },
clean ({ bold: !!bold, color: foreColor.clean, bgColor: bgColor.clean }),
span)
span)

@@ -243,6 +269,8 @@ for (const k of styles) { styledSpan[k] = true }

case 'color' : color = new Color (false, c.subtype); break
case 'bgColor' : bgColor = new Color (true, c.subtype); break
case 'bgColorBright': bgColor = new Color (true, c.subtype, Code.bright); break
case 'color' :
case 'colorLight' : color = new Color (false, c.subtype); break
case 'bgColor' :
case 'bgColorLight' : bgColor = new Color (true, c.subtype); break
case 'style' : styles.add (c.subtype); break

@@ -326,22 +354,24 @@ case 'unstyle': styles.delete (c.subtype); break

black: [0, 0, 0],
red: [204, 0, 0],
green: [0, 204, 0],
yellow: [204, 102, 0],
blue: [0, 0, 255],
magenta: [204, 0, 204],
cyan: [0, 153, 255],
white: [255, 255, 255]
}
black: [0, 0, 0],
darkGray: [100, 100, 100],
lightGray: [200, 200, 200],
white: [255, 255, 255],
Colors.rgbBright = {
black: [0, 0, 0],
red: [255, 51, 0],
green: [51, 204, 51],
yellow: [255, 153, 51],
blue: [26, 140, 255],
magenta: [255, 0, 255],
cyan: [0, 204, 255],
white: [255, 255, 255]
red: [204, 0, 0],
lightRed: [255, 51, 0],
green: [0, 204, 0],
lightGreen: [51, 204, 51],
yellow: [204, 102, 0],
lightYellow: [255, 153, 51],
blue: [0, 0, 255],
lightBlue: [26, 140, 255],
magenta: [204, 0, 204],
lightMagenta: [255, 0, 255],
cyan: [0, 153, 255],
lightCyan: [0, 204, 255],
}

@@ -348,0 +378,0 @@

{
"name": "ansicolor",
"version": "1.0.68",
"version": "1.1.68",
"description": "The final solution to the ANSI color/style management. Works in browsers!",

@@ -90,3 +90,3 @@ "main": "ansicolor.js",

"coveralls": "^2.13.1",
"esdoc": "^0.5.2",
"esdoc": "^1.0.1",
"esdoc-node": "^1.0.2",

@@ -93,0 +93,0 @@ "eslint": "^4.2.0",

@@ -51,6 +51,6 @@ # ansicolor

```javascript
console.log ('foo' + ansi.green (ansi.inverse (ansi.bgBrightCyan ('bar')) + 'baz') + 'qux')
console.log ('foo' + ansi.green (ansi.inverse (ansi.bgLightCyan ('bar')) + 'baz') + 'qux')
```
```javascript
console.log (ansi.underline.bright.green ('foo' + ansi.dim.red.bgBrightCyan ('bar'))) // method chaining
console.log (ansi.underline.bright.green ('foo' + ansi.dim.red.bgLightCyan ('bar'))) // method chaining
```

@@ -74,11 +74,15 @@

'foreground colors'
.black.red.green.yellow.blue.magenta.cyan.white
.red.green.yellow.blue.magenta.cyan.white.darkGray.black
```
```javascript
'light foreground colors'
.lightRed.lightGreen.lightYellow.lightBlue.lightMagenta.lightCyan.lightGray
```
```javascript
'background colors'
.bgBlack.bgRed.bgGreen.bgYellow.bgBlue.bgMagenta.bgCyan.bgWhite
.bgRed.bgGreen.bgYellow.bgBlue.bgMagenta.bgCyan.bgWhite.bgDarkGray.bgBlack
```
```javascript
'bright background colors'
.bgBrightBlack.bgBrightRed.bgBrightGreen.bgBrightYellow.bgBrightBlue.bgBrightMagenta.bgBrightCyan.bgBrightWhite
'light background colors'
.bgLightRed.bgLightGreen.bgLightYellow.bgLightBlue.bgLightMagenta.bgLightCyan.bgLightGray
```

@@ -90,6 +94,6 @@ ```javascript

You also can use these method names programmatically:
You also can obtain all those style names (for reflection purposes):
```javascript
ansi.names // [ 'black', 'bgBlack', 'bgBrightBlack', 'red', 'bgRed', ...
ansi.names // ['red', 'green', ...
```

@@ -108,3 +112,3 @@

```javascript
const parsed = ansi.parse ('foo'.bgBrightRed.bright.italic + 'bar'.red.dim)
const parsed = ansi.parse ('foo'.bgLightRed.bright.italic + 'bar'.red.dim)
```

@@ -121,3 +125,3 @@

color: { bright: true },
bgColor: { name: 'red', bright: true },
bgColor: { name: 'lightRed' },
text: 'foo' },

@@ -132,3 +136,3 @@

You can change default RGB values:
You can change default RGB values (won't work in terminals, affects only the ANSI→CSS transformation part):

@@ -138,22 +142,24 @@ ```javascript

black: [0, 0, 0],
red: [204, 0, 0],
green: [0, 204, 0],
yellow: [204, 102, 0],
blue: [0, 0, 255],
magenta: [204, 0, 204],
cyan: [0, 153, 255],
white: [255, 255, 255]
}
black: [0, 0, 0],
darkGray: [100, 100, 100],
lightGray: [200, 200, 200],
white: [255, 255, 255],
ansi.rgbBright = {
black: [0, 0, 0],
red: [255, 51, 0],
green: [51, 204, 51],
yellow: [255, 153, 51],
blue: [26, 140, 255],
magenta: [255, 0, 255],
cyan: [0, 204, 255],
white: [255, 255, 255]
red: [204, 0, 0],
lightRed: [255, 51, 0],
green: [0, 204, 0],
lightGreen: [51, 204, 51],
yellow: [204, 102, 0],
lightYellow: [255, 153, 51],
blue: [0, 0, 255],
lightBlue: [26, 140, 255],
magenta: [204, 0, 204],
lightMagenta: [255, 0, 255],
cyan: [0, 153, 255],
lightCyan: [0, 204, 255],
}

@@ -160,0 +166,0 @@ ```

@@ -29,3 +29,3 @@ "use strict";

same ('foo' + ansi.green (ansi.inverse (ansi.bgBrightCyan ('bar') + 'baz') + 'qux'),
same ('foo' + ansi.green (ansi.inverse (ansi.bgLightCyan ('bar') + 'baz') + 'qux'),
'foo\u001b[32m\u001b[7m\u001b[106mbar\u001b[49mbaz\u001b[27mqux\u001b[39m')

@@ -36,3 +36,3 @@ })

same (ansi.underline.bright.green ('chai' + ansi.dim.red.bgBrightCyan ('ning')),
same (ansi.underline.bright.green ('chai' + ansi.dim.red.bgLightCyan ('ning')),
'\u001b[4m\u001b[22m\u001b[1m\u001b[32mchai\u001b[22m\u001b[2m\u001b[31m\u001b[106mning\u001b[49m\u001b[32m\u001b[22m\u001b[1m\u001b[39m\u001b[22m\u001b[24m')

@@ -61,3 +61,3 @@ })

same (('foo'.bgCyan + 'bar').bgRed, '\u001b[41m\u001b[46mfoo\u001b[41mbar\u001b[49m')
same (('foo'.bgBrightCyan + 'bar').bgBrightRed, '\u001b[101m\u001b[106mfoo\u001b[101mbar\u001b[49m')
same (('foo'.bgLightCyan + 'bar').bgLightRed, '\u001b[101m\u001b[106mfoo\u001b[101mbar\u001b[49m')
same (('foo'.underline + 'bar').underline, '\u001b[4m\u001b[4mfoo\u001b[4mbar\u001b[24m')

@@ -72,3 +72,3 @@

const parsed = ansi.parse ('foo'.bgBrightRed.bright.italic.underline + 'bar'.red.dim)
const parsed = ansi.parse ('foo'.bgLightRed.bright.italic.underline + 'bar'.red.dim)

@@ -84,3 +84,3 @@ assert.deepEqual ([...parsed], parsed.spans)

color: { bright: true },
bgColor: { name: 'red', bright: true },
bgColor: { name: 'lightRed' },
text: 'foo',

@@ -95,2 +95,13 @@ code: { value: 49 } },

it ('brightness semantics (CSS)', () => {
const parsed = ansi.parse ('foo'.bright.red)
assert.deepEqual (parsed.spans,[ { css: 'font-weight: bold;color:rgba(255,51,0,1);',
bold: true,
color: { name: 'red', bright: true },
text: 'foo',
code: { value: 22 } }])
})
it ('asChromeConsoleLogArguments works', () => {

@@ -125,43 +136,55 @@

assert.deepEqual (ansi.names, [
'black',
'bgBlack',
'bgBrightBlack',
'red',
'bgRed',
'bgBrightRed',
'green',
'bgGreen',
'bgBrightGreen',
'yellow',
'bgYellow',
'bgBrightYellow',
'blue',
'bgBlue',
'bgBrightBlue',
'magenta',
'bgMagenta',
'bgBrightMagenta',
'cyan',
'bgCyan',
'bgBrightCyan',
'white',
'bgWhite',
'bgBrightWhite',
'default',
'bgDefault',
'bgBrightDefault',
'bright',
'dim',
'italic',
'underline',
'inverse'
])
'black',
'bgBlack',
'red',
'bgRed',
'green',
'bgGreen',
'yellow',
'bgYellow',
'blue',
'bgBlue',
'magenta',
'bgMagenta',
'cyan',
'bgCyan',
'lightGray',
'bgLightGray',
'default',
'bgDefault',
'darkGray',
'bgDarkGray',
'lightRed',
'bgLightRed',
'lightGreen',
'bgLightGreen',
'lightYellow',
'bgLightYellow',
'lightBlue',
'bgLightBlue',
'lightMagenta',
'bgLightMagenta',
'lightCyan',
'bgLightCyan',
'white',
'bgWhite',
'bgBrightRed',
'bgBrightGreen',
'bgBrightYellow',
'bgBrightBlue',
'bgBrightMagenta',
'bgBrightCyan',
'bright',
'dim',
'italic',
'underline',
'inverse'
])
})
it ('changing .rgb and .rgbBright works', () => {
it ('changing .rgb works', () => {
ansi.rgb.red = [255,0,0]
ansi.rgbBright.red = [255,127,0]
ansi.rgb.red = [255,0,0]
assert.equal (ansi.parse ('foo'.red.bgBrightRed).spans[0].css, 'color:rgba(255,0,0,1);background:rgba(255,127,0,1);')
assert.equal (ansi.parse ('foo'.red.bgLightRed).spans[0].css, 'color:rgba(255,0,0,1);background:rgba(255,51,0,1);')
})

@@ -191,2 +214,7 @@

})
it ('compatible with previous versions where Light was called Bright in bg methods', () => {
same ('foo'.bgLightCyan, 'foo'.bgBrightCyan)
})
})

@@ -193,0 +221,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc