Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ansis

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ansis - npm Package Compare versions

Comparing version 1.5.4 to 1.5.5

2

bundle.js

@@ -1,1 +0,1 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e=e=>{let[,t]=/([a-f\d]{3,6})/i.exec(e)||[],r=t?t.length:0;if(3===r)t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2];else if(6!==r)return[0,0,0];let n=parseInt(t,16);return[n>>16&255,n>>8&255,255&n]},t=(e,t,r)=>t>e?t:e>r?r:e,r=(e,t,r)=>{if(""===t)return e;let n=e.indexOf(t);if(n<0)return e;let i=t.length,o=0,l="";for(;~n;)l+=e.slice(o,n)+r,o=n+i,n=e.indexOf(t,o);return l+e.slice(o)},n=(e=>{const t=e=>!!l.find((t=>e.test(t))),r=e||("undefined"!=typeof process?process:{}),{stdout:n,platform:i}=r,o=r.env||{},l=r.argv||[],s="FORCE_COLOR"in o,g=o.FORCE_COLOR,c="true"===g||parseInt(g)>0,a="NO_COLOR"in o||s&&!c||t(/^-{1,2}(no-color|color=false|color=never)$/),p=s&&c||t(/^-{1,2}(color|color=true|color=always)$/),b=n&&"isTTY"in n&&/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(o.TERM);return!a&&(p||b||"win32"===i||"CI"in o)})(),i={open:"",close:""},o=n?(e,t)=>({open:`[${e}m`,close:`[${t}m`}):()=>i,l=n?e=>({open:`[38;5;${e}m`,close:""}):()=>i,s=n?e=>({open:`[48;5;${e}m`,close:""}):()=>i,g=n?(e,t,r)=>({open:`[38;2;${e};${t};${r}m`,close:""}):()=>i,c=n?(e,t,r)=>({open:`[48;2;${e};${t};${r}m`,close:""}):()=>i,a={visible:i,reset:o(0,0),inverse:o(7,27),hidden:o(8,28),bold:o(1,22),dim:o(2,22),faint:o(2,22),italic:o(3,23),underline:o(4,24),doubleUnderline:o(21,24),strikethrough:o(9,29),strike:o(9,29),frame:o(51,54),encircle:o(52,54),overline:o(53,55),black:o(30,39),red:o(31,39),green:o(32,39),yellow:o(33,39),blue:o(34,39),magenta:o(35,39),cyan:o(36,39),white:o(37,39),gray:o(90,39),grey:o(90,39),blackBright:o(90,39),redBright:o(91,39),greenBright:o(92,39),yellowBright:o(93,39),blueBright:o(94,39),magentaBright:o(95,39),cyanBright:o(96,39),whiteBright:o(97,39),bgBlack:o(40,49),bgRed:o(41,49),bgGreen:o(42,49),bgYellow:o(43,49),bgBlue:o(44,49),bgMagenta:o(45,49),bgCyan:o(46,49),bgWhite:o(47,49),bgBlackBright:o(100,49),bgRedBright:o(101,49),bgGreenBright:o(102,49),bgYellowBright:o(103,49),bgBlueBright:o(104,49),bgMagentaBright:o(105,49),bgCyanBright:o(106,49),bgWhiteBright:o(107,49)},{defineProperty:p,defineProperties:b,setPrototypeOf:u}=Object,f=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,d=/(\r*\n)/g,h=function(){const t=e=>e;return t.strip=e=>e.replace(f,""),t.extend=r=>{for(let t in r){let n=r[t],i=null!=n.open?n:g(...e(n));x[t]={get(){const e=B(this,i);return p(this,t,{value:e}),e}}}y=b((()=>{}),x),u(t,y)},t.extend(a),t},B=({props:e},{open:t,close:r})=>{const n=(e,...t)=>O(e,t,n.props);let i=t,o=r;return void 0!==e&&(i=e.openStack+t,o=r+e.closeStack),u(n,y),n.props={open:t,close:r,openStack:i,closeStack:o,parent:e},n.open=i,n.close=o,n},O=(e,t,n)=>{if(!e)return"";const{openStack:i,closeStack:o}=n;let l=null!=e.raw?String.raw(e,...t):e;if(~l.indexOf(""))for(;void 0!==n;)l=r(l,n.close,n.open),n=n.parent;return~l.indexOf("\n")&&(l=l.replace(d,o+"$1"+i)),i+l+o},m={ansi:e=>l(t(e,0,255)),bgAnsi:e=>s(t(e,0,255)),hex:t=>g(...e(t)),bgHex:t=>c(...e(t)),rgb:(e,r,n)=>g(t(e,0,255),t(r,0,255),t(n,0,255)),bgRgb:(e,r,n)=>c(t(e,0,255),t(r,0,255),t(n,0,255))},x={};let y;for(let e in m)x[e]={get(){return(...t)=>B(this,m[e](...t))}};x.ansi256=x.fg=x.ansi,x.bgAnsi256=x.bg=x.bgAnsi;const v=new h;exports.Ansis=h,exports.default=v;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e=e=>{let[,t]=/([a-f\d]{3,6})/i.exec(e)||[],r=t?t.length:0;if(3===r)t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2];else if(6!==r)return[0,0,0];let n=parseInt(t,16);return[n>>16&255,n>>8&255,255&n]},t=(e,t,r)=>t>e?t:e>r?r:e,r=(e,t,r)=>{if(""===t)return e;let n=e.indexOf(t);if(n<0)return e;let i=t.length,o=0,l="";for(;~n;)l+=e.slice(o,n)+r,o=n+i,n=e.indexOf(t,o);return l+e.slice(o)},n={open:"",close:""},i=(e=>{const t=e=>!!l.find((t=>e.test(t))),r=e||("undefined"!=typeof process?process:{}),{stdout:n,platform:i}=r,o=r.env||{},l=r.argv||[],s="FORCE_COLOR"in o,g=o.FORCE_COLOR,c="true"===g||parseInt(g)>0,a="NO_COLOR"in o||s&&!c||t(/^-{1,2}(no-color|color=false|color=never)$/),b=s&&c||t(/^-{1,2}(color|color=true|color=always)$/),p=n&&"isTTY"in n&&/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(o.TERM);return!a&&(b||p||"win32"===i||"CI"in o)})()?(e,t)=>({open:`[${e}m`,close:`[${t}m`}):()=>n,o=(e,t,r)=>i(`38;2;${e};${t};${r}`,39),l=(e,t,r)=>i(`48;2;${e};${t};${r}`,49),s={visible:n,reset:i(0,0),inverse:i(7,27),hidden:i(8,28),bold:i(1,22),dim:i(2,22),faint:i(2,22),italic:i(3,23),underline:i(4,24),doubleUnderline:i(21,24),strikethrough:i(9,29),strike:i(9,29),frame:i(51,54),encircle:i(52,54),overline:i(53,55),black:i(30,39),red:i(31,39),green:i(32,39),yellow:i(33,39),blue:i(34,39),magenta:i(35,39),cyan:i(36,39),white:i(37,39),grey:i(90,39),gray:i(90,39),blackBright:i(90,39),redBright:i(91,39),greenBright:i(92,39),yellowBright:i(93,39),blueBright:i(94,39),magentaBright:i(95,39),cyanBright:i(96,39),whiteBright:i(97,39),bgBlack:i(40,49),bgRed:i(41,49),bgGreen:i(42,49),bgYellow:i(43,49),bgBlue:i(44,49),bgMagenta:i(45,49),bgCyan:i(46,49),bgWhite:i(47,49),bgBlackBright:i(100,49),bgRedBright:i(101,49),bgGreenBright:i(102,49),bgYellowBright:i(103,49),bgBlueBright:i(104,49),bgMagentaBright:i(105,49),bgCyanBright:i(106,49),bgWhiteBright:i(107,49)},{defineProperty:g,defineProperties:c,setPrototypeOf:a}=Object,b=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,p=/(\r*\n)/g,u=function(){const t=e=>e;return t.strip=e=>e.replace(b,""),t.extend=r=>{for(let t in r){let n=r[t],i=null!=n.open?n:o(...e(n));B[t]={get(){const e=f(this,i);return g(this,t,{value:e}),e}}}O=c((()=>{}),B),a(t,O)},t.extend(s),t},f=({props:e},{open:t,close:r})=>{const n=(e,...t)=>d(e,t,n.props);let i=t,o=r;return void 0!==e&&(i=e.openStack+t,o=r+e.closeStack),a(n,O),n.props={open:t,close:r,openStack:i,closeStack:o,parent:e},n.open=i,n.close=o,n},d=(e,t,n)=>{if(!e)return"";const{openStack:i,closeStack:o}=n;let l=null!=e.raw?String.raw(e,...t):e;if(~l.indexOf(""))for(;void 0!==n;)l=r(l,n.close,n.open),n=n.parent;return~l.indexOf("\n")&&(l=l.replace(p,o+"$1"+i)),i+l+o},h={ansi:e=>(e=>i(`38;5;${e}`,39))(t(e,0,255)),bgAnsi:e=>(e=>i(`48;5;${e}`,49))(t(e,0,255)),hex:t=>o(...e(t)),bgHex:t=>l(...e(t)),rgb:(e,r,n)=>o(t(e,0,255),t(r,0,255),t(n,0,255)),bgRgb:(e,r,n)=>l(t(e,0,255),t(r,0,255),t(n,0,255))},B={};let O;for(let e in h)B[e]={get(){return(...t)=>f(this,h[e](...t))}};B.ansi256=B.fg=B.ansi,B.bgAnsi256=B.bg=B.bgAnsi;const x=new u;exports.Ansis=u,exports.default=x;
{
"name": "ansis",
"version": "1.5.4",
"version": "1.5.5",
"description": "Formatting text in terminal with ANSI colors & styles.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -59,7 +59,13 @@ <div align="center">

You can import module and named colors with ESM or CommonJS syntax.
```js
import { black, red, cyan, inverse, reset } from 'ansis/colors'; // named import
import ansis from 'ansis'; // ESM
const ansis = require('ansis'); // CommonJS
// ESM
import ansis from 'ansis';
import { red, black, inverse, reset } from 'ansis/colors';
// CommonJS
const ansis = require('ansis');
const { red, black, inverse, reset } = require('ansis/colors');
console.log(ansis.green`Hello ${inverse`ANSI`} World!`);

@@ -70,3 +76,3 @@ console.log(black.bgYellow`Warning:${reset.cyan` /path/to/file.js`} ${red`not found!`}`);

Output:\
![output](docs/img/quik-start-output.png?raw=true "output")
![screenshot "Hello ANSI World!"](docs/img/quik-start-output.png?raw=true)

@@ -77,11 +83,11 @@

You can import named colors, styles and functions.
All imported colors and styles **are chainable**.
All imported colors and styles are **chainable**.
> **Note**
>
> Imported code is not treeshakeable.\
> Imported code is not treeshakeable.
> Don't worry, full functional code is `3KB` only.
```js
import { red, green, blue, yellow, hex, bold, italic } from 'ansis/colors';
import { red, hex, italic } from 'ansis/colors';

@@ -97,15 +103,21 @@ red.bold('text');

All colors, styles and functions are chainable. Each color or style can be combined in any order.
```js
import ansis from 'ansis';
import { red, bold, underline } from 'ansis/colors';
import { red, cyan, bold, italic, hex } from 'ansis/colors';
// with namespace
ansis.red('text');
ansis.cyan.italic('text');
ansis.blau.underline.bold('text');
ansis.cyan.bold('text');
ansis.hex('#FF75D1').bgCyan.bold('text');
ansis.bold.bgHex('#FF75D1').cyan('text');
ansis.italic.bold.strike.yellow.bgMagentaBright('text');
// with named import
red.italic.bold('text');
bold.italic.red('text');
underline.yellowBright('text');
red('text');
cyan.bold('text');
hex('#FF75D1').bgCyan.bold('text');
bold.bgHex('#FF75D1').cyan('text');
italic.bold.strike.yellow.bgMagentaBright('text');
```

@@ -117,9 +129,23 @@

Each color or style can be nested with one another.
```js
import { red, bold, italic, underline } from 'ansis/colors';
import { red, italic, underline } from 'ansis/colors';
white(`MakBookPro, ${cyan.bold(`RAM:`)} 64 GB`);
white(`MakBookPro, ${cyan.bold(`RAM:`)} 64 GB | ${green.bold(`GPU:`)} 32 cores`);
red(`red ${italic(`red italic ${underline(`red italic underline`)}`)} red`);
// deep nested chained styles
green(
`green ${yellow(
`yellow ${magenta(
`magenta ${cyan(
`cyan ${red.italic.underline(`red italic underline`)} cyan`,
)} magenta`,
)} yellow`,
)} green`,
);
```
Output:\
![screenshot nested styles](docs/img/ansis-nested.png?raw=true)

@@ -129,3 +155,3 @@ <a id="templateLiterals" name="templateLiterals" href="#templateLiterals"></a>

Template literals allow to be complex template more readable and shortly.\
Template literals allow you to make a complex template more readable and shorter.\
None of the existing libraries (chalk, kleur, colorette, colors.js etc.) support nested template strings.\

@@ -135,4 +161,4 @@ This does it only one library - `ansis`. Use it and enjoy!

```js
// import used standard styles, colors and functions
import { red, green, greenBright, cyan, cyanBright, bold, italic, visible, hex } from 'ansis/colors';
// import used base styles, colors and functions
import { red, green, bold, visible, inverse, hex } from 'ansis/colors';

@@ -149,19 +175,33 @@ // define custom colors

// chained
bold.cyan`text`;
italic.yellowBright`text`;
red.bold`text`;
bold.yellowBright`text`;
hex('#FF75D1').bgYellow.bold`text`;
// nested
white`MakBookPro, ${cyan.bold`RAM:`} 64 GB`;
white`MakBookPro, ${cyan.bold`RAM:`} 64 GB | ${green.bold`GPU:`} 32 cores`;
white`MakBookPro, ${cyan.bold`RAM: ${cyanBright`64`} GB`} | ${green.bold`GPU: ${greenBright`32`} cores`}`;
red`red ${green`green ${pink.italic`pink italic`} green`} red`;
```
// mutiline nested
console.log(visible`
CPU: ${red.bold`${33}%`}
RAM: ${green`${44}%`}
DISK: ${hex('#FFAB40')`${55}%`}
`);
Multiline nested example.
```js
let cpu = 33;
let ram = 44;
let disk = 55;
// normal colors
visible`
CPU: ${red`${cpu}%`}
RAM: ${green`${ram}%`}
DISK: ${hex('#FFAB40')`${disk}%`}
`;
// inversed colors
inverse`
CPU: ${red`${cpu}%`}
RAM: ${green`${ram}%`}
DISK: ${hex('#FFAB40')`${disk}%`}
`;
```
Output:\
![screenshot multiline nested](docs/img/ansis-multiline-nested.png?raw=true)

@@ -172,2 +212,4 @@

Colors and styles have standard names used by many popular libraries, such as [chalk][chalk], [colorette][colorette], [kleur][kleur], [cli-color][cli-color], [ansi-colors][ansi-colors].
| Foreground colors | Background colors | Styles |

@@ -174,0 +216,0 @@ |:----------------------|:------------------|--------------------------------------------|

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc