termark 2.1.0 → 3.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.
@@ -0,0 +1,54 @@
1
+ import { ColourLevel } from "./types.mjs";
2
+
3
+ //#region src/utilities.d.ts
4
+ /**
5
+ * Check whether colours are supported in a given terminal environment.
6
+ *
7
+ * Use {@linkcode hasNoColour} for checking whether terminals that *could* support colour don't do so.
8
+ */
9
+ declare function areColoursSupported(): boolean;
10
+ /**
11
+ * Check whether a terminal environment supports at least some level of colours.
12
+ *
13
+ * @param level A colour level.
14
+ */
15
+ declare function supports(level: ColourLevel): boolean;
16
+ /**
17
+ * Check whether a terminal environment supports at most a given colour level.
18
+ *
19
+ * @param level A colour level.
20
+ */
21
+ declare function supportsAtMost(level: ColourLevel): boolean;
22
+ /**
23
+ * Modify the plain text part of a string with ANSI escape sequences.
24
+ *
25
+ * @example Creating a `toUpperCase` method for ANSI strings
26
+ * ```ts
27
+ * import { transformPreserveAnsi } from "termark";
28
+ *
29
+ * const toUpperCase = transformPreserveAnsi((str) => str.toUpperCase());
30
+ * ```
31
+ *
32
+ * @param fn A function that transforms some string.
33
+ */
34
+ declare function transformPreserveAnsi(fn: (plain: string) => string): (str: string) => string;
35
+ /**
36
+ * Make some string upper-case while preserving ANSI escape sequences as-is.
37
+ *
38
+ * @str The string to transform.
39
+ */
40
+ declare const ansiUpperCase: (str: string) => string;
41
+ /**
42
+ * Make some string lower-case while preserving ANSI escape sequences as-is.
43
+ *
44
+ * @param str The string to transform.
45
+ */
46
+ declare const ansiLowerCase: (str: string) => string;
47
+ /**
48
+ * Remove ANSI escape sequences from some text.
49
+ *
50
+ * @param input The input to strip of ANSI escape sequences.
51
+ */
52
+ declare function stripAnsi(input: string): string;
53
+ //#endregion
54
+ export { ansiLowerCase, ansiUpperCase, areColoursSupported, stripAnsi, supports, supportsAtMost, transformPreserveAnsi };
@@ -0,0 +1 @@
1
+ import{getColourLevel as e}from"./__internal/env.mjs";function t(){return e()!==0}function n(t){return e()>=t}function r(t){return e()<=t}function i(e){return t=>{let n=/(\u{001B}\[[0-9;]*[A-PRZ])|(.+?)/giu,r=``;for(let i of t.matchAll(n)){let t=i[0];r+=t.charCodeAt(0)===27?t:e(t)}return r}}const a=i(e=>e.toUpperCase()),o=i(e=>e.toLowerCase());function s(e){return e.replace(/\u{001B}\[[0-9;]*m/gu,``)}export{o as ansiLowerCase,a as ansiUpperCase,t as areColoursSupported,s as stripAnsi,n as supports,r as supportsAtMost,i as transformPreserveAnsi};
package/package.json CHANGED
@@ -1,39 +1,51 @@
1
1
  {
2
2
  "name": "termark",
3
- "version": "2.1.0",
4
- "main": "./dist/index.cjs",
5
- "module": "./dist/index.mjs",
6
- "exports": {
7
- ".": {
8
- "types": "./dist/index.d.ts",
9
- "import": "./dist/index.mjs",
10
- "require": "./dist/index.cjs"
11
- }
12
- },
3
+ "version": "3.0.0",
4
+ "description": "A basic library to format console output to the standard non-browser terminal.",
13
5
  "keywords": [
14
- "utility",
15
6
  "console",
7
+ "formatting",
16
8
  "node",
17
9
  "output",
18
- "formatting"
10
+ "utility"
19
11
  ],
20
- "author": "Miyazaki \"Q\" Hashimoto",
21
- "license": "Apache-2.0",
22
- "description": "A basic library to format console output to the standard non-browser terminal.",
23
12
  "homepage": "https://genesis.q-file.com/projects/termark",
13
+ "license": "Apache-2.0",
14
+ "author": "Miyazaki \"Q\" Hashimoto",
24
15
  "repository": {
25
16
  "type": "git",
26
17
  "url": "https://codeberg.org/Genesis_Software/termark.git"
27
18
  },
19
+ "type": "module",
20
+ "main": "./dist/index.cjs",
21
+ "module": "./dist/index.mjs",
22
+ "types": "./dist/index.d.mts",
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/index.d.mts",
26
+ "import": "./dist/index.mjs",
27
+ "require": "./dist/index.cjs"
28
+ }
29
+ },
28
30
  "devDependencies": {
29
- "@rollup/plugin-terser": "^0.4.4",
30
31
  "@types/node": "^24.3.0",
31
- "rollup": "^4.49.0",
32
- "rollup-plugin-typescript2": "^0.36.0",
33
- "typescript": "^5.9.2"
32
+ "oxfmt": "^0.50.0",
33
+ "oxlint": "^1.65.0",
34
+ "tsdown": "^0.22.0",
35
+ "tsx": "^4.22.0",
36
+ "typescript": "^5.9.2",
37
+ "vitest": "^4.1.6"
34
38
  },
39
+ "readme": "README.npm.md",
35
40
  "scripts": {
36
- "build": "rollup -c",
37
- "test": "node dist/index.mjs"
41
+ "build": "tsdown --config .config/tsdown.config.ts",
42
+ "format": "oxfmt --config .config/oxfmt.config.ts",
43
+ "lint": "oxlint",
44
+ "lint:fix": "oxlint --fix",
45
+ "test": "vitest --config .config/vitest.config.ts",
46
+ "demo:truecolor": "tsx examples/truecolor.ts",
47
+ "demo:box": "tsx examples/box.ts",
48
+ "demo:basic": "tsx examples/basic.ts",
49
+ "demo:link": "tsx examples/link.ts"
38
50
  }
39
51
  }
