termark 1.0.0 → 1.1.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 CHANGED
@@ -28,10 +28,13 @@ Termark is compatible with both ECMAScript modules (`import`/`export` syntax), a
28
28
 
29
29
  ```js
30
30
  // CJS:
31
- const termark = require('termark');
31
+ const Termark = require('termark');
32
32
 
33
33
  // ESM:
34
- import termark from 'termark';
34
+ import Termark from 'termark';
35
+
36
+ // for both, you'd then likely do this for convenience:
37
+ const termark = new Termark();
35
38
  ```
36
39
 
37
40
  ## Usage
@@ -39,7 +42,9 @@ import termark from 'termark';
39
42
  Here's a quick reference for every feature Termark provides:
40
43
 
41
44
  ```ts
42
- import termark from 'termark';
45
+ import Termark from 'termark';
46
+
47
+ const termark = new Termark();
43
48
 
44
49
  console.log(
45
50
  termark.red('This is red text.'),
@@ -57,7 +62,9 @@ console.log(
57
62
  ### Basic ANSI styling
58
63
 
59
64
  ```ts
60
- import termark from 'termark';
65
+ import Termark from 'termark';
66
+
67
+ const termark = new Termark();
61
68
 
62
69
  termark.reset('...');
63
70
  termark.bold('...');
@@ -74,7 +81,9 @@ termark.strike('...');
74
81
  ### 4-bit colours
75
82
 
76
83
  ```ts
77
- import termark from 'termark';
84
+ import Termark from 'termark';
85
+
86
+ const termark = new Termark();
78
87
 
79
88
  termark.black('...');
80
89
  termark.red('...');
@@ -112,7 +121,9 @@ termark.bgWhiteBright('...');
112
121
  ### 8-bit colours
113
122
 
114
123
  ```ts
115
- import termark from 'termark';
124
+ import Termark from 'termark';
125
+
126
+ const termark = new Termark();
116
127
 
117
128
  termark.ansi256('text', 33)('...');
118
129
  termark.ansi256('background', 200)('...');
@@ -121,7 +132,9 @@ termark.ansi256('background', 200)('...');
121
132
  ### 24-bit colours
122
133
 
123
134
  ```ts
124
- import termark from 'termark';
135
+ import Termark from 'termark';
136
+
137
+ const termark = new Termark();
125
138
 
126
139
  // You can specify your RGB values as an array:
127
140
  termark.rgb('text', [182, 22, 234])('...');
@@ -141,7 +154,9 @@ termark.rgb('text', convert.hex.rgb('008330'))('...');
141
154
  ### Gradients
142
155
 
143
156
  ```ts
144
- import termark from 'termark';
157
+ import Termark from 'termark';
158
+
159
+ const termark = new Termark();
145
160
 
146
161
  termark.gradient('text', [[200, 123, 0], [0, 255, 255], [177, 209, 10]])('...');
147
162
  termark.gradient('background', [[123, 75, 204], [255, 255, 255], [0, 44, 55]])('...');
@@ -169,7 +184,9 @@ We then apply $C_i$ to each character $i$ to get our (mostly) smooth gradient.
169
184
  ### Built-in terminal logging methods
170
185
 
171
186
  ```ts
172
- import termark from 'termark';
187
+ import Termark from 'termark';
188
+
189
+ const termark = new Termark();
173
190
 
174
191
  termark.success('...'); // Logs some message in green as an info message.
175
192
  termark.info('...'); // Logs some message in blue as an info message.
@@ -186,7 +203,9 @@ termark.error('File not found', brandPrefix);
186
203
  ### Template strings
187
204
 
188
205
  ```ts
189
- import termark from 'termark';
206
+ import Termark from 'termark';
207
+
208
+ const termark = new Termark();
190
209
 
191
210
  // Instead of using this:
192
211
  termark.blue('...');
@@ -198,7 +217,9 @@ termark.blue`...`;
198
217
  ### Nested styles
199
218
 
200
219
  ```ts
201
- import termark from 'termark';
220
+ import Termark from 'termark';
221
+
222
+ const termark = new Termark();
202
223
 
203
224
  termark.blue(
204
225
  'This is some blue text ' +
@@ -210,7 +231,9 @@ termark.blue(
210
231
  ### Colour-detection utilities
211
232
 
212
233
  ```ts
213
- import termark from 'termark';
234
+ import Termark from 'termark';
235
+
236
+ const termark = new Termark();
214
237
 
215
238
  termark.areColorsEnabled; // Check whether terminal colours are enabled.
216
239
  termark.is8bitEnabled; // Check whether 8-bit (256) colours are enabled.
