termark 1.1.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -54
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +106 -68
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
@@ -4,9 +4,10 @@ Termark is a basic library to format console output to the standard non-browser
|
|
4
4
|
|
5
5
|
## Features & Highlights
|
6
6
|
|
7
|
-
-
|
7
|
+
- Zero dependencies
|
8
8
|
- [ESM & CJS compatible](#esm--cjs-compatibility)
|
9
9
|
- [NO_COLOR](https://no-color.org/)-friendly
|
10
|
+
- [Default and named imports]
|
10
11
|
- [Basic ANSI styling](#basic-ansi-styling) (`dim`, `bold`, `italic`, …)
|
11
12
|
- [4-bit](#4-bit-colours) ($2^4 = 16$) colours (`red`, `cyan`, `blueBright`, …)
|
12
13
|
- [8-bit](#8-bit-colours) ($2^8 = 256$) colours (`ansi256()`)
|
@@ -15,6 +16,7 @@ Termark is a basic library to format console output to the standard non-browser
|
|
15
16
|
- Built-in [terminal logging methods](#built-in-terminal-logging-methods) (`success()`, `info()`, `warn()`, `error()`)
|
16
17
|
- [Template strings](#template-strings) & [nested styles](#nested-styles) (``` green`Success: File ${cyan`plans.txt`} created successfully!` ```)
|
17
18
|
- [Colour-detection utilities](#colour-detection-utilities) (`areColorsEnabled`, `is8bitEnabled`, `is24bitEnabled`)
|
19
|
+
- [Usage as an object or as a class](#class-v-object)
|
18
20
|
|
19
21
|
## Installation
|
20
22
|
|
@@ -28,13 +30,28 @@ Termark is compatible with both ECMAScript modules (`import`/`export` syntax), a
|
|
28
30
|
|
29
31
|
```js
|
30
32
|
// CJS:
|
31
|
-
const
|
33
|
+
const termark = require('termark');
|
32
34
|
|
33
35
|
// ESM:
|
34
|
-
import
|
36
|
+
import termark from 'termark';
|
37
|
+
```
|
38
|
+
|
39
|
+
## Default & named imports
|
40
|
+
|
41
|
+
Termark offers both a default import that has access to all properties and methods, or you can import each one individually:
|
42
|
+
|
43
|
+
```ts
|
44
|
+
// Default import:
|
45
|
+
import termark from 'termark';
|
35
46
|
|
36
|
-
|
37
|
-
|
47
|
+
termark.info('This is the default import, where all properties and methods are accessible.');
|
48
|
+
|
49
|
+
// Named imports:
|
50
|
+
import { success, inverse } from 'termark';
|
51
|
+
|
52
|
+
success(
|
53
|
+
inverse('This text with a green background is achieved with named imports!')
|
54
|
+
)
|
38
55
|
```
|
39
56
|
|
40
57
|
## Usage
|
@@ -42,9 +59,7 @@ const termark = new Termark();
|
|
42
59
|
Here's a quick reference for every feature Termark provides:
|
43
60
|
|
44
61
|
```ts
|
45
|
-
import
|
46
|
-
|
47
|
-
const termark = new Termark();
|
62
|
+
import termark from 'termark';
|
48
63
|
|
49
64
|
console.log(
|
50
65
|
termark.red('This is red text.'),
|
@@ -62,9 +77,7 @@ console.log(
|
|
62
77
|
### Basic ANSI styling
|
63
78
|
|
64
79
|
```ts
|
65
|
-
import
|
66
|
-
|
67
|
-
const termark = new Termark();
|
80
|
+
import termark from 'termark';
|
68
81
|
|
69
82
|
termark.reset('...');
|
70
83
|
termark.bold('...');
|
@@ -81,9 +94,7 @@ termark.strike('...');
|
|
81
94
|
### 4-bit colours
|
82
95
|
|
83
96
|
```ts
|
84
|
-
import
|
85
|
-
|
86
|
-
const termark = new Termark();
|
97
|
+
import termark from 'termark';
|
87
98
|
|
88
99
|
termark.black('...');
|
89
100
|
termark.red('...');
|
@@ -121,9 +132,7 @@ termark.bgWhiteBright('...');
|
|
121
132
|
### 8-bit colours
|
122
133
|
|
123
134
|
```ts
|
124
|
-
import
|
125
|
-
|
126
|
-
const termark = new Termark();
|
135
|
+
import termark from 'termark';
|
127
136
|
|
128
137
|
termark.ansi256('text', 33)('...');
|
129
138
|
termark.ansi256('background', 200)('...');
|
@@ -132,9 +141,7 @@ termark.ansi256('background', 200)('...');
|
|
132
141
|
### 24-bit colours
|
133
142
|
|
134
143
|
```ts
|
135
|
-
import
|
136
|
-
|
137
|
-
const termark = new Termark();
|
144
|
+
import termark from 'termark';
|
138
145
|
|
139
146
|
// You can specify your RGB values as an array:
|
140
147
|
termark.rgb('text', [182, 22, 234])('...');
|
@@ -153,40 +160,19 @@ termark.rgb('text', convert.hex.rgb('008330'))('...');
|
|
153
160
|
|
154
161
|
### Gradients
|
155
162
|
|
156
|
-
|
157
|
-
import Termark from 'termark';
|
163
|
+
**Please note that gradients do not support nested styling.**
|
158
164
|
|
159
|
-
|
165
|
+
```ts
|
166
|
+
import termark from 'termark';
|
160
167
|
|
161
168
|
termark.gradient('text', [[200, 123, 0], [0, 255, 255], [177, 209, 10]])('...');
|
162
169
|
termark.gradient('background', [[123, 75, 204], [255, 255, 255], [0, 44, 55]])('...');
|
163
170
|
```
|
164
171
|
|
165
|
-
The way this works is as follows:
|
166
|
-
|
167
|
-
We have two colours $C_1 = (R_1,G_1,B_1)$ and $C_2 = (R_2,G_2,B_2)$, and we need to generate a gradient over a string of length $L$.
|
168
|
-
For each character at index $i$ (from 0 to $L-1$), we need to find an interpolated colour $C_i$.
|
169
|
-
For that, we can do the following:
|
170
|
-
|
171
|
-
$$
|
172
|
-
\begin{align*}
|
173
|
-
t &= \frac{i}{L-1} \\\\
|
174
|
-
R_i &= R_1 + t \times (R_2 - R_1) \\
|
175
|
-
G_i &= G_1 + t \times (G_2 - G_1) \\
|
176
|
-
B_i &= B_1 + t \times (B_2 - B_1)
|
177
|
-
\end{align*}
|
178
|
-
$$
|
179
|
-
|
180
|
-
We then apply $C_i$ to each character $i$ to get our (mostly) smooth gradient.
|
181
|
-
|
182
|
-
**Please note that gradients do not support nested styling.**
|
183
|
-
|
184
172
|
### Built-in terminal logging methods
|
185
173
|
|
186
174
|
```ts
|
187
|
-
import
|
188
|
-
|
189
|
-
const termark = new Termark();
|
175
|
+
import termark from 'termark';
|
190
176
|
|
191
177
|
termark.success('...'); // Logs some message in green as an info message.
|
192
178
|
termark.info('...'); // Logs some message in blue as an info message.
|
@@ -203,9 +189,7 @@ termark.error('File not found', brandPrefix);
|
|
203
189
|
### Template strings
|
204
190
|
|
205
191
|
```ts
|
206
|
-
import
|
207
|
-
|
208
|
-
const termark = new Termark();
|
192
|
+
import termark from 'termark';
|
209
193
|
|
210
194
|
// Instead of using this:
|
211
195
|
termark.blue('...');
|
@@ -217,9 +201,7 @@ termark.blue`...`;
|
|
217
201
|
### Nested styles
|
218
202
|
|
219
203
|
```ts
|
220
|
-
import
|
221
|
-
|
222
|
-
const termark = new Termark();
|
204
|
+
import termark from 'termark';
|
223
205
|
|
224
206
|
termark.blue(
|
225
207
|
'This is some blue text ' +
|
@@ -231,15 +213,29 @@ termark.blue(
|
|
231
213
|
### Colour-detection utilities
|
232
214
|
|
233
215
|
```ts
|
234
|
-
import
|
235
|
-
|
236
|
-
const termark = new Termark();
|
216
|
+
import termark from 'termark';
|
237
217
|
|
238
218
|
termark.areColorsEnabled; // Check whether terminal colours are enabled.
|
239
219
|
termark.is8bitEnabled; // Check whether 8-bit (256) colours are enabled.
|
240
220
|
termark.is24bitEnabled; // Check whether 24-bit (truecolor) colours are enabled.
|
241
221
|
```
|
242
222
|
|
223
|
+
### Class v. Object
|
224
|
+
|
225
|
+
You can use Termark by importing the object, or you can import the class:
|
226
|
+
|
227
|
+
```ts
|
228
|
+
import { Termark } from 'termark';
|
229
|
+
|
230
|
+
const termark = new Termark(); // This is the same as importing the `termark` object.
|
231
|
+
termark.success('Termark is working!');
|
232
|
+
|
233
|
+
// Alternatively, you could do this:
|
234
|
+
Termark.init.success('This work, too!');
|
235
|
+
```
|
236
|
+
|
237
|
+
`Termark.init` enables using the `Termark` class as the default `termark` object.
|
238
|
+
|
243
239
|
## Licence
|
244
240
|
|
245
241
|
Termark's code is licenced under the [Apache licence version 2](https://www.apache.org/licenses/LICENSE-2.0).
|
package/dist/index.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";const r=()=>!process.env.NO_COLOR,t=()=>{const r=process.env.COLORTERM;return{is16bit:!!r&&(r.includes("ansi")&&!r.includes("256")),is256:!!r&&r.includes("ansi256"),isTrueColor:!!r&&(r.includes("truecolor")||r.includes("24bit"))}};function
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const r=()=>!process.env.NO_COLOR,t=()=>{const r=process.env.COLORTERM;return{is16bit:!!r&&(r.includes("ansi")&&!r.includes("256")),is256:!!r&&r.includes("ansi256"),isTrueColor:!!r&&(r.includes("truecolor")||r.includes("24bit"))}};function e(t,e,o){if("color"===o&&!r())return r=>r.toString();const i=`[${t}m`,s=`[${e}m`;return r=>{const t=r.toString().trim();return-1===t.indexOf(s)?`${i}${t}${s}`:`${i}${t.replaceAll(s,s+i)}${s}`}}function o(r,t,e){return[Math.round(r[0]+e*(t[0]-r[0])),Math.round(r[1]+e*(t[1]-r[1])),Math.round(r[2]+e*(t[2]-r[2]))]}class i{constructor(){this.areColorsEnabled=r(),this.is8bitEnabled=t().is256,this.is24bitEnabled=t().isTrueColor,this.reset=e(0,0,"format"),this.bold=e(1,22,"format"),this.dim=e(2,22,"format"),this.italic=e(3,23,"format"),this.underline=e(4,24,"format"),this.blink=e(5,25,"format"),this.inverse=e(7,27,"format"),this.overline=e(53,55,"format"),this.hidden=e(8,28,"format"),this.strike=e(9,29,"format"),this.black=e(30,39,"color"),this.red=e(31,39,"color"),this.green=e(32,39,"color"),this.yellow=e(33,39,"color"),this.blue=e(34,39,"color"),this.magenta=e(35,39,"color"),this.cyan=e(36,39,"color"),this.white=e(37,39,"color"),this.blackBright=e(90,39,"color"),this.redBright=e(91,39,"color"),this.greenBright=e(92,39,"color"),this.yellowBright=e(93,39,"color"),this.blueBright=e(94,39,"color"),this.magentaBright=e(95,39,"color"),this.cyanBright=e(96,39,"color"),this.whiteBright=e(97,39,"color"),this.bgBlack=e(40,49,"color"),this.bgRed=e(41,49,"color"),this.bgGreen=e(42,49,"color"),this.bgYellow=e(43,49,"color"),this.bgBlue=e(44,49,"color"),this.bgMagenta=e(45,49,"color"),this.bgCyan=e(46,49,"color"),this.bgWhite=e(47,49,"color"),this.bgBlackBright=e(100,49,"color"),this.bgRedBright=e(101,49,"color"),this.bgGreenBright=e(102,49,"color"),this.bgYellowBright=e(103,49,"color"),this.bgBlueBright=e(104,49,"color"),this.bgMagentaBright=e(105,49,"color"),this.bgCyanBright=e(106,49,"color"),this.bgWhiteBright=e(107,49,"color")}static get init(){return new this.termarkInstance}ansi256(o,s){if(s<0||s>255)throw new Error(i.init.red("Value `color` is out of range! The value must be a number between 0 and 255!"));if(!t().is256||!r())return r=>r.toString();return e("text"===o?`38;5;${s}`:`48;5;${s}`,"text"===o?39:49,"color")}rgb(r,...o){let s,n,l;if(Array.isArray(o[0])?(s=o[0][0],n=o[0][1],l=o[0][2]):(s=o[0],n=o[1],l=o[2]),"number"==typeof s&&(s<0||s>255)||"number"==typeof n&&(n<0||n>255)||"number"==typeof l&&(l<0||l>255))throw new Error(i.init.red("One or multiple of the colours specified is out of range! Each colour can have a value only between 0 and 255!"));if(!t().isTrueColor)return r=>r.toString();return e("text"===r?`38;2;${s};${n};${l}`:`48;2;${s};${n};${l}`,"text"===r?39:49,"color")}gradient(e,i){if(!r()||!t().isTrueColor)return r=>r.toString();const s="text"===e?"[38;2;":"[48;2;",n="text"===e?"[39m":"[49m";return r=>{const t=r.toString().trim(),e=i.length,l=Math.min(t.length/(e-1));let g="";for(let r=0;r<t.length;r++){const h=Math.min(Math.floor(r/l),e-2),a=r%l/l,c=o(i[h],i[h+1],a);g+=`${s}${c[0]};${c[1]};${c[2]}m${t[r]}${n}`}return g}}success(r,t=""){console.info(`${t}${i.init.green(r)}`)}info(r,t=""){console.info(`${t}${i.init.blue(r)}`)}warn(r,t=""){console.warn(`${t}${i.init.yellow(r)}`)}error(r,t=""){console.error(`${t}${i.init.red(r)}`)}custom(r,t,o){return e(r,t,"asColor"===o?"color":"format")}}i.termarkInstance=i;const s=new i,{areColorsEnabled:n,is8bitEnabled:l,is24bitEnabled:g,reset:h,bold:a,dim:c,italic:b,underline:u,blink:p,inverse:x,overline:B,hidden:d,strike:m,black:f,red:w,green:$,yellow:y,blue:k,magenta:C,cyan:M,white:E,blackBright:v,redBright:R,greenBright:O,yellowBright:T,blueBright:G,magentaBright:S,cyanBright:W,whiteBright:Y,bgBlack:A,bgRed:_,bgGreen:I,bgYellow:L,bgBlue:j,bgMagenta:N,bgCyan:P,bgWhite:V,bgBlackBright:q,bgRedBright:z,bgGreenBright:D,bgYellowBright:F,bgBlueBright:H,bgMagentaBright:J,bgCyanBright:K,bgWhiteBright:Q,ansi256:U,rgb:X,gradient:Z,success:rr,info:tr,warn:er,error:or,custom:ir}=s;exports.Termark=i,exports.ansi256=U,exports.areColorsEnabled=n,exports.bgBlack=A,exports.bgBlackBright=q,exports.bgBlue=j,exports.bgBlueBright=H,exports.bgCyan=P,exports.bgCyanBright=K,exports.bgGreen=I,exports.bgGreenBright=D,exports.bgMagenta=N,exports.bgMagentaBright=J,exports.bgRed=_,exports.bgRedBright=z,exports.bgWhite=V,exports.bgWhiteBright=Q,exports.bgYellow=L,exports.bgYellowBright=F,exports.black=f,exports.blackBright=v,exports.blink=p,exports.blue=k,exports.blueBright=G,exports.bold=a,exports.custom=ir,exports.cyan=M,exports.cyanBright=W,exports.default=s,exports.dim=c,exports.error=or,exports.gradient=Z,exports.green=$,exports.greenBright=O,exports.hidden=d,exports.info=tr,exports.inverse=x,exports.is24bitEnabled=g,exports.is8bitEnabled=l,exports.italic=b,exports.magenta=C,exports.magentaBright=S,exports.overline=B,exports.red=w,exports.redBright=R,exports.reset=h,exports.rgb=X,exports.strike=m,exports.success=rr,exports.underline=u,exports.warn=er,exports.white=E,exports.whiteBright=Y,exports.yellow=y,exports.yellowBright=T;
|
package/dist/index.d.ts
CHANGED
@@ -1,83 +1,48 @@
|
|
1
1
|
import { ANSIStyleType, RGB } from './util';
|
2
2
|
/**
|
3
|
-
* The `Termark` class
|
3
|
+
* The `Termark` class is almost the same as the {@linkcode termark} object and by using `Termark.init`, it effectively does become the same.
|
4
4
|
*
|
5
|
-
*
|
6
|
-
* - Methods (commands)
|
7
|
-
*
|
8
|
-
* For info regarding ANSI styling:
|
9
|
-
* @see https://en.wikipedia.org/wiki/ANSI_escape_code
|
10
|
-
*
|
11
|
-
* ---
|
12
|
-
*
|
13
|
-
* With properties, you're able to use features of Termark that don't execute
|
14
|
-
* any command per se, but simply to retrieve information; you don't perform
|
15
|
-
* any operation with these.
|
16
|
-
*
|
17
|
-
* @example
|
18
|
-
* ```typescript
|
19
|
-
* import Termark from 'termark';
|
20
|
-
*
|
21
|
-
* const termark = new Termark();
|
22
|
-
*
|
23
|
-
* // All properties provided by Termark:
|
24
|
-
*
|
25
|
-
* termark.areColorsEnabled; // Check whether colours are enabled
|
26
|
-
* termark.is8bitEnabled; // Check whether 8-bit (256) colours are enabled
|
27
|
-
* termark.is24bitEnabled; // Check whether 24-bit (truecolor) colours are enabled
|
28
|
-
* ```
|
29
|
-
*
|
30
|
-
* In addition, properties on the `Termark` class are static-ish, i.e., they only do one thing, and you have no input on it.
|
31
|
-
*
|
32
|
-
* ---
|
33
|
-
*
|
34
|
-
* With methods on the other hand, you *do* perform commands and operations.
|
35
|
-
* Methods are dynamic, meaning that you *do* specify how they work.
|
36
|
-
*
|
37
|
-
* @example
|
38
|
-
* ```typescript
|
39
|
-
* import Termark from 'termark';
|
40
|
-
*
|
41
|
-
* const termark = new Termark();
|
42
|
-
*
|
43
|
-
* termark.red('...'); // Returns "..." in red.
|
44
|
-
* termark.rgb('background', [255, 255, 255])('...'); // Returns "..." with a white background.
|
45
|
-
* ```
|
5
|
+
* However, it is nonetheless useful as it enables type-safety,
|
46
6
|
*
|
47
|
-
*
|
48
|
-
* with a string of your choosing. This is made possible by the fact that most of (see below) Termark's
|
49
|
-
* methods return a function where you specify your input.
|
7
|
+
* You use this class the same way as you would the {@linkcode termark} object.
|
50
8
|
*
|
51
9
|
* @example
|
52
10
|
* ```typescript
|
53
|
-
* import Termark from 'termark';
|
54
|
-
*
|
55
|
-
* const termark = new Termark();
|
56
|
-
*
|
57
|
-
* termark.ansi256('text', 33)('This is blue text');
|
58
|
-
* termark.ansi256('text', 33)`This is also blue text`;
|
59
|
-
* ```
|
60
|
-
*
|
61
|
-
* ### Exceptions
|
62
|
-
*
|
63
|
-
* There are some exceptions to the above, however; not *all* of Termark's methods return
|
64
|
-
* a function to specify your input. These ones are:
|
65
|
-
*
|
66
|
-
* ```typescript
|
67
|
-
* import Termark from 'termark';
|
11
|
+
* import { Termark } from 'termark';
|
68
12
|
*
|
69
|
-
* const termark = new Termark();
|
13
|
+
* const termark = new Termark(); // This is the same as if you'd import the `termark` object.
|
14
|
+
* termark.success('Termark is working!');
|
70
15
|
*
|
71
|
-
*
|
72
|
-
*
|
73
|
-
* termark.warn('...');
|
74
|
-
* termark.error('...');
|
16
|
+
* // Alternatively, you could do:
|
17
|
+
* Termark.init.success('This works, too!');
|
75
18
|
* ```
|
76
19
|
*
|
77
|
-
*
|
78
|
-
* return a function where you specify your input.
|
20
|
+
* @see The {@linkcode termark} object.
|
79
21
|
*/
|
80
|
-
export
|
22
|
+
export declare class Termark {
|
23
|
+
/**
|
24
|
+
* A reference to a Termark instance.
|
25
|
+
*
|
26
|
+
* This is an object that holds the properties defined below.
|
27
|
+
*/
|
28
|
+
private static termarkInstance;
|
29
|
+
/**
|
30
|
+
* A static getter function that returns a Termark reference object.
|
31
|
+
*
|
32
|
+
* With this method, it's possible to use the `Termark` class like an object.
|
33
|
+
*
|
34
|
+
* @example
|
35
|
+
* ```typescript
|
36
|
+
* import { Termark } from 'termark';
|
37
|
+
* Termark.init.success('...');
|
38
|
+
*
|
39
|
+
* // ...is the same as:
|
40
|
+
*
|
41
|
+
* import termark from 'termark';
|
42
|
+
* termark.success('...');
|
43
|
+
* ```
|
44
|
+
*/
|
45
|
+
static get init(): Termark;
|
81
46
|
/** Check whether terminal colours are enabled. */
|
82
47
|
areColorsEnabled: boolean;
|
83
48
|
/** Check whether 8-bit colours are enabled. */
|
@@ -298,3 +263,76 @@ export default class Termark {
|
|
298
263
|
*/
|
299
264
|
custom(opener: string | number, closer: string | number, type: 'asColor' | 'asFormat'): (input: string | TemplateStringsArray) => string;
|
300
265
|
}
|
266
|
+
/**
|
267
|
+
* The `termark` object enables accessing all features of Termark:
|
268
|
+
*
|
269
|
+
* - Properties (retrieve information)
|
270
|
+
* - Methods (commands)
|
271
|
+
*
|
272
|
+
* For info regarding ANSI styling:
|
273
|
+
* @see https://en.wikipedia.org/wiki/ANSI_escape_code
|
274
|
+
*
|
275
|
+
* ---
|
276
|
+
*
|
277
|
+
* With properties, you're able to use features of Termark that don't execute
|
278
|
+
* any command per se, but simply to retrieve information; you don't perform
|
279
|
+
* any operation with these.
|
280
|
+
*
|
281
|
+
* @example
|
282
|
+
* ```typescript
|
283
|
+
* import termark from 'termark';
|
284
|
+
*
|
285
|
+
* // All properties provided by Termark:
|
286
|
+
*
|
287
|
+
* termark.areColorsEnabled; // Check whether colours are enabled
|
288
|
+
* termark.is8bitEnabled; // Check whether 8-bit (256) colours are enabled
|
289
|
+
* termark.is24bitEnabled; // Check whether 24-bit (truecolor) colours are enabled
|
290
|
+
* ```
|
291
|
+
*
|
292
|
+
* In addition, properties on the `Termark` class are static-ish, i.e., they only do one thing, and you have no input on it.
|
293
|
+
*
|
294
|
+
* ---
|
295
|
+
*
|
296
|
+
* With methods on the other hand, you *do* perform commands and operations.
|
297
|
+
* Methods are dynamic, meaning that you *do* specify how they work.
|
298
|
+
*
|
299
|
+
* @example
|
300
|
+
* ```typescript
|
301
|
+
* import termark from 'termark';
|
302
|
+
*
|
303
|
+
* termark.red('...'); // Returns "..." in red.
|
304
|
+
* termark.rgb('background', [255, 255, 255])('...'); // Returns "..." with a white background.
|
305
|
+
* ```
|
306
|
+
*
|
307
|
+
* With all methods, you **must** append either `('...')` or ``` `...` ```, and replace "`...`"
|
308
|
+
* with a string of your choosing. This is made possible by the fact that most of (see below) Termark's
|
309
|
+
* methods return a function where you specify your input.
|
310
|
+
*
|
311
|
+
* @example
|
312
|
+
* ```typescript
|
313
|
+
* import termark from 'termark';
|
314
|
+
*
|
315
|
+
* termark.ansi256('text', 33)('This is blue text');
|
316
|
+
* termark.ansi256('text', 33)`This is also blue text`;
|
317
|
+
* ```
|
318
|
+
*
|
319
|
+
* ### Exceptions
|
320
|
+
*
|
321
|
+
* There are some exceptions to the above, however; not *all* of Termark's methods return
|
322
|
+
* a function to specify your input. These ones are:
|
323
|
+
*
|
324
|
+
* ```typescript
|
325
|
+
* import termark from 'termark';
|
326
|
+
*
|
327
|
+
* termark.success('...');
|
328
|
+
* termark.info('...');
|
329
|
+
* termark.warn('...');
|
330
|
+
* termark.error('...');
|
331
|
+
* ```
|
332
|
+
*
|
333
|
+
* This is because the above three methods handle console outputs for you. Therefore, they needn't
|
334
|
+
* return a function where you specify your input.
|
335
|
+
*/
|
336
|
+
declare const termark: Termark;
|
337
|
+
export default termark;
|
338
|
+
export declare const areColorsEnabled: boolean, is8bitEnabled: boolean, is24bitEnabled: boolean, reset: (input: string | TemplateStringsArray) => string, bold: (input: string | TemplateStringsArray) => string, dim: (input: string | TemplateStringsArray) => string, italic: (input: string | TemplateStringsArray) => string, underline: (input: string | TemplateStringsArray) => string, blink: (input: string | TemplateStringsArray) => string, inverse: (input: string | TemplateStringsArray) => string, overline: (input: string | TemplateStringsArray) => string, hidden: (input: string | TemplateStringsArray) => string, strike: (input: string | TemplateStringsArray) => string, black: (input: string | TemplateStringsArray) => string, red: (input: string | TemplateStringsArray) => string, green: (input: string | TemplateStringsArray) => string, yellow: (input: string | TemplateStringsArray) => string, blue: (input: string | TemplateStringsArray) => string, magenta: (input: string | TemplateStringsArray) => string, cyan: (input: string | TemplateStringsArray) => string, white: (input: string | TemplateStringsArray) => string, blackBright: (input: string | TemplateStringsArray) => string, redBright: (input: string | TemplateStringsArray) => string, greenBright: (input: string | TemplateStringsArray) => string, yellowBright: (input: string | TemplateStringsArray) => string, blueBright: (input: string | TemplateStringsArray) => string, magentaBright: (input: string | TemplateStringsArray) => string, cyanBright: (input: string | TemplateStringsArray) => string, whiteBright: (input: string | TemplateStringsArray) => string, bgBlack: (input: string | TemplateStringsArray) => string, bgRed: (input: string | TemplateStringsArray) => string, bgGreen: (input: string | TemplateStringsArray) => string, bgYellow: (input: string | TemplateStringsArray) => string, bgBlue: (input: string | TemplateStringsArray) => string, bgMagenta: (input: string | TemplateStringsArray) => string, bgCyan: (input: string | TemplateStringsArray) => string, bgWhite: (input: string | TemplateStringsArray) => string, bgBlackBright: (input: string | TemplateStringsArray) => string, bgRedBright: (input: string | TemplateStringsArray) => string, bgGreenBright: (input: string | TemplateStringsArray) => string, bgYellowBright: (input: string | TemplateStringsArray) => string, bgBlueBright: (input: string | TemplateStringsArray) => string, bgMagentaBright: (input: string | TemplateStringsArray) => string, bgCyanBright: (input: string | TemplateStringsArray) => string, bgWhiteBright: (input: string | TemplateStringsArray) => string, ansi256: (type: ANSIStyleType, color: number) => (input: string | TemplateStringsArray) => string, rgb: (type: ANSIStyleType, ...rgb: RGB | [RGB]) => (input: string | TemplateStringsArray) => string, gradient: (type: ANSIStyleType, colors: RGB[]) => (input: string | TemplateStringsArray) => string, success: (message: string, prefix?: string) => void, info: (message: string, prefix?: string) => void, warn: (message: string, prefix?: string) => void, error: (message: string, prefix?: string) => void, custom: (opener: string | number, closer: string | number, type: "asColor" | "asFormat") => (input: string | TemplateStringsArray) => string;
|
package/dist/index.mjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
const
|
1
|
+
const t=()=>!process.env.NO_COLOR,r=()=>{const t=process.env.COLORTERM;return{is16bit:!!t&&(t.includes("ansi")&&!t.includes("256")),is256:!!t&&t.includes("ansi256"),isTrueColor:!!t&&(t.includes("truecolor")||t.includes("24bit"))}};function e(r,e,i){if("color"===i&&!t())return t=>t.toString();const o=`[${r}m`,n=`[${e}m`;return t=>{const r=t.toString().trim();return-1===r.indexOf(n)?`${o}${r}${n}`:`${o}${r.replaceAll(n,n+o)}${n}`}}function i(t,r,e){return[Math.round(t[0]+e*(r[0]-t[0])),Math.round(t[1]+e*(r[1]-t[1])),Math.round(t[2]+e*(r[2]-t[2]))]}class o{constructor(){this.areColorsEnabled=t(),this.is8bitEnabled=r().is256,this.is24bitEnabled=r().isTrueColor,this.reset=e(0,0,"format"),this.bold=e(1,22,"format"),this.dim=e(2,22,"format"),this.italic=e(3,23,"format"),this.underline=e(4,24,"format"),this.blink=e(5,25,"format"),this.inverse=e(7,27,"format"),this.overline=e(53,55,"format"),this.hidden=e(8,28,"format"),this.strike=e(9,29,"format"),this.black=e(30,39,"color"),this.red=e(31,39,"color"),this.green=e(32,39,"color"),this.yellow=e(33,39,"color"),this.blue=e(34,39,"color"),this.magenta=e(35,39,"color"),this.cyan=e(36,39,"color"),this.white=e(37,39,"color"),this.blackBright=e(90,39,"color"),this.redBright=e(91,39,"color"),this.greenBright=e(92,39,"color"),this.yellowBright=e(93,39,"color"),this.blueBright=e(94,39,"color"),this.magentaBright=e(95,39,"color"),this.cyanBright=e(96,39,"color"),this.whiteBright=e(97,39,"color"),this.bgBlack=e(40,49,"color"),this.bgRed=e(41,49,"color"),this.bgGreen=e(42,49,"color"),this.bgYellow=e(43,49,"color"),this.bgBlue=e(44,49,"color"),this.bgMagenta=e(45,49,"color"),this.bgCyan=e(46,49,"color"),this.bgWhite=e(47,49,"color"),this.bgBlackBright=e(100,49,"color"),this.bgRedBright=e(101,49,"color"),this.bgGreenBright=e(102,49,"color"),this.bgYellowBright=e(103,49,"color"),this.bgBlueBright=e(104,49,"color"),this.bgMagentaBright=e(105,49,"color"),this.bgCyanBright=e(106,49,"color"),this.bgWhiteBright=e(107,49,"color")}static get init(){return new this.termarkInstance}ansi256(i,n){if(n<0||n>255)throw new Error(o.init.red("Value `color` is out of range! The value must be a number between 0 and 255!"));if(!r().is256||!t())return t=>t.toString();return e("text"===i?`38;5;${n}`:`48;5;${n}`,"text"===i?39:49,"color")}rgb(t,...i){let n,l,s;if(Array.isArray(i[0])?(n=i[0][0],l=i[0][1],s=i[0][2]):(n=i[0],l=i[1],s=i[2]),"number"==typeof n&&(n<0||n>255)||"number"==typeof l&&(l<0||l>255)||"number"==typeof s&&(s<0||s>255))throw new Error(o.init.red("One or multiple of the colours specified is out of range! Each colour can have a value only between 0 and 255!"));if(!r().isTrueColor)return t=>t.toString();return e("text"===t?`38;2;${n};${l};${s}`:`48;2;${n};${l};${s}`,"text"===t?39:49,"color")}gradient(e,o){if(!t()||!r().isTrueColor)return t=>t.toString();const n="text"===e?"[38;2;":"[48;2;",l="text"===e?"[39m":"[49m";return t=>{const r=t.toString().trim(),e=o.length,s=Math.min(r.length/(e-1));let h="";for(let t=0;t<r.length;t++){const g=Math.min(Math.floor(t/s),e-2),a=t%s/s,c=i(o[g],o[g+1],a);h+=`${n}${c[0]};${c[1]};${c[2]}m${r[t]}${l}`}return h}}success(t,r=""){console.info(`${r}${o.init.green(t)}`)}info(t,r=""){console.info(`${r}${o.init.blue(t)}`)}warn(t,r=""){console.warn(`${r}${o.init.yellow(t)}`)}error(t,r=""){console.error(`${r}${o.init.red(t)}`)}custom(t,r,i){return e(t,r,"asColor"===i?"color":"format")}}o.termarkInstance=o;const n=new o,{areColorsEnabled:l,is8bitEnabled:s,is24bitEnabled:h,reset:g,bold:a,dim:c,italic:b,underline:u,blink:d,inverse:B,overline:m,hidden:f,strike:$,black:w,red:y,green:k,yellow:C,blue:M,magenta:E,cyan:p,white:v,blackBright:x,redBright:O,greenBright:R,yellowBright:S,blueBright:T,magentaBright:G,cyanBright:W,whiteBright:Y,bgBlack:A,bgRed:I,bgGreen:L,bgYellow:N,bgBlue:V,bgMagenta:_,bgCyan:j,bgWhite:q,bgBlackBright:z,bgRedBright:D,bgGreenBright:F,bgYellowBright:H,bgBlueBright:J,bgMagentaBright:K,bgCyanBright:P,bgWhiteBright:Q,ansi256:U,rgb:X,gradient:Z,success:tt,info:rt,warn:et,error:it,custom:ot}=n;export{o as Termark,U as ansi256,l as areColorsEnabled,A as bgBlack,z as bgBlackBright,V as bgBlue,J as bgBlueBright,j as bgCyan,P as bgCyanBright,L as bgGreen,F as bgGreenBright,_ as bgMagenta,K as bgMagentaBright,I as bgRed,D as bgRedBright,q as bgWhite,Q as bgWhiteBright,N as bgYellow,H as bgYellowBright,w as black,x as blackBright,d as blink,M as blue,T as blueBright,a as bold,ot as custom,p as cyan,W as cyanBright,n as default,c as dim,it as error,Z as gradient,k as green,R as greenBright,f as hidden,rt as info,B as inverse,h as is24bitEnabled,s as is8bitEnabled,b as italic,E as magenta,G as magentaBright,m as overline,y as red,O as redBright,g as reset,X as rgb,$ as strike,tt as success,u as underline,et as warn,v as white,Y as whiteBright,C as yellow,S as yellowBright};
|