package/dist/index.d.ts DELETED
@@ -1,383 +0,0 @@
1
- import { ANSIStyleType, RGB, FormatFunction, LoggerOptions, LogObject } from './util';
2
- /**
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
- *
5
- * However, it is nonetheless useful as it enables type-safety,
6
- *
7
- * You use this class the same way as you would the {@linkcode termark} object.
8
- *
9
- * @example
10
- * ```typescript
11
- * import { Termark } from 'termark';
12
- *
13
- * const termark = new Termark(); // This is the same as if you'd import the `termark` object.
14
- * termark.success('Termark is working!');
15
- *
16
- * // Alternatively, you could do:
17
- * Termark.init.success('This works, too!');
18
- * ```
19
- *
20
- * @see The {@linkcode termark} object.
21
- */
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;
46
- private static successPrefix;
47
- private static infoPrefix;
48
- private static warnPrefix;
49
- private static errorPrefix;
50
- /** Check whether terminal colours are enabled. */
51
- areColorsEnabled: boolean;
52
- /** Check whether 8-bit colours are enabled. */
53
- is8bitEnabled: boolean;
54
- /** Check whether 24-bit colours are enabled. */
55
- is24bitEnabled: boolean;
56
- /** Reset all styles. */
57
- reset: FormatFunction;
58
- /** Make some text bold. */
59
- bold: FormatFunction;
60
- /** Make some text thin. */
61
- dim: FormatFunction;
62
- /** Make some text italic. May not be widely supported. */
63
- italic: FormatFunction;
64
- /** Underline some text. */
65
- underline: FormatFunction;
66
- /** Make some text blink slowly. May not be widely supported/may not work everywhere. */
67
- blink: FormatFunction;
68
- /** Invert some text (foreground colour becomes background colour, background colour becomes foreground colour). */
69
- inverse: FormatFunction;
70
- /** Add a line above some text. May not be widely supported. */
71
- overline: FormatFunction;
72
- /** Visually hide some text. */
73
- hidden: FormatFunction;
74
- /** Add a line through (strike) some text. */
75
- strike: FormatFunction;
76
- /** Colour some text black. */
77
- black: FormatFunction;
78
- /** Colour some text red. */
79
- red: FormatFunction;
80
- /** Colour some text green. */
81
- green: FormatFunction;
82
- /** Colour some text yellow. */
83
- yellow: FormatFunction;
84
- /** Colour some text blue. */
85
- blue: FormatFunction;
86
- /** Colour some text magenta. */
87
- magenta: FormatFunction;
88
- /** Colour some text cyan. */
89
- cyan: FormatFunction;
90
- /** Colour some text white. */
91
- white: FormatFunction;
92
- /** Colour some text bright black (grey). */
93
- blackBright: FormatFunction;
94
- /** Colour some text bright red. */
95
- redBright: FormatFunction;
96
- /** Colour some text bright green. */
97
- greenBright: FormatFunction;
98
- /** Colour some text bright yellow. */
99
- yellowBright: FormatFunction;
100
- /** Colour some text bright blue. */
101
- blueBright: FormatFunction;
102
- /** Colour some text bright magenta. */
103
- magentaBright: FormatFunction;
104
- /** Colour some text bright cyan. */
105
- cyanBright: FormatFunction;
106
- /** Colour some text bright white. */
107
- whiteBright: FormatFunction;
108
- /** Colour the background of some text black. */
109
- bgBlack: FormatFunction;
110
- /** Colour the background of some text red. */
111
- bgRed: FormatFunction;
112
- /** Colour the background of some text green. */
113
- bgGreen: FormatFunction;
114
- /** Colour the background of some text yellow. */
115
- bgYellow: FormatFunction;
116
- /** Colour the background of some text blue. */
117
- bgBlue: FormatFunction;
118
- /** Colour the background of some text magenta. */
119
- bgMagenta: FormatFunction;
120
- /** Colour the background of some text cyan. */
121
- bgCyan: FormatFunction;
122
- /** Colour the background of some text white. */
123
- bgWhite: FormatFunction;
124
- /** Colour the background of some text bright black (grey). */
125
- bgBlackBright: FormatFunction;
126
- /** Colour the background of some text bright red. */
127
- bgRedBright: FormatFunction;
128
- /** Colour the background of some text bright green. */
129
- bgGreenBright: FormatFunction;
130
- /** Colour the background of some text bright yellow. */
131
- bgYellowBright: FormatFunction;
132
- /** Colour the background of some text bright blue. */
133
- bgBlueBright: FormatFunction;
134
- /** Colour the background of some text bright magenta. */
135
- bgMagentaBright: FormatFunction;
136
- /** Colour the background of some text bright cyan. */
137
- bgCyanBright: FormatFunction;
138
- /** Colour the background of some text bright white. */
139
- bgWhiteBright: FormatFunction;
140
- /**
141
- * Make some text or its background one of 256 colours.
142
- * If `color` is bigger than 255 or smaller than 0, it automatically rounds to 255 or 0 respectively.
143
- *
144
- * @param type Whether the styling should be applied to the text itself or the background.
145
- * @param color A number between 0 and 255 that specifies the colour.
146
- * @param content The string that should be styled.
147
- * @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.
148
- * @see https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
149
- */
150
- ansi256(type: ANSIStyleType, color: number): FormatFunction;
151
- /**
152
- * Make some text or its background using custom RGB values.
153
- *
154
- * @param type Whether to apply the colour to the text itself or its background.
155
- * @param rgb A list of `red`, `green`, and `blue` values.
156
- * @returns A function to specify an input, which returns the stylized text, assuming colours are enabled, *and* `truecolor` is enabled as well.
157
- *
158
- * @example
159
- * ```typescript
160
- * import termark from 'termark';
161
- *
162
- * termark.rgb('background', 128, 84, 249)('...');
163
- * termark.rgb('text', [85, 222, 124])('...');
164
- * ```
165
- */
166
- rgb(type: ANSIStyleType, ...rgb: RGB | [RGB]): FormatFunction;
167
- /**
168
- * Apply a gradient to some text or its background.
169
- *
170
- * @param type Whether to apply the gradient to the text itself or its background.
171
- * @param colors An array of RGB values
172
- * @returns A function to specify an input, which returns the stylized input, assuming colours are enabled, *and* `truecolor` is enabled as well.
173
- * @see https://htmlcolorcodes.com/ For colour conversions.
174
- *
175
- * @example
176
- * ```typescript
177
- * import termark from 'termark';
178
- *
179
- * termark.gradient('text', [[53, 72, 172], [200, 230, 121]])('...');
180
- * termark.gradient('background', [[222, 111, 0], [93, 255, 68], [0, 224, 110]])('...');
181
- * ```
182
- */
183
- gradient(type: ANSIStyleType, colors: RGB[]): FormatFunction;
184
- /**
185
- * Logs a `message` to the console on the `info` level.
186
- *
187
- * **Note:** Since there is no dedicated '`success`' method, we have to print to the same level
188
- * as `info()`.
189
- *
190
- * @param message The message to be logged in green as a success (info).
191
- * @param prefix An optional brand prefix.
192
- *
193
- * @example
194
- * ```typescript
195
- * import termark from 'termark';
196
- *
197
- * termark.success('...'); // Logs "..." in green as a success (info).
198
- * ```
199
- */
200
- success(message: string | TemplateStringsArray, prefix?: string): void;
201
- /**
202
- * Logs a `message` to the console on the `info` level.
203
- *
204
- * @param message The message to be logged in blue as an info.
205
- * @param prefix An optional brand prefix.
206
- *
207
- * @example
208
- * ```typescript
209
- * import termark from 'termark';
210
- *
211
- * termark.info('...'); // Logs "..." in blue as an info.
212
- * ```
213
- */
214
- info(message: string | TemplateStringsArray, prefix?: string): void;
215
- /**
216
- * Logs a `message` to the console on the `error` level.
217
- *
218
- * **Note:** In Node, `console.warn` and `console.error` print to the *same* level (`error`),
219
- * and are therefore interchangeable. As such, this method only exists to provide a different look
220
- * for an error message (e.g., for non-fatal errors).
221
- *
222
- * @param message The message to be logged in yellow as a warning (error).
223
- * @param prefix An optional brand prefix.
224
- *
225
- * @example
226
- * ```typescript
227
- * import termark from 'termark';
228
- *
229
- * termark.warn('...'); // Logs "..." in yellow as a warning (error).
230
- * ```
231
- */
232
- warn(message: string | TemplateStringsArray, prefix?: string): void;
233
- /**
234
- * Logs a `message` to the console on the `error` level.
235
- *
236
- * @param message The message to be logged in red as an error.
237
- * @param prefix An optional brand prefix.
238
- *
239
- * @example
240
- * ```typescript
241
- * import termark from 'termark';
242
- *
243
- * termark.error('...'); // Logs "..." in red as an error.
244
- * ```
245
- */
246
- error(message: string | TemplateStringsArray, prefix?: string): void;
247
- /**
248
- * Style some text using entirely custom settings.
249
- *
250
- * Please not that this method will not return any errors by itself.
251
- * As such, it's advised that you're familiar with [the ANSI escape code](https://en.wikipedia.org/wiki/ANSI_escape_code) if you plan to use this method.
252
- * However, this method will still return the plain text if the styling you want to apply doesn't exist.
253
- *
254
- * Also note that you **mustn't include the actual escape sequence (e.g., `\x1b[`), nor the symbol at the end of the code (e.g., `m`)**, only the parameters themselves.
255
- *
256
- * @param opener The code that should be prepended to the text. This is for styling your input itself.
257
- * @param closer The code that should be appended to the text. This is for styling what comes after your input. It's best if this is either `0`, or the code to set the default style of something (e.g., `39` to reset to the default text colour).
258
- * @param type Whether the formatting should be viewed as applying colour, or performing simple styling. If it is the former, styling won't be applied if terminal colours are disabled.
259
- * @returns The text stylized using `opener`.
260
- *
261
- * @example
262
- * ```typescript
263
- * import termark from 'termark';
264
- *
265
- * termark.custom('58;2;33', 59)('...'); // This should result in a string with a blue underline.
266
- * ```
267
- */
268
- custom(opener: string | number, closer: string | number, type: 'asColor' | 'asFormat'): FormatFunction;
269
- /**
270
- * Create a theme (multiple stylings grouped together).
271
- *
272
- * This creates a function you can call to style some desired string using the stylings
273
- * you specified.
274
- *
275
- * @example
276
- * ```ts
277
- * import termark, { Termark } from 'termark';
278
- *
279
- * const myTheme = Termark.createTheme(
280
- * termark.bold,
281
- * termark.blue,
282
- * termark.bgGreen
283
- * );
284
- *
285
- * console.log(
286
- * myTheme('...') // message will be bold with a green background and blue text
287
- * );
288
- * ```
289
- *
290
- * @param styles Stylings to apply.
291
- * @returns A function to style some desired text using the specified styles.
292
- */
293
- static createTheme(...styles: FormatFunction[]): FormatFunction;
294
- /**
295
- * Define a custom logger.
296
- *
297
- * Using the `options` object, you can specify the styling that is applied to each method. For example, you can customize
298
- * how a message logged using `error()` looks.
299
- *
300
- * For `success()`, `info()`, `warn()`, and `error()`, you can also customize the prefix.
301
- *
302
- * The resulting methods are exactly like the predefined ones, apart from the custom styling. That means that each method also
303
- * takes an optional `prefix` argument for branding purposes.
304
- *
305
- * @param options An object to customize the logger.
306
- * @returns An object with methods to log various messages to the terminal with various (semantic) styling.
307
- */
308
- static createLogger(options: LoggerOptions): LogObject;
309
- }
310
- /**
311
- * The `termark` object enables accessing all features of Termark:
312
- *
313
- * - Properties (retrieve information)
314
- * - Methods (commands)
315
- *
316
- * For info regarding ANSI styling:
317
- * @see https://en.wikipedia.org/wiki/ANSI_escape_code
318
- *
319
- * ---
320
- *
321
- * With properties, you're able to use features of Termark that don't execute
322
- * any command per se, but simply to retrieve information; you don't perform
323
- * any operation with these.
324
- *
325
- * @example
326
- * ```typescript
327
- * import termark from 'termark';
328
- *
329
- * // All properties provided by Termark:
330
- *
331
- * termark.areColorsEnabled; // Check whether colours are enabled
332
- * termark.is8bitEnabled; // Check whether 8-bit (256) colours are enabled
333
- * termark.is24bitEnabled; // Check whether 24-bit (truecolor) colours are enabled
334
- * ```
335
- *
336
- * In addition, properties on the `Termark` class are static-ish, i.e., they only do one thing, and you have no input on it.
337
- *
338
- * ---
339
- *
340
- * With methods on the other hand, you *do* perform commands and operations.
341
- * Methods are dynamic, meaning that you *do* specify how they work.
342
- *
343
- * @example
344
- * ```typescript
345
- * import termark from 'termark';
346
- *
347
- * termark.red('...'); // Returns "..." in red.
348
- * termark.rgb('background', [255, 255, 255])('...'); // Returns "..." with a white background.
349
- * ```
350
- *
351
- * With all methods, you **must** append either `('...')` or ``` `...` ```, and replace "`...`"
352
- * with a string of your choosing. This is made possible by the fact that most of (see below) Termark's
353
- * methods return a function where you specify your input.
354
- *
355
- * @example
356
- * ```typescript
357
- * import termark from 'termark';
358
- *
359
- * termark.ansi256('text', 33)('This is blue text');
360
- * termark.ansi256('text', 33)`This is also blue text`;
361
- * ```
362
- *
363
- * ### Exceptions
364
- *
365
- * There are some exceptions to the above, however; not *all* of Termark's methods return
366
- * a function to specify your input. These ones are:
367
- *
368
- * ```typescript
369
- * import termark from 'termark';
370
- *
371
- * termark.success('...');
372
- * termark.info('...');
373
- * termark.warn('...');
374
- * termark.error('...');
375
- * ```
376
- *
377
- * This is because the above three methods handle console outputs for you. Therefore, they needn't
378
- * return a function where you specify your input.
379
- */
380
- declare const termark: Termark;
381
- export default termark;
382
- export declare const areColorsEnabled: boolean, is8bitEnabled: boolean, is24bitEnabled: boolean, reset: FormatFunction, bold: FormatFunction, dim: FormatFunction, italic: FormatFunction, underline: FormatFunction, blink: FormatFunction, inverse: FormatFunction, overline: FormatFunction, hidden: FormatFunction, strike: FormatFunction, black: FormatFunction, red: FormatFunction, green: FormatFunction, yellow: FormatFunction, blue: FormatFunction, magenta: FormatFunction, cyan: FormatFunction, white: FormatFunction, blackBright: FormatFunction, redBright: FormatFunction, greenBright: FormatFunction, yellowBright: FormatFunction, blueBright: FormatFunction, magentaBright: FormatFunction, cyanBright: FormatFunction, whiteBright: FormatFunction, bgBlack: FormatFunction, bgRed: FormatFunction, bgGreen: FormatFunction, bgYellow: FormatFunction, bgBlue: FormatFunction, bgMagenta: FormatFunction, bgCyan: FormatFunction, bgWhite: FormatFunction, bgBlackBright: FormatFunction, bgRedBright: FormatFunction, bgGreenBright: FormatFunction, bgYellowBright: FormatFunction, bgBlueBright: FormatFunction, bgMagentaBright: FormatFunction, bgCyanBright: FormatFunction, bgWhiteBright: FormatFunction, ansi256: (type: ANSIStyleType, color: number) => FormatFunction, rgb: (type: ANSIStyleType, ...rgb: RGB | [RGB]) => FormatFunction, gradient: (type: ANSIStyleType, colors: RGB[]) => FormatFunction, success: (message: string | TemplateStringsArray, prefix?: string) => void, info: (message: string | TemplateStringsArray, prefix?: string) => void, warn: (message: string | TemplateStringsArray, prefix?: string) => void, error: (message: string | TemplateStringsArray, prefix?: string) => void, custom: (opener: string | number, closer: string | number, type: "asColor" | "asFormat") => FormatFunction;
383
- export declare const createTheme: typeof Termark.createTheme, createLogger: typeof Termark.createLogger;
package/dist/util.d.ts DELETED
@@ -1,157 +0,0 @@
1
- export type ANSIStyleType = 'text' | 'background';
2
- export type RGB = [number, number, number];
3
- /**
4
- * Check whether terminal colours are supported/enabled.
5
- *
6
- * @returns If the `NO_COLOR` environment variable is undefined, true. If it has any value, it returns false, as per the [specifications](https://no-color.org/).
7
- */
8
- export declare const areColoursEnabled: () => boolean;
9
- /**
10
- * Check whether a colour level is supported.
11
- *
12
- * @returns A property that is used to check the colour level support.
13
- */
14
- export declare const getColourSupport: () => {
15
- is16bit: boolean;
16
- is256: boolean;
17
- isTrueColor: boolean;
18
- };
19
- /**
20
- * Format some text using ANSI codes.
21
- *
22
- * @param open The code prepended to the text. This is used to style the text itself.
23
- * @param close The code appended to the text. This is used to style what comes immediately after the text, and should ideally be a reset code.
24
- * @param type Whether the styling applies basic formatting, or colours the text.
25
- * @returns If terminal colours are enabled and `type` is set to `'color'`, some coloured text. If `type` is set to `'format'`, the formatted text.
26
- */
27
- export declare function format(open: number | string, close: number | string, type: 'format' | 'color'): (input: string | TemplateStringsArray) => string;
28
- /**
29
- * Calculate an intermediate colour between two colours.
30
- *
31
- * This is done as follows:
32
- * We have two colours: `C1 = (R1,G1,B1)`, and `C2 = (R2,G2,B2)`, and we need to generate a gradient over a string of length `L`.
33
- * For each character at index `i` (from 0 to `L-1`), we need to find an interpolated colour `Ci`.
34
- *
35
- * For that, we can do the following:
36
- * ```txt
37
- * t = i/(L-1)
38
- *
39
- * Ri = R1 + t * (R2 - R1)
40
- * Gi = G1 + t * (G2 - G1)
41
- * Bi = B1 + t * (B2 - B1)
42
- * ```
43
- *
44
- * We then apply `Ci` to each character `i` to get our (mostly) smooth gradient.
45
- *
46
- * @param color1 The starting colour.
47
- * @param color2 The ending colour.
48
- * @param factor How to calculate the colour.
49
- * @returns An RGB value that is the colour between `color1` and `color2` at `factor`.
50
- */
51
- export declare function interpolate(color1: RGB, color2: RGB, factor: number): RGB;
52
- /**
53
- * From [`JSAux`](https://codeberg.org/Genesis_Software/js-aux).
54
- */
55
- export declare function clamp(value: number, min: number, max: number): number;
56
- export type FormatFunctionReturn = string | TemplateStringsArray;
57
- export type FormatFunction = (input: FormatFunctionReturn) => string;
58
- /**
59
- * The object returned by the `createLogger()` method of the `Termark` class.
60
- */
61
- export type LogObject = {
62
- /**
63
- * A generic logging function.
64
- *
65
- * @param message Th message string.
66
- * @param prefix An optional prefix for branding purposes.
67
- */
68
- log(message: string, prefix?: string): void;
69
- /**
70
- * A success logging function. Prints to the same level as `log()`.
71
- *
72
- * @param message Th message string.
73
- * @param prefix An optional prefix for branding purposes.
74
- */
75
- success(message: string, prefix?: string): void;
76
- /**
77
- * An info logging function. Prints to the same level as `log()`.
78
- *
79
- * @param message Th message string.
80
- * @param prefix An optional prefix for branding purposes.
81
- */
82
- info(message: string, prefix?: string): void;
83
- /**
84
- * A warning logging function. Prints to the same level as `error()`.
85
- *
86
- * @param message Th message string.
87
- * @param prefix An optional prefix for branding purposes.
88
- */
89
- warn(message: string, prefix?: string): void;
90
- /**
91
- * An error logging function.
92
- *
93
- * @param message Th message string.
94
- * @param prefix An optional prefix for branding purposes.
95
- */
96
- error(message: string, prefix?: string): void;
97
- };
98
- /**
99
- * Options for the logging methods that aren't `log()` of a custom logger.
100
- */
101
- export interface LoggerLogOptions {
102
- /**
103
- * Customize the prefix of a certain "level" or "type" of log (e.g., `error`).
104
- *
105
- * This is only for semantics.
106
- *
107
- * If left empty, the default prefix is used. If set to `false`, it will be omitted.
108
- *
109
- * The following are the default prefixes:
110
- *
111
- * - `success()`: `[✔]`
112
- * - `info()`: `[i]`,
113
- * - `warn()`: `[!]`,
114
- * - `error()`: `[X]`
115
- */
116
- prefix: string | false;
117
- /**
118
- * An array of styles to apply.
119
- *
120
- * @example [termark.blue, termark.bold]
121
- */
122
- styles: FormatFunction[];
123
- }
124
- /**
125
- * Options to customize a custom logger.
126
- */
127
- export interface LoggerOptions {
128
- /**
129
- * The default styling.
130
- *
131
- * This is what gets applied to the message string when the `log()` method is called.
132
- */
133
- default: FormatFunction[];
134
- /**
135
- * Styling to apply when the `success()` method is called.
136
- *
137
- * Keep in mind that this is only for visuals; there is no "success" log level
138
- * in Node. Therefore, this prints to the same level as `log()` and `info()`.
139
- */
140
- success?: LoggerLogOptions;
141
- /**
142
- * Styling to apply when the `info()` method is called.
143
- *
144
- * This prints to the same level as `log()` and `success()`.
145
- */
146
- info?: LoggerLogOptions;
147
- /**
148
- * Styling to apply when the `warn()` method is called.
149
- *
150
- * This prints to the same level as `error()`.
151
- */
152
- warn?: LoggerLogOptions;
153
- /**
154
- * Styling to apply when the `error()` method is called.`
155
- */
156
- error?: LoggerLogOptions;
157
- }