package/dist/index.cjs CHANGED
@@ -1,181 +1 @@
1
- /*
2
- Copyright 2025 Q
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */
16
-
17
- 'use strict';
18
-
19
- const areColoursEnabled = () => {
20
- const noColour = process.env.NO_COLOR;
21
- return noColour ? false : true;
22
- };
23
- const getColourSupport = () => {
24
- const colourTerm = process.env.COLORTERM;
25
- const is16bit = colourTerm ? (colourTerm.includes('ansi') && !(colourTerm.includes('256'))) : false;
26
- const is256 = colourTerm ? colourTerm.includes('ansi256') : false;
27
- const isTrueColor = colourTerm ? (colourTerm.includes('truecolor') || colourTerm.includes('24bit')) : false;
28
- return {
29
- is16bit,
30
- is256,
31
- isTrueColor
32
- };
33
- };
34
- function format(open, close, type) {
35
- if (type === 'color' && !areColoursEnabled())
36
- return (input) => input.toString();
37
- const opener = `\x1b[${open}m`;
38
- const closer = `\x1b[${close}m`;
39
- return (input$1) => {
40
- const input = input$1.toString().trim();
41
- const index = input.indexOf(closer);
42
- if (index === -1)
43
- return `${opener}${input}${closer}`;
44
- return `${opener}${input.replaceAll(closer, closer + opener)}${closer}`;
45
- };
46
- }
47
- function interpolate(color1, color2, factor) {
48
- return [
49
- Math.round(color1[0] + factor * (color2[0] - color1[0])),
50
- Math.round(color1[1] + factor * (color2[1] - color1[1])),
51
- Math.round(color1[2] + factor * (color2[2] - color1[2])),
52
- ];
53
- }
54
-
55
- const termark = {
56
- areColorsEnabled: areColoursEnabled(),
57
- is8bitEnabled: getColourSupport().is256,
58
- is24bitEnabled: getColourSupport().isTrueColor,
59
- reset: format(0, 0, 'format'),
60
- bold: format(1, 22, 'format'),
61
- dim: format(2, 22, 'format'),
62
- italic: format(3, 23, 'format'),
63
- underline: format(4, 24, 'format'),
64
- blink: format(5, 25, 'format'),
65
- inverse: format(7, 27, 'format'),
66
- overline: format(53, 55, 'format'),
67
- hidden: format(8, 28, 'format'),
68
- strike: format(9, 29, 'format'),
69
- black: format(30, 39, 'color'),
70
- red: format(31, 39, 'color'),
71
- green: format(32, 39, 'color'),
72
- yellow: format(33, 39, 'color'),
73
- blue: format(34, 39, 'color'),
74
- magenta: format(35, 39, 'color'),
75
- cyan: format(36, 39, 'color'),
76
- white: format(37, 39, 'color'),
77
- blackBright: format(90, 39, 'color'),
78
- redBright: format(91, 39, 'color'),
79
- greenBright: format(92, 39, 'color'),
80
- yellowBright: format(93, 39, 'color'),
81
- blueBright: format(94, 39, 'color'),
82
- magentaBright: format(95, 39, 'color'),
83
- cyanBright: format(96, 39, 'color'),
84
- whiteBright: format(97, 39, 'color'),
85
- bgBlack: format(40, 49, 'color'),
86
- bgRed: format(41, 49, 'color'),
87
- bgGreen: format(42, 49, 'color'),
88
- bgYellow: format(43, 49, 'color'),
89
- bgBlue: format(44, 49, 'color'),
90
- bgMagenta: format(45, 49, 'color'),
91
- bgCyan: format(46, 49, 'color'),
92
- bgWhite: format(47, 49, 'color'),
93
- bgBlackBright: format(100, 49, 'color'),
94
- bgRedBright: format(101, 49, 'color'),
95
- bgGreenBright: format(102, 49, 'color'),
96
- bgYellowBright: format(103, 49, 'color'),
97
- bgBlueBright: format(104, 49, 'color'),
98
- bgMagentaBright: format(105, 49, 'color'),
99
- bgCyanBright: format(106, 49, 'color'),
100
- bgWhiteBright: format(107, 49, 'color'),
101
- ansi256(type, color) {
102
- if (color < 0 || color > 255)
103
- throw new Error(termark.red('Value `color` is out of range! The value must be a number between 0 and 255!'));
104
- if (!getColourSupport().is256 || !areColoursEnabled())
105
- return (input) => input.toString();
106
- const textFormat = `38;5;${color}`;
107
- const bgFormat = `48;5;${color}`;
108
- const opener = type === 'text' ? textFormat : bgFormat;
109
- const closer = type === 'text' ? 39 : 49;
110
- return format(opener, closer, 'color');
111
- },
112
- rgb(type, ...rgb) {
113
- let red;
114
- let green;
115
- let blue;
116
- if (Array.isArray(rgb[0])) {
117
- red = rgb[0][0];
118
- green = rgb[0][1];
119
- blue = rgb[0][2];
120
- }
121
- else {
122
- red = rgb[0];
123
- green = rgb[1];
124
- blue = rgb[2];
125
- }
126
- if (((typeof red === 'number') && (red < 0 || red > 255)) ||
127
- ((typeof green === 'number') && (green < 0 || green > 255)) ||
128
- ((typeof blue === 'number') && (blue < 0 || blue > 255)))
129
- throw new Error(termark.red('One or multiple of the colours specified is out of range! Each colour can have a value only between 0 and 255!'));
130
- if (!getColourSupport().isTrueColor)
131
- return (input) => input.toString();
132
- const textFormat = `38;2;${red};${green};${blue}`;
133
- const bgFormat = `48;2;${red};${green};${blue}`;
134
- const opener = type === 'text' ? textFormat : bgFormat;
135
- const closer = type === 'text' ? 39 : 49;
136
- return format(opener, closer, 'color');
137
- },
138
- gradient(type, colors) {
139
- if (!areColoursEnabled() || !getColourSupport().isTrueColor)
140
- return (input) => input.toString();
141
- const textFormat = `38;2;`;
142
- const bgFormat = `48;2;`;
143
- const opener = type === 'text' ? `\x1b[${textFormat}` : `\x1b[${bgFormat}`;
144
- const closer = type === 'text' ? `\x1b[${39}m` : `\x1b[${49}m`;
145
- return (input$1) => {
146
- const input = input$1.toString().trim();
147
- const colourCount = colors.length;
148
- const step = Math.min(input.length / (colourCount - 1));
149
- let result = '';
150
- for (let character = 0; character < input.length; character++) {
151
- const colourIndex = Math.min(Math.floor(character / step), colourCount - 2);
152
- const factor = (character % step) / step;
153
- const startColour = colors[colourIndex];
154
- const endColour = colors[colourIndex + 1];
155
- const interpolatedColour = interpolate(startColour, endColour, factor);
156
- result += `${opener}${interpolatedColour[0]};${interpolatedColour[1]};${interpolatedColour[2]}m${input[character]}${closer}`;
157
- }
158
- return result;
159
- };
160
- },
161
- success(message, prefix = '') {
162
- console.info(`${prefix}${termark.green(message)}`);
163
- },
164
- info(message, prefix = '') {
165
- console.info(`${prefix}${termark.blue(message)}`);
166
- },
167
- warn(message, prefix = '') {
168
- console.warn(`${prefix}${termark.yellow(message)}`);
169
- },
170
- error(message, prefix = '') {
171
- console.error(`${prefix}${termark.red(message)}`);
172
- },
173
- custom(opener, closer, type) {
174
- const formatType = type === 'asColor' ? 'color' : 'format';
175
- return format(opener, closer, formatType);
176
- },
177
- };
178
-
179
- module.exports = termark;
180
-
181
- // Copyright (C) 2025 Q
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 o(t,o,e){if("color"===e&&!r())return r=>r.toString();const i=`[${t}m`,n=`[${o}m`;return r=>{const t=r.toString().trim();return-1===t.indexOf(n)?`${i}${t}${n}`:`${i}${t.replaceAll(n,n+i)}${n}`}}function e(r,t,o){return[Math.round(r[0]+o*(t[0]-r[0])),Math.round(r[1]+o*(t[1]-r[1])),Math.round(r[2]+o*(t[2]-r[2]))]}class i{constructor(){this.areColorsEnabled=r(),this.is8bitEnabled=t().is256,this.is24bitEnabled=t().isTrueColor,this.reset=o(0,0,"format"),this.bold=o(1,22,"format"),this.dim=o(2,22,"format"),this.italic=o(3,23,"format"),this.underline=o(4,24,"format"),this.blink=o(5,25,"format"),this.inverse=o(7,27,"format"),this.overline=o(53,55,"format"),this.hidden=o(8,28,"format"),this.strike=o(9,29,"format"),this.black=o(30,39,"color"),this.red=o(31,39,"color"),this.green=o(32,39,"color"),this.yellow=o(33,39,"color"),this.blue=o(34,39,"color"),this.magenta=o(35,39,"color"),this.cyan=o(36,39,"color"),this.white=o(37,39,"color"),this.blackBright=o(90,39,"color"),this.redBright=o(91,39,"color"),this.greenBright=o(92,39,"color"),this.yellowBright=o(93,39,"color"),this.blueBright=o(94,39,"color"),this.magentaBright=o(95,39,"color"),this.cyanBright=o(96,39,"color"),this.whiteBright=o(97,39,"color"),this.bgBlack=o(40,49,"color"),this.bgRed=o(41,49,"color"),this.bgGreen=o(42,49,"color"),this.bgYellow=o(43,49,"color"),this.bgBlue=o(44,49,"color"),this.bgMagenta=o(45,49,"color"),this.bgCyan=o(46,49,"color"),this.bgWhite=o(47,49,"color"),this.bgBlackBright=o(100,49,"color"),this.bgRedBright=o(101,49,"color"),this.bgGreenBright=o(102,49,"color"),this.bgYellowBright=o(103,49,"color"),this.bgBlueBright=o(104,49,"color"),this.bgMagentaBright=o(105,49,"color"),this.bgCyanBright=o(106,49,"color"),this.bgWhiteBright=o(107,49,"color")}ansi256(e,n){if(n<0||n>255)throw new Error((new i).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 o("text"===e?`38;5;${n}`:`48;5;${n}`,"text"===e?39:49,"color")}rgb(r,...e){let n,l,s;if(Array.isArray(e[0])?(n=e[0][0],l=e[0][1],s=e[0][2]):(n=e[0],l=e[1],s=e[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((new i).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 o("text"===r?`38;2;${n};${l};${s}`:`48;2;${n};${l};${s}`,"text"===r?39:49,"color")}gradient(o,i){if(!r()||!t().isTrueColor)return r=>r.toString();const n="text"===o?"[38;2;":"[48;2;",l="text"===o?"":"";return r=>{const t=r.toString().trim(),o=i.length,s=Math.min(t.length/(o-1));let h="";for(let r=0;r<t.length;r++){const c=Math.min(Math.floor(r/s),o-2),a=r%s/s,g=e(i[c],i[c+1],a);h+=`${n}${g[0]};${g[1]};${g[2]}m${t[r]}${l}`}return h}}success(r,t=""){console.info(`${t}${(new i).green(r)}`)}info(r,t=""){console.info(`${t}${(new i).blue(r)}`)}warn(r,t=""){console.warn(`${t}${(new i).yellow(r)}`)}error(r,t=""){console.error(`${t}${(new i).red(r)}`)}custom(r,t,e){return o(r,t,"asColor"===e?"color":"format")}}module.exports=i;
package/dist/index.d.ts CHANGED
@@ -1,318 +1,172 @@
1
+ import { ANSIStyleType, RGB } from './util';
1
2
  /**
2
- * All properties and methods provided by Termark.
3
+ * The `Termark` class enables accessing all features of Termark:
4
+ *
5
+ * - Properties (retrieve information)
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
+ * ```
46
+ *
47
+ * With all methods, you **must** append either `('...')` or ``` `...` ```, and replace "`...`"
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.
50
+ *
51
+ * @example
52
+ * ```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';
68
+ *
69
+ * const termark = new Termark();
70
+ *
71
+ * termark.success('...');
72
+ * termark.info('...');
73
+ * termark.warn('...');
74
+ * termark.error('...');
75
+ * ```
76
+ *
77
+ * This is because the above three methods handle console outputs for you. Therefore, they needn't
78
+ * return a function where you specify your input.
3
79
  */
4
- interface Termark {
5
- /**
6
- * Check whether terminal colours are enabled.
7
- *
8
- * @returns true If terminal colours are enabled.
9
- */
80
+ export default class Termark {
81
+ /** Check whether terminal colours are enabled. */
10
82
  areColorsEnabled: boolean;
11
- /**
12
- * Check whether 8-bit colours are enabled.
13
- *
14
- * @returns true If 8-bit colours are enabled.
15
- */
83
+ /** Check whether 8-bit colours are enabled. */
16
84
  is8bitEnabled: boolean;
17
- /**
18
- * Check whether 24-bit colours (truecolor) are enabled.
19
- *
20
- * @returns true If 24-bit colours are enabled.
21
- */
85
+ /** Check whether 24-bit colours are enabled. */
22
86
  is24bitEnabled: boolean;
23
- /**
24
- * Reset all formatting of some text.
25
- *
26
- * @param input The text to format.
27
- * @returns The formatted text.
28
- */
87
+ /** Reset all styles. */
29
88
  reset: (input: string | TemplateStringsArray) => string;
30
- /**
31
- * Make some text bold.
32
- *
33
- * @param input The text to format.
34
- * @returns The text in bold letters.
35
- */
89
+ /** Make some text bold. */
36
90
  bold: (input: string | TemplateStringsArray) => string;
37
- /**
38
- * Make some text thinner.
39
- *
40
- * @param input The text to format.
41
- * @returns The text in thinner letters.
42
- */
91
+ /** Make some text thin. */
43
92
  dim: (input: string | TemplateStringsArray) => string;
44
- /**
45
- * Make some text italic. May not be widely supported.
46
- *
47
- * @param input The text to format.
48
- * @returns The text with italicized (usually slanted) letters.
49
- */
93
+ /** Make some text italic. May not be widely supported. */
50
94
  italic: (input: string | TemplateStringsArray) => string;
51
- /**
52
- * Underline some text.
53
- *
54
- * @param input The text to format.
55
- * @returns The underlined text.
56
- */
95
+ /** Underline some text. */
57
96
  underline: (input: string | TemplateStringsArray) => string;
58
- /**
59
- * Make some text blink slowly.
60
- *
61
- * @param input The text to format.
62
- * @returns The blinking text.
63
- */
97
+ /** Make some text blink slowly. */
64
98
  blink: (input: string | TemplateStringsArray) => string;
65
- /**
66
- * Invert some text (foreground colour becomes background colour, background colour becomes foreground colour).
67
- *
68
- * @param input The text to format.
69
- * @returns The inverted text.
70
- */
99
+ /** Invert some text (foreground colour becomes background colour, background colour becomes foreground colour). */
71
100
  inverse: (input: string | TemplateStringsArray) => string;
72
- /**
73
- * Add a line above some text (may not be widely supported).
74
- *
75
- * @param input The text to format.
76
- * @returns The text with a line above it.
77
- */
101
+ /** Add a line above some text. May not be widely supported. */
78
102
  overline: (input: string | TemplateStringsArray) => string;
79
- /**
80
- * Hide some text (may not be widely supported).
81
- *
82
- * @param input The text to format.
83
- * @returns The hidden text.
84
- */
103
+ /** Visually hide some text. */
85
104
  hidden: (input: string | TemplateStringsArray) => string;
86
- /**
87
- * Add a line through (strike) some text.
88
- *
89
- * @param input The text to format.
90
- * @returns The striked text.
91
- */
105
+ /** Add a line through (strike) some text. */
92
106
  strike: (input: string | TemplateStringsArray) => string;
93
- /**
94
- * Make some text black.
95
- *
96
- * @param input The text to colour.
97
- * @returns If colours are enabled, `input` coloured black.
98
- */
107
+ /** Colour some text black. */
99
108
  black: (input: string | TemplateStringsArray) => string;
100
- /**
101
- * Make some text red.
102
- *
103
- * @param input The text to colour.
104
- * @returns If colours are enabled, `input` coloured red.
105
- */
109
+ /** Colour some text red. */
106
110
  red: (input: string | TemplateStringsArray) => string;
107
- /**
108
- * Make some text green.
109
- *
110
- * @param input The text to colour.
111
- * @returns If colours are enabled, `input` coloured green.
112
- */
111
+ /** Colour some text green. */
113
112
  green: (input: string | TemplateStringsArray) => string;
114
- /**
115
- * Make some text yellow.
116
- *
117
- * @param input The text to colour.
118
- * @returns If colours are enabled, `input` coloured yellow.
119
- */
113
+ /** Colour some text yellow. */
120
114
  yellow: (input: string | TemplateStringsArray) => string;
121
- /**
122
- * Make some text blue.
123
- *
124
- * @param input The text to colour.
125
- * @returns If colours are enabled, `input` coloured blue.
126
- */
115
+ /** Colour some text blue. */
127
116
  blue: (input: string | TemplateStringsArray) => string;
128
- /**
129
- * Make some text magenta.
130
- *
131
- * @param input The text to colour.
132
- * @returns If colours are enabled, `input` coloured magenta.
133
- */
117
+ /** Colour some text magenta. */
134
118
  magenta: (input: string | TemplateStringsArray) => string;
135
- /**
136
- * Make some text cyan.
137
- *
138
- * @param input The text to colour.
139
- * @returns If colours are enabled, `input` coloured cyan.
140
- */
119
+ /** Colour some text cyan. */
141
120
  cyan: (input: string | TemplateStringsArray) => string;
142
- /**
143
- * Make some text white.
144
- *
145
- * @param input The text to colour.
146
- * @returns If colours are enabled, `input` coloured white.
147
- */
121
+ /** Colour some text white. */
148
122
  white: (input: string | TemplateStringsArray) => string;
149
- /**
150
- * Make some text bright black (grey).
151
- *
152
- * @param input The text to colour.
153
- * @returns If colours are enabled, `input` coloured bright black (grey).
154
- */
123
+ /** Colour some text bright black (grey). */
155
124
  blackBright: (input: string | TemplateStringsArray) => string;
156
- /**
157
- * Make some text bright red.
158
- *
159
- * @param input The text to colour.
160
- * @returns If colours are enabled, `input` coloured bright red.
161
- */
125
+ /** Colour some text bright red. */
162
126
  redBright: (input: string | TemplateStringsArray) => string;
163
- /**
164
- * Make some text bright green.
165
- *
166
- * @param input The text to colour.
167
- * @returns If colours are enabled, `input` coloured bright green.
168
- */
127
+ /** Colour some text bright green. */
169
128
  greenBright: (input: string | TemplateStringsArray) => string;
170
- /**
171
- * Make some text bright yellow.
172
- *
173
- * @param input The text to colour.
174
- * @returns If colours are enabled, `input` coloured bright yellow.
175
- */
129
+ /** Colour some text bright yellow. */
176
130
  yellowBright: (input: string | TemplateStringsArray) => string;
177
- /**
178
- * Make some text bright blue.
179
- *
180
- * @param input The text to colour.
181
- * @returns If colours are enabled, `input` coloured bright blue.
182
- */
131
+ /** Colour some text bright blue. */
183
132
  blueBright: (input: string | TemplateStringsArray) => string;
184
- /**
185
- * Make some text bright magenta.
186
- *
187
- * @param input The text to colour.
188
- * @returns If colours are enabled, `input` coloured bright magenta.
189
- */
133
+ /** Colour some text bright magenta. */
190
134
  magentaBright: (input: string | TemplateStringsArray) => string;
191
- /**
192
- * Make some text bright cyran.
193
- *
194
- * @param input The text to colour.
195
- * @returns If colours are enabled, `input` coloured bright cyan.
196
- */
135
+ /** Colour some text bright cyan. */
197
136
  cyanBright: (input: string | TemplateStringsArray) => string;
198
- /**
199
- * Make some text bright white.
200
- *
201
- * @param input The text to colour.
202
- * @returns If colours are enabled, `input` coloured bright white.
203
- */
137
+ /** Colour some text bright white. */
204
138
  whiteBright: (input: string | TemplateStringsArray) => string;
205
- /**
206
- * Make the background of some text black.
207
- *
208
- * @param input The text whose background to colour.
209
- * @returns If colours are enabled, `input` with a black background.
210
- */
139
+ /** Colour the background of some text black. */
211
140
  bgBlack: (input: string | TemplateStringsArray) => string;
212
- /**
213
- * Make the background of some text red.
214
- *
215
- * @param input The text whose background to colour.
216
- * @returns If colours are enabled, `input` with a red background.
217
- */
141
+ /** Colour the background of some text red. */
218
142
  bgRed: (input: string | TemplateStringsArray) => string;
219
- /**
220
- * Make the background of some text green.
221
- *
222
- * @param input The text whose background to colour.
223
- * @returns If colours are enabled, `input` with a green background.
224
- */
143
+ /** Colour the background of some text green. */
225
144
  bgGreen: (input: string | TemplateStringsArray) => string;
226
- /**
227
- * Make the background of some text yellow.
228
- *
229
- * @param input The text whose background to colour.
230
- * @returns If colours are enabled, `input` with a yellow background.
231
- */
145
+ /** Colour the background of some text yellow. */
232
146
  bgYellow: (input: string | TemplateStringsArray) => string;
233
- /**
234
- * Make the background of some text blue.
235
- *
236
- * @param input The text whose background to colour.
237
- * @returns If colours are enabled, `input` with a blue background.
238
- */
147
+ /** Colour the background of some text blue. */
239
148
  bgBlue: (input: string | TemplateStringsArray) => string;
240
- /**
241
- * Make the background of some text magenta.
242
- *
243
- * @param input The text whose background to colour.
244
- * @returns If colours are enabled, `input` with a magenta background.
245
- */
149
+ /** Colour the background of some text magenta. */
246
150
  bgMagenta: (input: string | TemplateStringsArray) => string;
247
- /**
248
- * Make the background of some text cyan.
249
- *
250
- * @param input The text whose background to colour.
251
- * @returns If colours are enabled, `input` with a cyan background.
252
- */
151
+ /** Colour the background of some text cyan. */
253
152
  bgCyan: (input: string | TemplateStringsArray) => string;
254
- /**
255
- * Make the background of some text white.
256
- *
257
- * @param input The text whose background to colour.
258
- * @returns If colours are enabled, `input` with a white background.
259
- */
153
+ /** Colour the background of some text white. */
260
154
  bgWhite: (input: string | TemplateStringsArray) => string;
261
- /**
262
- * Make the background of some text bright black (grey).
263
- *
264
- * @param input The text whose background to colour.
265
- * @returns If colours are enabled, `input` with a bright black (grey) background.
266
- */
155
+ /** Colour the background of some text bright black (grey). */
267
156
  bgBlackBright: (input: string | TemplateStringsArray) => string;
268
- /**
269
- * Make the background of some text bright red.
270
- *
271
- * @param input The text whose background to colour.
272
- * @returns If colours are enabled, `input` with a bright re backgroundd.
273
- */
157
+ /** Colour the background of some text bright red. */
274
158
  bgRedBright: (input: string | TemplateStringsArray) => string;
275
- /**
276
- * Make the background of some text bright green.
277
- *
278
- * @param input The text whose background to colour.
279
- * @returns If colours are enabled, `input` with a bright gree backgroundn.
280
- */
159
+ /** Colour the background of some text bright green. */
281
160
  bgGreenBright: (input: string | TemplateStringsArray) => string;
282
- /**
283
- * Make the background of some text bright yellow.
284
- *
285
- * @param input The text whose background to colour.
286
- * @returns If colours are enabled, `input` with a bright yello backgroundw.
287
- */
161
+ /** Colour the background of some text bright yellow. */
288
162
  bgYellowBright: (input: string | TemplateStringsArray) => string;
289
- /**
290
- * Make the background of some text bright blue.
291
- *
292
- * @param input The text whose background to colour.
293
- * @returns If colours are enabled, `input` with a bright blu backgrounde.
294
- */
163
+ /** Colour the background of some text bright blue. */
295
164
  bgBlueBright: (input: string | TemplateStringsArray) => string;
296
- /**
297
- * Make the background of some text bright magenta.
298
- *
299
- * @param input The text whose background to colour.
300
- * @returns If colours are enabled, `input` with a bright magent backgrounda.
301
- */
165
+ /** Colour the background of some text bright magenta. */
302
166
  bgMagentaBright: (input: string | TemplateStringsArray) => string;
303
- /**
304
- * Make the background of some text bright cyan.
305
- *
306
- * @param input The desired text to be styled.
307
- * @returns If colours are enabled, `input` with a bright cyan background.
308
- */
167
+ /** Colour the background of some text bright cyan. */
309
168
  bgCyanBright: (input: string | TemplateStringsArray) => string;
310
- /**
311
- * Make the background of some text bright white.
312
- *
313
- * @param input The desired text to be styled.
314
- * @returns If colours are enabled, `input` with a bright white background.
315
- */
169
+ /** Colour the background of some text bright white. */
316
170
  bgWhiteBright: (input: string | TemplateStringsArray) => string;
317
171
  /**
318
172
  * Make some text or its background one of 256 colours.
@@ -324,7 +178,7 @@ interface Termark {
324
178
  * @returns If terminal colours are enabled and [8-bit colours](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) are supported, the stylized text. If either is false, it returns the plain string.
325
179
  * @see https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
326
180
  */
327
- ansi256: (type: 'text' | 'background', color: number) => (input: string | TemplateStringsArray) => string;
181
+ ansi256(type: ANSIStyleType, color: number): (input: string | TemplateStringsArray) => string;
328
182
  /**
329
183
  * Make some text or its background using custom RGB values.
330
184
  *
@@ -340,7 +194,7 @@ interface Termark {
340
194
  * termark.rgb('text', [85, 222, 124])('...');
341
195
  * ```
342
196
  */
343
- rgb: (type: 'text' | 'background', ...rgb: [number, number, number] | [[number, number, number]]) => (input: string | TemplateStringsArray) => string;
197
+ rgb(type: ANSIStyleType, ...rgb: RGB | [RGB]): (input: string | TemplateStringsArray) => string;
344
198
  /**
345
199
  * Apply a gradient to some text or its background.
346
200
  *
@@ -357,7 +211,7 @@ interface Termark {
357
211
  * termark.gradient('background', [[222, 111, 0], [93, 255, 68], [0, 224, 110]])('...');
358
212
  * ```
359
213
  */
360
- gradient: (type: 'text' | 'background', colors: [number, number, number][]) => (input: string | TemplateStringsArray) => string;
214
+ gradient(type: ANSIStyleType, colors: RGB[]): (input: string | TemplateStringsArray) => string;
361
215
  /**
362
216
  * Logs a `message` to the console on the `info` level.
363
217
  *
@@ -374,7 +228,7 @@ interface Termark {
374
228
  * termark.success('...'); // Logs "..." in green as a success (info).
375
229
  * ```
376
230
  */
377
- success: (message: string, prefix?: string) => void;
231
+ success(message: string, prefix?: string): void;
378
232
  /**
379
233
  * Logs a `message` to the console on the `info` level.
380
234
  *
@@ -388,7 +242,7 @@ interface Termark {
388
242
  * termark.info('...'); // Logs "..." in blue as an info.
389
243
  * ```
390
244
  */
391
- info: (message: string, prefix?: string) => void;
245
+ info(message: string, prefix?: string): void;
392
246
  /**
393
247
  * Logs a `message` to the console on the `error` level.
394
248
  *
@@ -406,7 +260,7 @@ interface Termark {
406
260
  * termark.warn('...'); // Logs "..." in yellow as a warning (error).
407
261
  * ```
408
262
  */
409
- warn: (message: string, prefix?: string) => void;
263
+ warn(message: string, prefix?: string): void;
410
264
  /**
411
265
  * Logs a `message` to the console on the `error` level.
412
266
  *
@@ -420,7 +274,7 @@ interface Termark {
420
274
  * termark.error('...'); // Logs "..." in red as an error.
421
275
  * ```
422
276
  */
423
- error: (message: string, prefix?: string) => void;
277
+ error(message: string, prefix?: string): void;
424
278
  /**
425
279
  * Style some text using entirely custom settings.
426
280
  *
@@ -442,73 +296,5 @@ interface Termark {
442
296
  * termark.custom('58;2;33', 59)('...'); // This should result in a string with a blue underline.
443
297
  * ```
444
298
  */
445
- custom: (opener: number | string, closer: number | string, type: 'asFormat' | 'asColor') => (input: string | TemplateStringsArray) => string;
299
+ custom(opener: string | number, closer: string | number, type: 'asColor' | 'asFormat'): (input: string | TemplateStringsArray) => string;
446
300
  }
447
- /**
448
- * The `termark` object enables accessing all features of Termark:
449
- *
450
- * - Properties (retrieve information)
451
- * - Methods (commands)
452
- *
453
- * For info regarding ANSI styling:
454
- * @see https://en.wikipedia.org/wiki/ANSI_escape_code
455
- *
456
- * ---
457
- *
458
- * With properties, you're able to use features of Termark that don't execute
459
- * any command per se, but simply to retrieve information; you don't perform
460
- * any operation with these.
461
- *
462
- * @example
463
- * ```typescript
464
- * import termark from 'termark';
465
- *
466
- * // All properties provided by Termark:
467
- *
468
- * termark.areColorsEnabled; // Check whether colours are enabled
469
- * termark.is8bitEnabled; // Check whether 8-bit (256) colours are enabled
470
- * termark.is24bitEnabled; // Check whether 24-bit (truecolor) colours are enabled
471
- * ```
472
- *
473
- * In addition, properties on the `termark` object are static, i.e., they only do one thing, and you have no input on it.
474
- *
475
- * ---
476
- *
477
- * With methods on the other hand, you *do* perform commands and operations.
478
- * Methods are dynamic, meaning that you *do* specify how they work.
479
- *
480
- * @example
481
- * ```typescript
482
- * import termark from 'termark';
483
- *
484
- * termark.red('...'); // Returns "..." in red.
485
- * termark.rgb('background', [255, 255, 255])('...'); // Returns "..." with a white background.
486
- * ```
487
- *
488
- * With all methods, you **must** append either `('...')` or ``` `...` ```, and replace "`...`"
489
- * with a string of your choosing. This is made possible by the fact that most of (see below) Termark's
490
- * methods return a function where you specify your input.
491
- *
492
- * @example
493
- * ```typescript
494
- * termark.ansi256('text', 33)('This is blue text');
495
- * termark.ansi256('text', 33)`This is also blue text`;
496
- * ```
497
- *
498
- * ### Exceptions
499
- *
500
- * There are some exceptions to the above, however; not *all* of Termark's methods return
501
- * a function to specify your input. These ones are:
502
- *
503
- * ```typescript
504
- * termark.success('...');
505
- * termark.info('...');
506
- * termark.warn('...');
507
- * termark.error('...');
508
- * ```
509
- *
510
- * This is because the above three methods handle console outputs for you. Therefore, they needn't
511
- * return a function where you specify your input.
512
- */
513
- declare const termark: Termark;
514
- export default termark;
package/dist/index.mjs CHANGED
@@ -1,179 +1 @@
1
- /*
2
- Copyright 2025 Q
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */
16
-
17
- const areColoursEnabled = () => {
18
- const noColour = process.env.NO_COLOR;
19
- return noColour ? false : true;
20
- };
21
- const getColourSupport = () => {
22
- const colourTerm = process.env.COLORTERM;
23
- const is16bit = colourTerm ? (colourTerm.includes('ansi') && !(colourTerm.includes('256'))) : false;
24
- const is256 = colourTerm ? colourTerm.includes('ansi256') : false;
25
- const isTrueColor = colourTerm ? (colourTerm.includes('truecolor') || colourTerm.includes('24bit')) : false;
26
- return {
27
- is16bit,
28
- is256,
29
- isTrueColor
30
- };
31
- };
32
- function format(open, close, type) {
33
- if (type === 'color' && !areColoursEnabled())
34
- return (input) => input.toString();
35
- const opener = `\x1b[${open}m`;
36
- const closer = `\x1b[${close}m`;
37
- return (input$1) => {
38
- const input = input$1.toString().trim();
39
- const index = input.indexOf(closer);
40
- if (index === -1)
41
- return `${opener}${input}${closer}`;
42
- return `${opener}${input.replaceAll(closer, closer + opener)}${closer}`;
43
- };
44
- }
45
- function interpolate(color1, color2, factor) {
46
- return [
47
- Math.round(color1[0] + factor * (color2[0] - color1[0])),
48
- Math.round(color1[1] + factor * (color2[1] - color1[1])),
49
- Math.round(color1[2] + factor * (color2[2] - color1[2])),
50
- ];
51
- }
52
-
53
- const termark = {
54
- areColorsEnabled: areColoursEnabled(),
55
- is8bitEnabled: getColourSupport().is256,
56
- is24bitEnabled: getColourSupport().isTrueColor,
57
- reset: format(0, 0, 'format'),
58
- bold: format(1, 22, 'format'),
59
- dim: format(2, 22, 'format'),
60
- italic: format(3, 23, 'format'),
61
- underline: format(4, 24, 'format'),
62
- blink: format(5, 25, 'format'),
63
- inverse: format(7, 27, 'format'),
64
- overline: format(53, 55, 'format'),
65
- hidden: format(8, 28, 'format'),
66
- strike: format(9, 29, 'format'),
67
- black: format(30, 39, 'color'),
68
- red: format(31, 39, 'color'),
69
- green: format(32, 39, 'color'),
70
- yellow: format(33, 39, 'color'),
71
- blue: format(34, 39, 'color'),
72
- magenta: format(35, 39, 'color'),
73
- cyan: format(36, 39, 'color'),
74
- white: format(37, 39, 'color'),
75
- blackBright: format(90, 39, 'color'),
76
- redBright: format(91, 39, 'color'),
77
- greenBright: format(92, 39, 'color'),
78
- yellowBright: format(93, 39, 'color'),
79
- blueBright: format(94, 39, 'color'),
80
- magentaBright: format(95, 39, 'color'),
81
- cyanBright: format(96, 39, 'color'),
82
- whiteBright: format(97, 39, 'color'),
83
- bgBlack: format(40, 49, 'color'),
84
- bgRed: format(41, 49, 'color'),
85
- bgGreen: format(42, 49, 'color'),
86
- bgYellow: format(43, 49, 'color'),
87
- bgBlue: format(44, 49, 'color'),
88
- bgMagenta: format(45, 49, 'color'),
89
- bgCyan: format(46, 49, 'color'),
90
- bgWhite: format(47, 49, 'color'),
91
- bgBlackBright: format(100, 49, 'color'),
92
- bgRedBright: format(101, 49, 'color'),
93
- bgGreenBright: format(102, 49, 'color'),
94
- bgYellowBright: format(103, 49, 'color'),
95
- bgBlueBright: format(104, 49, 'color'),
96
- bgMagentaBright: format(105, 49, 'color'),
97
- bgCyanBright: format(106, 49, 'color'),
98
- bgWhiteBright: format(107, 49, 'color'),
99
- ansi256(type, color) {
100
- if (color < 0 || color > 255)
101
- throw new Error(termark.red('Value `color` is out of range! The value must be a number between 0 and 255!'));
102
- if (!getColourSupport().is256 || !areColoursEnabled())
103
- return (input) => input.toString();
104
- const textFormat = `38;5;${color}`;
105
- const bgFormat = `48;5;${color}`;
106
- const opener = type === 'text' ? textFormat : bgFormat;
107
- const closer = type === 'text' ? 39 : 49;
108
- return format(opener, closer, 'color');
109
- },
110
- rgb(type, ...rgb) {
111
- let red;
112
- let green;
113
- let blue;
114
- if (Array.isArray(rgb[0])) {
115
- red = rgb[0][0];
116
- green = rgb[0][1];
117
- blue = rgb[0][2];
118
- }
119
- else {
120
- red = rgb[0];
121
- green = rgb[1];
122
- blue = rgb[2];
123
- }
124
- if (((typeof red === 'number') && (red < 0 || red > 255)) ||
125
- ((typeof green === 'number') && (green < 0 || green > 255)) ||
126
- ((typeof blue === 'number') && (blue < 0 || blue > 255)))
127
- throw new Error(termark.red('One or multiple of the colours specified is out of range! Each colour can have a value only between 0 and 255!'));
128
- if (!getColourSupport().isTrueColor)
129
- return (input) => input.toString();
130
- const textFormat = `38;2;${red};${green};${blue}`;
131
- const bgFormat = `48;2;${red};${green};${blue}`;
132
- const opener = type === 'text' ? textFormat : bgFormat;
133
- const closer = type === 'text' ? 39 : 49;
134
- return format(opener, closer, 'color');
135
- },
136
- gradient(type, colors) {
137
- if (!areColoursEnabled() || !getColourSupport().isTrueColor)
138
- return (input) => input.toString();
139
- const textFormat = `38;2;`;
140
- const bgFormat = `48;2;`;
141
- const opener = type === 'text' ? `\x1b[${textFormat}` : `\x1b[${bgFormat}`;
142
- const closer = type === 'text' ? `\x1b[${39}m` : `\x1b[${49}m`;
143
- return (input$1) => {
144
- const input = input$1.toString().trim();
145
- const colourCount = colors.length;
146
- const step = Math.min(input.length / (colourCount - 1));
147
- let result = '';
148
- for (let character = 0; character < input.length; character++) {
149
- const colourIndex = Math.min(Math.floor(character / step), colourCount - 2);
150
- const factor = (character % step) / step;
151
- const startColour = colors[colourIndex];
152
- const endColour = colors[colourIndex + 1];
153
- const interpolatedColour = interpolate(startColour, endColour, factor);
154
- result += `${opener}${interpolatedColour[0]};${interpolatedColour[1]};${interpolatedColour[2]}m${input[character]}${closer}`;
155
- }
156
- return result;
157
- };
158
- },
159
- success(message, prefix = '') {
160
- console.info(`${prefix}${termark.green(message)}`);
161
- },
162
- info(message, prefix = '') {
163
- console.info(`${prefix}${termark.blue(message)}`);
164
- },
165
- warn(message, prefix = '') {
166
- console.warn(`${prefix}${termark.yellow(message)}`);
167
- },
168
- error(message, prefix = '') {
169
- console.error(`${prefix}${termark.red(message)}`);
170
- },
171
- custom(opener, closer, type) {
172
- const formatType = type === 'asColor' ? 'color' : 'format';
173
- return format(opener, closer, formatType);
174
- },
175
- };
176
-
177
- export { termark as default };
178
-
179
- // Copyright (C) 2025 Q
1
+ 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 o(t,o,e){if("color"===e&&!r())return r=>r.toString();const i=`[${t}m`,n=`[${o}m`;return r=>{const t=r.toString().trim();return-1===t.indexOf(n)?`${i}${t}${n}`:`${i}${t.replaceAll(n,n+i)}${n}`}}function e(r,t,o){return[Math.round(r[0]+o*(t[0]-r[0])),Math.round(r[1]+o*(t[1]-r[1])),Math.round(r[2]+o*(t[2]-r[2]))]}class i{constructor(){this.areColorsEnabled=r(),this.is8bitEnabled=t().is256,this.is24bitEnabled=t().isTrueColor,this.reset=o(0,0,"format"),this.bold=o(1,22,"format"),this.dim=o(2,22,"format"),this.italic=o(3,23,"format"),this.underline=o(4,24,"format"),this.blink=o(5,25,"format"),this.inverse=o(7,27,"format"),this.overline=o(53,55,"format"),this.hidden=o(8,28,"format"),this.strike=o(9,29,"format"),this.black=o(30,39,"color"),this.red=o(31,39,"color"),this.green=o(32,39,"color"),this.yellow=o(33,39,"color"),this.blue=o(34,39,"color"),this.magenta=o(35,39,"color"),this.cyan=o(36,39,"color"),this.white=o(37,39,"color"),this.blackBright=o(90,39,"color"),this.redBright=o(91,39,"color"),this.greenBright=o(92,39,"color"),this.yellowBright=o(93,39,"color"),this.blueBright=o(94,39,"color"),this.magentaBright=o(95,39,"color"),this.cyanBright=o(96,39,"color"),this.whiteBright=o(97,39,"color"),this.bgBlack=o(40,49,"color"),this.bgRed=o(41,49,"color"),this.bgGreen=o(42,49,"color"),this.bgYellow=o(43,49,"color"),this.bgBlue=o(44,49,"color"),this.bgMagenta=o(45,49,"color"),this.bgCyan=o(46,49,"color"),this.bgWhite=o(47,49,"color"),this.bgBlackBright=o(100,49,"color"),this.bgRedBright=o(101,49,"color"),this.bgGreenBright=o(102,49,"color"),this.bgYellowBright=o(103,49,"color"),this.bgBlueBright=o(104,49,"color"),this.bgMagentaBright=o(105,49,"color"),this.bgCyanBright=o(106,49,"color"),this.bgWhiteBright=o(107,49,"color")}ansi256(e,n){if(n<0||n>255)throw new Error((new i).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 o("text"===e?`38;5;${n}`:`48;5;${n}`,"text"===e?39:49,"color")}rgb(r,...e){let n,l,s;if(Array.isArray(e[0])?(n=e[0][0],l=e[0][1],s=e[0][2]):(n=e[0],l=e[1],s=e[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((new i).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 o("text"===r?`38;2;${n};${l};${s}`:`48;2;${n};${l};${s}`,"text"===r?39:49,"color")}gradient(o,i){if(!r()||!t().isTrueColor)return r=>r.toString();const n="text"===o?"[38;2;":"[48;2;",l="text"===o?"":"";return r=>{const t=r.toString().trim(),o=i.length,s=Math.min(t.length/(o-1));let h="";for(let r=0;r<t.length;r++){const c=Math.min(Math.floor(r/s),o-2),a=r%s/s,g=e(i[c],i[c+1],a);h+=`${n}${g[0]};${g[1]};${g[2]}m${t[r]}${l}`}return h}}success(r,t=""){console.info(`${t}${(new i).green(r)}`)}info(r,t=""){console.info(`${t}${(new i).blue(r)}`)}warn(r,t=""){console.warn(`${t}${(new i).yellow(r)}`)}error(r,t=""){console.error(`${t}${(new i).red(r)}`)}custom(r,t,e){return o(r,t,"asColor"===e?"color":"format")}}export{i as default};
package/dist/util.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export type ANSIStyleType = 'text' | 'background';
2
+ export type RGB = [number, number, number];
1
3
  /**
2
4
  * Check whether terminal colours are supported/enabled.
3
5
  *
@@ -46,4 +48,4 @@ export declare function format(open: number | string, close: number | string, ty
46
48
  * @param factor How to calculate the colour.
47
49
  * @returns An RGB value that is the colour between `color1` and `color2` at `factor`.
48
50
  */
49
- export declare function interpolate(color1: [number, number, number], color2: [number, number, number], factor: number): [number, number, number];
51
+ export declare function interpolate(color1: RGB, color2: RGB, factor: number): RGB;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "termark",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "main": "./dist/index.cjs",
5
5
  "module": "./dist/index.mjs",
6
6
  "exports": {
@@ -30,9 +30,9 @@
30
30
  "url": "https://codeberg.org/Genesis_Software/termark.git"
31
31
  },
32
32
  "devDependencies": {
33
+ "@rollup/plugin-terser": "^0.4.4",
33
34
  "@types/node": "^24.3.0",
34
35
  "rollup": "^4.49.0",
35
- "rollup-plugin-cleanup": "^3.2.1",
36
36
  "rollup-plugin-typescript2": "^0.36.0",
37
37
  "typescript": "^5.9.2"
38
38
  }