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.6.0-beta.0 to 2.0.0

80

index.d.ts

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

type ColorExtend = Record<string, string|{open:string, close:string}>
type ColorExtend = Record<string, string | { open: string, close: string }>

@@ -206,3 +206,3 @@ declare const ansis: Ansis;

}
declare const Ansis: new (str: string) => Ansis;
declare const Ansis: new () => Ansis;

@@ -274,2 +274,76 @@ /**

export { AnsiColors, AnsiColorsExtend, AnsiStyles, Ansis, ansis as default };
declare function ansi256(code: number): Ansis;
declare function fg(code: number): Ansis;
declare function bgAnsi256(code: number): Ansis;
declare function bg(code: number): Ansis;
declare function rgb(red: number, green: number, blue: number): Ansis;
declare function bgRgb(red: number, green: number, blue: number): Ansis;
declare function hex(code: string): Ansis;
declare function bgHex(code: string): Ansis;
// misc
declare const reset: Ansis;
declare const inverse: Ansis;
declare const hidden: Ansis;
declare const visible: Ansis;
// styles
declare const bold: Ansis;
declare const dim: Ansis;
declare const faint: Ansis;
declare const italic: Ansis;
declare const underline: Ansis;
declare const doubleUnderline: Ansis;
declare const strikethrough: Ansis;
declare const strike: Ansis;
declare const frame: Ansis;
declare const encircle: Ansis;
declare const overline: Ansis;
// foreground colors
declare const black: Ansis;
declare const red: Ansis;
declare const green: Ansis;
declare const yellow: Ansis;
declare const blue: Ansis;
declare const magenta: Ansis;
declare const cyan: Ansis;
declare const white: Ansis;
declare const gray: Ansis;
declare const grey: Ansis;
declare const blackBright: Ansis;
declare const redBright: Ansis;
declare const greenBright: Ansis;
declare const yellowBright: Ansis;
declare const blueBright: Ansis;
declare const magentaBright: Ansis;
declare const cyanBright: Ansis;
declare const whiteBright: Ansis;
// background colors
declare const bgBlack: Ansis;
declare const bgRed: Ansis;
declare const bgGreen: Ansis;
declare const bgYellow: Ansis;
declare const bgBlue: Ansis;
declare const bgMagenta: Ansis;
declare const bgCyan: Ansis;
declare const bgWhite: Ansis;
declare const bgBlackBright: Ansis;
declare const bgRedBright: Ansis;
declare const bgGreenBright: Ansis;
declare const bgYellowBright: Ansis;
declare const bgBlueBright: Ansis;
declare const bgMagentaBright: Ansis;
declare const bgCyanBright: Ansis;
declare const bgWhiteBright: Ansis;
export { type AnsiColors, type AnsiColorsExtend, type AnsiStyles, Ansis, ansi256, bg, bgAnsi256, bgBlack, bgBlackBright, bgBlue, bgBlueBright, bgCyan, bgCyanBright, bgGreen, bgGreenBright, bgHex, bgMagenta, bgMagentaBright, bgRed, bgRedBright, bgRgb, bgWhite, bgWhiteBright, bgYellow, bgYellowBright, black, blackBright, blue, blueBright, bold, cyan, cyanBright, ansis as default, dim, doubleUnderline, encircle, faint, fg, frame, gray, green, greenBright, grey, hex, hidden, inverse, italic, magenta, magentaBright, overline, red, redBright, reset, rgb, strike, strikethrough, underline, visible, white, whiteBright, yellow, yellowBright };

6

index.js

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

'use strict';
const colors = require('./colors.js');
module.exports = colors.default;
module.exports.Ansis = colors.Ansis;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e=e=>{let[,r]=/([a-f\d]{3,6})/i.exec(e)||[],t=r?r.length:0;if(3===t)r=r[0]+r[0]+r[1]+r[1]+r[2]+r[2];else if(6!==t)return[0,0,0];let g=parseInt(r,16);return[g>>16&255,g>>8&255,255&g]},r=(e,r,t)=>r>e?r:e>t?t:e,t=(e,r,t)=>{if(""===r)return e;let g=e.indexOf(r);if(g<0)return e;let i=r.length,o=0,n="";for(;~g;)n+=e.slice(o,g)+t,o=g+i,g=e.indexOf(r,o);return n+e.slice(o)},g={open:"",close:""},i=(e=>{const r=e=>!!o.find((r=>e.test(r))),t=globalThis,g=null!=t.Deno,i=t.process||t.Deno||{},o=i.argv||i.args||[];let n={};try{n=g?i.env.toObject():i.env||{}}catch(e){}const s="FORCE_COLOR",l=s in n,b=n[s],a="true"===b||parseInt(b,10)>0,p="NO_COLOR"in n||l&&!a||r(/^-{1,2}(no-color|color=false|color=never)$/),h=l&&a||r(/^-{1,2}(color|color=true|color=always)$/),x="win32"===(g?t.Deno.build.os:i.platform),c=g?t.Deno.isatty(1):i.stdout&&"isTTY"in i.stdout,B=(n.NEXT_RUNTIME||"").indexOf("edge")>-1,d=(c||B)&&/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(n.TERM);return!p&&(h||d||x||"CI"in n)})()?(e,r)=>({open:`[${e}m`,close:`[${r}m`}):()=>g,o=(e,r,t)=>i(`38;2;${e};${r};${t}`,39),n=(e,r,t)=>i(`48;2;${e};${r};${t}`,49),s={visible:g,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:l,defineProperties:b,setPrototypeOf:a}=Object,p=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,h=/(\r*\n)/g,x=function(){const r=e=>e;return r.strip=e=>e.replace(p,""),r.extend=t=>{for(let r in t){let g=t[r],i=null!=g.open?g:o(...e(g));u[r]={get(){const e=c(this,i);return l(this,r,{value:e}),e}}}f=b((()=>{}),u),a(r,f)},r.extend(s),r},c=({props:e},{open:r,close:t})=>{const g=(e,...r)=>B(e,r,g.props);let i=r,o=t;return void 0!==e&&(i=e.openStack+r,o=t+e.closeStack),a(g,f),g.props={open:r,close:t,openStack:i,closeStack:o,props:e},g.open=i,g.close=o,g},B=(e,r,g)=>{if(!e)return"";const{openStack:i,closeStack:o}=g;let n=null!=e.raw?String.raw(e,...r):e;if(~n.indexOf(""))for(;void 0!==g;)n=t(n,g.close,g.open),g=g.props;return~n.indexOf("\n")&&(n=n.replace(h,o+"$1"+i)),i+n+o},d={ansi:e=>(e=>i(`38;5;${e}`,39))(r(e,0,255)),bgAnsi:e=>(e=>i(`48;5;${e}`,49))(r(e,0,255)),hex:r=>o(...e(r)),bgHex:r=>n(...e(r)),rgb:(e,t,g)=>o(r(e,0,255),r(t,0,255),r(g,0,255)),bgRgb:(e,t,g)=>n(r(e,0,255),r(t,0,255),r(g,0,255))},u={};let f;for(let e in d)u[e]={get(){return(...r)=>c(this,d[e](...r))}};u.ansi256=u.fg=u.ansi,u.bgAnsi256=u.bg=u.bgAnsi;const y=new x,{ansi256:k,ansi:w,fg:v,bgAnsi256:m,bgAnsi:O,bg:R,rgb:$,bgRgb:C,hex:A,bgHex:M,reset:S,inverse:Y,hidden:G,visible:T,bold:W,dim:_,faint:D,italic:E,underline:I,doubleUnderline:P,strikethrough:U,strike:j,frame:H,encircle:N,overline:L,black:q,red:F,green:X,yellow:Z,blue:z,magenta:J,cyan:K,white:Q,gray:V,grey:ee,blackBright:re,redBright:te,greenBright:ge,yellowBright:ie,blueBright:oe,magentaBright:ne,cyanBright:se,whiteBright:le,bgBlack:be,bgRed:ae,bgGreen:pe,bgYellow:he,bgBlue:xe,bgMagenta:ce,bgCyan:Be,bgWhite:de,bgBlackBright:ue,bgRedBright:fe,bgGreenBright:ye,bgYellowBright:ke,bgBlueBright:we,bgMagentaBright:ve,bgCyanBright:me,bgWhiteBright:Oe}=y;exports.Ansis=x,exports.ansi=w,exports.ansi256=k,exports.bg=R,exports.bgAnsi=O,exports.bgAnsi256=m,exports.bgBlack=be,exports.bgBlackBright=ue,exports.bgBlue=xe,exports.bgBlueBright=we,exports.bgCyan=Be,exports.bgCyanBright=me,exports.bgGreen=pe,exports.bgGreenBright=ye,exports.bgHex=M,exports.bgMagenta=ce,exports.bgMagentaBright=ve,exports.bgRed=ae,exports.bgRedBright=fe,exports.bgRgb=C,exports.bgWhite=de,exports.bgWhiteBright=Oe,exports.bgYellow=he,exports.bgYellowBright=ke,exports.black=q,exports.blackBright=re,exports.blue=z,exports.blueBright=oe,exports.bold=W,exports.cyan=K,exports.cyanBright=se,exports.default=y,exports.dim=_,exports.doubleUnderline=P,exports.encircle=N,exports.faint=D,exports.fg=v,exports.frame=H,exports.gray=V,exports.green=X,exports.greenBright=ge,exports.grey=ee,exports.hex=A,exports.hidden=G,exports.inverse=Y,exports.italic=E,exports.magenta=J,exports.magentaBright=ne,exports.overline=L,exports.red=F,exports.redBright=te,exports.reset=S,exports.rgb=$,exports.strike=j,exports.strikethrough=U,exports.underline=I,exports.visible=T,exports.white=Q,exports.whiteBright=le,exports.yellow=Z,exports.yellowBright=ie;
{
"name": "ansis",
"version": "1.6.0-beta.0",
"version": "2.0.0",
"description": "Colorize text in terminal or console output with ANSI colors & styles",

@@ -57,3 +57,2 @@ "keywords": [

".": {
"types": "./index.d.ts",
"import": "./index.js",

@@ -63,5 +62,4 @@ "require": "./index.js"

"./colors": {
"types": "./colors.d.ts",
"import": "./colors.js",
"require": "./colors.js"
"import": "./index.js",
"require": "./index.js"
}

@@ -75,4 +73,2 @@ },

"index.js",
"colors.d.ts",
"colors.js",
"package.json",

@@ -79,0 +75,0 @@ "LICENSE",

@@ -35,13 +35,14 @@ <div align="center">

## Highlights
## 💡 Highlights
- supports both **ESM** and **CommonJS**
- supports **Deno**, **Next.JS** runtime
- up to **x3.5 faster** than **chalk**, [see benchmarks](#benchmark)
- dist code is only **5 KB** incl. named import for ESM and CommonJS
- up to **x3 faster** than **chalk**, [see benchmarks](#benchmark)
- dist code is only **5 KB** incl. named import of all styles
- [standard API](#base-colors) like **chalk**
- default and [named import](#named-import) `import { red, bold, rgb } from 'ansis/colors'`
- [chained syntax](#chained-syntax) `red.bold('text')`
- default import `import ansis from 'ansis'`, usage `ansis.red('error')`
- [named import](#named-import) `import { red } from 'ansis'`, usage ``` red('error') ```
- [chained syntax](#chained-syntax) `red.bold.underline('text')`
- [nested **template strings**](#nested-syntax) ``` red`R ${green`G`} R` ```
- [ANSI 256 colors](#256-colors) and [Truecolor](#truecolor) (**RGB**, **HEX**)
- [ANSI 256 colors](#256-colors) and [Truecolor](#truecolor) (**RGB**, **HEX**) ``` rgb(224, 17, 95)`Ruby` ```, ``` hex('#96C')`Amethyst` ```
- [extending of base colors](#extend-colors) with named **truecolors**

@@ -57,2 +58,7 @@ - [ANSI codes](#escape-codes) as `open` and `close` property for each

## ❓Question / Feature Request / Bug
If you have discovered a bug or have a feature suggestion, feel free to create
an [issue](https://github.com/webdiscus/ansis/issues) on GitHub.
<a id="install" name="install" href="#install"></a>

@@ -68,17 +74,16 @@

You can import module and named colors with ESM or CommonJS syntax.
You can import default module or named colors with ESM or CommonJS syntax.
```js
// ESM
// ESM default import
import ansis from 'ansis';
import { red, green, blue } from 'ansis/colors';
// ESM named import
import { red, green, blue } from 'ansis';
// CommonJS
// CommonJS default import
const ansis = require('ansis');
const { red, green, blue } = require('ansis/colors');
// CommonJS named import
const { red, green, blue } = require('ansis');
// default import
console.log(ansis.green(`Success!`));
// named import
console.log(ansis.green('Success!'));
console.log(green('Success!'));

@@ -100,3 +105,3 @@

```js
import { red, black, inverse, reset } from 'ansis/colors';
import { red, black, inverse, reset } from 'ansis';

@@ -129,3 +134,3 @@ console.log(green`Hello ${inverse`ANSI`} World!

// named import
import { red, hex, italic } from 'ansis/colors';
import { red, hex, italic } from 'ansis';

@@ -145,3 +150,3 @@ red.bold('text');

```js
import { red } from 'ansis/colors';
import { red } from 'ansis';

@@ -162,3 +167,3 @@ let message = 'error';

```js
import { red, bold, italic, hex } from 'ansis/colors';
import { red, bold, italic, hex } from 'ansis';

@@ -181,3 +186,3 @@ red.bold`text`;

```js
import { red, green } from 'ansis/colors';
import { red, green } from 'ansis';

@@ -190,3 +195,3 @@ red`red ${green`green`} red`;

```js
import { red, green, cyan, magenta, yellow, italic, underline } from 'ansis/colors';
import { red, green, cyan, magenta, yellow, italic, underline } from 'ansis';

@@ -213,3 +218,3 @@ red(`red ${italic(`red italic ${underline(`red italic underline`)}`)} red`);

```js
import { red, green, hex, visible, inverse } from 'ansis/colors';
import { red, green, hex, visible, inverse } from 'ansis';

@@ -337,3 +342,3 @@ // defined a truecolor as the constant

```js
import { bold, ansi256, fg, bgAnsi256, bg } from 'ansis/colors';
import { bold, ansi256, fg, bgAnsi256, bg } from 'ansis';

@@ -369,3 +374,3 @@ // foreground color

```js
import { bold, hex, rgb, bgHex, bgRgb } from 'ansis/colors';
import { bold, hex, rgb, bgHex, bgRgb } from 'ansis';

@@ -394,3 +399,3 @@ // foreground color

```js
import { red, bold } from 'ansis/colors';
import { red, bold } from 'ansis';

@@ -428,3 +433,3 @@ // each style has `open` and `close` properties

```js
import { bgGreen } from 'ansis/colors';
import { bgGreen } from 'ansis';

@@ -431,0 +436,0 @@ console.log(bgGreen`\nAnsis\nNew Line\nNext New Line\n`);

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