termark 3.0.0 → 3.0.1

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
@@ -22,7 +22,7 @@ Termark is a basic library to format console output to the standard non-browser
22
22
  - [**FORCE_COLOR**](https://force-color.org/)-friendly
23
23
  - **`truecolor` support** including gradients
24
24
  - **Automatic colour-support detection** with **step-wise fallback** (truecolor → 8-bit → 4-bit → plain text)
25
- - **Extensible** via `extend`; includes **built-in support** for `css-color-names` via `fromColObject`
25
+ - **Extensible** via `extend`; includes built-in support for `css-color-names` via `fromColObject`
26
26
  - **Runtime-agnostic** (currently supported: Node, Bun, Deno)
27
27
 
28
28
  ## Usage
@@ -73,7 +73,9 @@ console.log(fmt.bold.red(`Error: This ${fmt.brightCyan("file")} is corrupted!`))
73
73
 
74
74
  ### Advanced colouring
75
75
 
76
- Termark features methods like `hex` and `rgb` as well as the powerful `gradient` for advanced, versatile colouring. All of these methods feature `bg*` variants.
76
+ Termark features methods like `hex` and `rgb` as well as the powerful `gradient` for advanced, versatile colouring.
77
+ All of these methods feature `bg*` variants, e.g. `bgHex`, which apply colour to the background of the text rather
78
+ than the text itself.
77
79
 
78
80
  ```ts
79
81
  import { fmt } from "termark";
@@ -98,10 +100,15 @@ import { fmt } from "termark";
98
100
  console.log(fmt.fg(57).text("..."));
99
101
  ```
100
102
 
101
- **Note:** The `.text()` method is designed for `hex`, `rgb`, `gradient`, and `fg` when they are the last in the chain or when no other styling is needed. However, technically _all_ styling chains can be terminated by `.text()`, e.g., `fmt.bold.red.text("...")`. `.text()` exists to eliminate the need to write `hex("#338cd1")("Coloured text")`, which is still an option, but it's not elegant.
103
+ **Note:** The `.text()` method is designed for `hex`, `rgb`, `gradient` and `fg` (and their `bg*` counterparts) when
104
+ they are the last in the chain or when no other styling is needed. However, technically _all_ styling chains can be
105
+ terminated by `.text()`, e.g. `fmt.bold.red.text("...")`. `.text()` exists to eliminate the need to write
106
+ `hex("#338cd1")("Coloured text")`, which is still an option, but it's not elegant.
102
107
 
103
108
  ### Layout utilities
104
109
 
110
+ #### `box`
111
+
105
112
  Termark features a powerful `box` method which lets you encase your text in a, well, box.
106
113
 
107
114
  ```ts
@@ -109,14 +116,16 @@ import { fmt, box } from "termark";
109
116
 
110
117
  const myBox = box(fmt.bold.brightGreen("Deployment successful!"), {
111
118
  kind: "rounded",
112
- padding: 2, // Vertical padding only increases every four units.
113
- margin: 3, // Vertical margin only increases every four units.
119
+ padding: 2, // Vertical padding only increases every four units by default.
120
+ margin: 3, // Vertical margin only increases every four units by default.
114
121
  style: fmt.hex("#ffa500"), // Orange border
115
122
  });
116
123
 
117
124
  console.log(myBox);
118
125
  ```
119
126
 
127
+ **Note:** `margin` and `padding` also accept objects to customize top, bottom, left, and right margin/padding.
128
+
120
129
  ### Extensibility
121
130
 
122
131
  **Note:** All extensions of Termark must be called as the last one in a given chain, and a string must be passed.
@@ -126,23 +135,25 @@ console.log(myBox);
126
135
  With the `extend` function, any kind of method can be created as an extension of Termark, such as shortcuts to styles.
127
136
 
128
137
  ```ts
129
- import { extend, ansiUpperCase } from "termark";
138
+ import { extend } from "termark";
130
139
 
131
140
  const myLib = extend((base) => ({
132
141
  // Formatting extensions
133
- shout: (str) => base.red.bold(ansiUpperCase(str)),
142
+ shout: (str) => base.red.bold(str.toUpperCase()),
134
143
  // Colouring extensions
135
144
  orange: (str) => base.hex("#ffa500").text(str),
136
145
  }));
137
146
 
138
- console.log(myLib.shout("This text is in red bold and all-caps"));
147
+ console.log(myLib.shout("This text is bold in red and all-caps"));
139
148
  ```
140
149
 
141
- **Note:** When transforming text such as making it upper-case, use `transformPreserveAnsi` or a function derived from it (such as `ansiUpperCase` in the above example) if you plan to nest styles. Keep in mind that transformations apply to nested styles, too; for `shout` above, all nested text will be upper-case too by default.
150
+ Transformations apply to nested styles, too; for `shout` above, all nested text will be upper-case.
142
151
 
143
152
  #### via `fromColObject`
144
153
 
145
- The `fromColObject` function enables mapping mass colour dictionaries into styling methods. Excellent for packages like [`css-color-names`](https://github.com/bahamas10/css-color-names) or [`color-names`](https://github.com/meodai/color-names) (the latter with some additional work).
154
+ The `fromColObject` function enables mapping mass colour dictionaries into styling methods. Excellent for packages
155
+ like [`css-color-names`](https://github.com/bahamas10/css-color-names) or
156
+ [`color-names`](https://github.com/meodai/color-names) (the latter with some additional work).
146
157
 
147
158
  ```ts
148
159
  import { fromColObject } from "termark";
@@ -162,7 +173,8 @@ const withBg = fromColObject(cssColours, true);
162
173
 
163
174
  ### Hyperlinks
164
175
 
165
- Hyperlinks are achieved by Termark with the help of [OSC 8](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda). Currently, it is non-standard, and may not be supported in every terminal.
176
+ Hyperlinks are achieved by Termark with the help
177
+ of [OSC 8](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda). Currently, it is non-standard, and may not be supported in every terminal.
166
178
 
167
179
  ```ts
168
180
  import { fmt } from "termark";
package/dist/index.cjs CHANGED
@@ -1,4 +1,5 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./__internal/env.cjs`),t=require(`./__internal/styling.cjs`),n=require(`./__internal/impl.cjs`),r=require(`./utilities.cjs`),i=n.createProxy(new n.TermarkImpl);function a(...e){let t={};for(let n of e)Object.assign(t,n(i));return n.createProxy(new n.TermarkImpl,t)}function o(e,n={}){let{kind:i=`sharp`,style:a=e=>e,padding:o=1,margin:s=0}=n,c=t.BOX_BORDERS[i],l=Math.floor(o/4),u=Math.floor(s/4),d=e.split(`
2
- `),f=d.map(e=>r.stripAnsi(e).length),p=Math.max(...f),m=c.tl+c.h.repeat(p+o*2)+c.tr,h=c.bl+c.h.repeat(p+o*2)+c.br,g=` `.repeat(s),_=`
3
- `.repeat(u),v=g+a(m)+g,y=g+a(h)+g,b=g+a(c.v),x=a(c.v)+g;return`${_}${v}\n${d.map(e=>{let t=r.stripAnsi(e),n=e+` `.repeat(p-t.length),i=b+` `.repeat(o*2+t.length)+x,a=l===0?``:`${i}\n`.repeat(l),s=l===0?``:`\n${i}`.repeat(l),c=` `.repeat(o);return`${a}${b}${c}${n}${c}${x}${s}`}).join(`
4
- `)}\n${y}${_}`}function s(e,t){let n={};for(let t in e){let r=e[t];n[t]=i.hex(r)}if(t)for(let t in e){let r=e[t],a=`bg${t.slice(0,1).toUpperCase()}${t.slice(1)}`;n[a]=i.hex(r)}return a(()=>({...n}))}exports.ansiLowerCase=r.ansiLowerCase,exports.ansiUpperCase=r.ansiUpperCase,exports.areColoursSupported=r.areColoursSupported,exports.box=o,exports.extend=a,exports.fmt=i,exports.fromColObject=s,exports.getColourLevel=e.getColourLevel,exports.hasNoColour=e.hasNoColour,exports.stripAnsi=r.stripAnsi,exports.supports=r.supports,exports.supportsAtMost=r.supportsAtMost,exports.transformPreserveAnsi=r.transformPreserveAnsi;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});function e(e){if(typeof globalThis.process?.env==`object`)return globalThis.process.env[e];if(typeof globalThis.Deno?.env?.get==`function`)try{return globalThis.Deno.env.get(e)}catch{return}}function t(){if(globalThis.process?.stdout?.isTTY)return!0;if(typeof globalThis.Deno?.stdout?.isTerminal==`function`)try{return globalThis.Deno.stdout?.isTerminal()}catch{return!1}return!1}function n(){let t=e(`NO_COLOR`)||e(`NODE_DISABLE_COLORS`);return t!==void 0&&t!==``}function r(){if(n())return 0;let r=e(`FORCE_COLOR`);if(r!==void 0)return r===`0`?0:r===`1`?1:r===`2`?2:r===`3`?3:1;if(!t())return e(`CI`)&&(e(`GITHUB_ACTIONS`)||e(`GITLAB_CI`))?1:0;let i=e(`TERM`);if(i===`dumb`)return 0;let a=e(`COLORTERM`);return a===`truecolor`||a===`24bit`||e(`TERM_PROGRAM`)===`vscode`?3:i&&/-256(color)?$/i.test(i)||e(`TERM_PROGRAM`)===`Apple_Terminal`?2:(i&&/color|ansi|cygwin|linux/i.test(i),1)}const i=/^#?([a-f\d]{3}|[a-f\d]{6})$/i;function a(e,t,n){return Math.min(Math.max(e,t),n)}function o(e,t){if(e.length===1)return e[0];let n=t*(e.length-1),r=Math.min(Math.floor(n),e.length-2),i=n-r,a=e[r],o=e[r+1];return[Math.round(a[0]+(o[0]-a[0])*i),Math.round(a[1]+(o[1]-a[1])*i),Math.round(a[2]+(o[2]-a[2])*i)]}function s(e){return e.slice(0,1).toUpperCase()+e.slice(1)}function c(e){let t=i.exec(e);if(!t)return[255,255,255];let n=t[1].replace(/^#/,``),r=3^n.length?n:n.split(``).map(e=>e+e).join(``),a=parseInt(r,16);return[a>>16&255,a>>8&255,a&255]}function l([e,t,n]){return e^t||t^n?16+36*Math.round(e/51)+6*Math.round(t/51)+Math.round(n/51):e<8?16:e>248?231:Math.round((e-8)*24/247)+232}function u(e){if(e<8)return 30+e;if(e<16)return 82+e;let t,n,r;if(e<232){let i=e-16,a=i%36;t=(i/36|0)/5,n=(a/6|0)/5,r=a%6/5}else t=n=r=((e-232)*10+8)/255;let i=Math.max(t,n,r)*2,a=Math.round(t),o=Math.round(n)<<1,s=Math.round(r)<<2,c=2^i?0:60;return 30+(s|o|a)+c}function d(e){return`\x1b[${e}m`}function f(e,t,n){return e.indexOf(n)===-1?`${t}${e}${n}`:`${t}${e.replaceAll(n,n+t)}${n}`}const p={reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],blink:[5,25],inverse:[7,27],overline:[53,55],hidden:[8,28],strike:[9,29],black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],brightBlack:[90,39],grey:[90,39],gray:[90,39],brightRed:[91,39],brightGreen:[92,39],brightYellow:[93,39],brightBlue:[94,39],brightMagenta:[95,39],brightCyan:[96,39],brightWhite:[97,39],bgBrightBlack:[100,49],bgGrey:[100,49],bgGray:[100,49],bgBrightRed:[101,49],bgBrightGreen:[102,49],bgBrightYellow:[103,49],bgBrightBlue:[104,49],bgBrightMagenta:[105,49],bgBrightCyan:[106,49],bgBrightWhite:[107,49]};function m(e,t,n){let r=Array.from(e),i=r.length,a=t?.map(e=>typeof e==`string`?c(e):e),s=n?.map(e=>typeof e==`string`?c(e):e);return r.map((e,t)=>{let n=i>1?t/(i-1):0,r=``,c=``;if(a){let[e,t,i]=o(a,n);r+=`\x1b[38;2;${e};${t};${i}m`,c=`\x1B[39m`+c}if(s){let[e,t,i]=o(s,n);r+=`\x1b[48;2;${e};${t};${i}m`,c=`\x1B[49m`+c}return r+e+c}).join(``)}function h(e){return e.type===`fg`?_(e.code,`fg`):e.type===`bg`?_(e.code,`bg`):e.type===`hex`?y(e.hex,`fg`):e.type===`bgHex`?y(e.hex,`bg`):e.type===`rgb`?v([e.r,e.g,e.b],`fg`):e.type===`bgRgb`?v([e.r,e.g,e.b],`bg`):[``,``]}function g(e,t){let n=t.filter(e=>typeof e!=`string`&&(e.type===`gradient`||e.type===`bgGradient`)),r=n.filter(e=>e.type===`gradient`).at(-1),i=n.filter(e=>e.type===`bgGradient`).at(-1);return t.reduce((t,n)=>{let a=r||i?m(e,r?.colours,i?.colours):t;if(typeof n==`string`)return f(a,d(p[n][0]),d(p[n][1]));{let[e,t]=h(n);return f(a,e,t)}},e)}function _(e,t){if(n()||r()===0)return[``,``];let i=a(e,0,255),o=d(t===`fg`?39:49);if(r()>=2)return[d(t===`fg`?`38;5;${i}`:`48;5;${i}`),o];{let e=u(i);return[d(t===`fg`?e:e+10),o]}}function v(e,t){if(n()||r()===0)return[``,``];let i=e.map(e=>a(e,0,255)),o=d(t===`fg`?39:49);if(r()===3){let e=i.join(`;`);return[d(t===`fg`?`38;2;${e}`:`48;2;${e}`),o]}if(r()===2){let e=l(i);return[d(t===`fg`?`38;5;${e}`:`48;5;${e}`),o]}{let n=u(l(e));return[d(t===`fg`?n:n+10),o]}}function y(e,t){return i.test(e)?v(c(e),t):[``,``]}function b(e,t){let n=`\x1B]8;;`;return`${n}${e}\\${t||e}${n}\\`}function x(e,t){return new Proxy(t=>g(t,e),{get(n,r){return r in p?x([...e,r],t):r===`fg`?n=>x([...e,{type:`fg`,code:n}],t):r===`bg`?n=>x([...e,{type:`bg`,code:n}],t):r===`hex`?n=>x([...e,{type:`hex`,hex:n}],t):r===`bgHex`?n=>x([...e,{type:`bgHex`,hex:n}],t):r===`rgb`?([n,r,i])=>x([...e,{type:`rgb`,r:n,g:r,b:i}],t):r===`bgRgb`?([n,r,i])=>x([...e,{type:`bgRgb`,r:n,g:r,b:i}],t):r===`gradient`?n=>x([...e,{type:`gradient`,colours:n}],t):r===`bgGradient`?n=>x([...e,{type:`bgGradient`,colours:n}],t):r===`link`?(t,n)=>b(t,g(n??t,e)):r===`text`?t=>g(t,e):r in t?n=>g(t[r](n),e):n[r]}})}const S=x([],{});function C(){return r()!==0}function w(e){return r()>=e}function T(e){return r()<=e}function E(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 D=E(e=>e.toUpperCase()),O=E(e=>e.toLowerCase());function k(e){return e.replace(/\u{001B}\[[0-9;]*m/gu,``)}const A={sharp:{tl:`┌`,tr:`┐`,bl:`└`,br:`┘`,h:`─`,v:`│`},rounded:{tl:`╭`,tr:`╮`,bl:`╰`,br:`╯`,h:`─`,v:`│`},double:{tl:`╔`,tr:`╗`,bl:`╚`,br:`╝`,h:`═`,v:`║`},heavy:{tl:`┏`,tr:`┓`,bl:`┗`,br:`┛`,h:`━`,v:`┃`},dashed:{tl:`┌`,tr:`┐`,bl:`└`,br:`┘`,h:`⹀`,v:`╎`},dotted:{tl:`┌`,tr:`┐`,bl:`└`,br:`┘`,h:`╌`,v:`┊`},ascii:{tl:`+`,tr:`+`,bl:`+`,br:`+`,h:`-`,v:`|`}};function j(e,t={}){let{kind:n=`sharp`,style:r=e=>e,padding:i=1,margin:a=0}=t,o=typeof n==`string`?A[n]:n,s=typeof i==`number`?Math.floor(i/4):i.top??0,c=typeof i==`number`?Math.floor(i/4):i.bottom??0,l=typeof a==`number`?Math.floor(a/4):a.top??0,u=typeof a==`number`?Math.floor(a/4):a.bottom??0,d=e.split(`
2
+ `),f=d.map(e=>k(e).length),p=Math.max(...f),m=o.tl+o.h.repeat(p+(typeof i==`number`?i*2:(i.left??0)+(i.right??0)))+o.tr,h=o.bl+o.h.repeat(p+(typeof i==`number`?i*2:(i.left??0)+(i.right??0)))+o.br,g=` `.repeat(typeof a==`number`?a:a.left??0),_=` `.repeat(typeof a==`number`?a:a.right??0),v=`
3
+ `.repeat(l),y=`
4
+ `.repeat(u),b=g+r(m)+_,x=g+r(h)+_,S=g+r(o.v),C=r(o.v)+_;return`${v}${b}\n${d.map(e=>{let t=k(e),n=e+` `.repeat(p-t.length),r=S+` `.repeat((typeof i==`number`?i*2:(i.left??0)+(i.right??0))+t.length)+C,a=i===0?``:`${r}\n`.repeat(s),o=i===0?``:`\n${r}`.repeat(c),l=` `.repeat(typeof i==`number`?i:i.left??0),u=` `.repeat(typeof i==`number`?i:i.right??0);return`${a}${S}${l}${n}${u}${C}${o}`}).join(`
5
+ `)}\n${x}${y}`}function M(e){if(Array.isArray(e)){let t={};for(let n of e)Object.assign(t,n(S));return x([],t)}return x([],e(S))}function N(e,t){let n=Object.entries(e).map(([e,t])=>[e,e=>S.hex(t).text(e)]),r=t?Object.entries(e).map(([e,t])=>[`bg${s(e)}`,e=>S.bgHex(t).text(e)]):null;return M(()=>Object.fromEntries([...n,...r??[]]))}exports.ansiLowerCase=O,exports.ansiUpperCase=D,exports.areColoursSupported=C,exports.box=j,exports.extend=M,exports.fmt=S,exports.termark=S,exports.fromColObject=N,exports.getColorLevel=r,exports.getColourLevel=r,exports.hasNoColor=n,exports.hasNoColour=n,exports.link=b,exports.stripAnsi=k,exports.supports=w,exports.supportsAtMost=T,exports.transformPreserveAnsi=E;
package/dist/index.d.cts CHANGED
@@ -1 +1,492 @@
1
- export type * from './index.d.mts'
1
+ type RGB = [r: number, g: number, b: number];
2
+ /**
3
+ * A number representing the supported colour level.
4
+ *
5
+ * - `0` — No colours, just black-and-white text.
6
+ * - `1` — Basic 4-bit (16) colours.
7
+ * - `2` — 8-bit (256) colours.
8
+ * - `3` — 24-bit (16 mil; `truecolor`) colours.
9
+ */
10
+ type ColourLevel = 0 | 1 | 2 | 3;
11
+ type BaseStyle = "reset" | "bold" | "dim" | "italic" | "underline" | "blink" | "inverse" | "overline" | "hidden" | "strike" | "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "bgBlack" | "bgRed" | "bgGreen" | "bgYellow" | "bgBlue" | "bgMagenta" | "bgCyan" | "bgWhite" | "brightBlack" | "grey" | "gray" | "brightRed" | "brightGreen" | "brightYellow" | "brightBlue" | "brightMagenta" | "brightCyan" | "brightWhite" | "bgBrightBlack" | "bgGrey" | "bgGray" | "bgBrightRed" | "bgBrightGreen" | "bgBrightYellow" | "bgBrightBlue" | "bgBrightMagenta" | "bgBrightCyan" | "bgBrightWhite";
12
+ type GradientStyle = {
13
+ type: "gradient";
14
+ colours: string[] | RGB[];
15
+ } | {
16
+ type: "bgGradient";
17
+ colours: string[] | RGB[];
18
+ };
19
+ type DynamicStyle = {
20
+ type: "fg";
21
+ code: number;
22
+ } | {
23
+ type: "bg";
24
+ code: number;
25
+ } | {
26
+ type: "hex";
27
+ hex: string;
28
+ } | {
29
+ type: "bgHex";
30
+ hex: string;
31
+ } | {
32
+ type: "rgb";
33
+ r: number;
34
+ b: number;
35
+ g: number;
36
+ } | {
37
+ type: "bgRgb";
38
+ r: number;
39
+ b: number;
40
+ g: number;
41
+ } | GradientStyle;
42
+ type StyleFn = (str: string) => string;
43
+ type AnyStyle = BaseStyle | DynamicStyle;
44
+ type StyleData = [open: string, close: string];
45
+ type Termark<ExtKey extends PropertyKey = string> = { [K in BaseStyle]: Termark<ExtKey>; } & { [K in ExtKey]: StyleFn; } & {
46
+ /**
47
+ * Apply a custom colour to the text using an ANSI colour code.
48
+ *
49
+ * @param code An ANSI colour code (0–255)
50
+ */
51
+ fg(code: number): Termark<ExtKey>;
52
+ /**
53
+ * Apply a custom background colour to the text using an ANSI colour code.
54
+ *
55
+ * @param code An ANSI colour code (0–255)
56
+ */
57
+ bg(code: number): Termark<ExtKey>;
58
+ /**
59
+ * Apply a custom colour to the text using a hex colour code.
60
+ *
61
+ * @param hex A hex colour code. The preceding `#` symbol is optional.
62
+ */
63
+ hex(hex: string): Termark<ExtKey>;
64
+ /**
65
+ * Apply a custom background colour to the text using a hex colour code.
66
+ *
67
+ * @param hex A hex colour code. The preceding `#` symbol is optional.
68
+ */
69
+ bgHex(hex: string): Termark<ExtKey>;
70
+ /**
71
+ * Apply a custom colour to the text using an RGB tuple.
72
+ *
73
+ * @param col An RGB tuple.
74
+ */
75
+ rgb(col: RGB): Termark<ExtKey>;
76
+ /**
77
+ * Apply a custom background colour to the text using an RGB tuple.
78
+ *
79
+ * @param col An RGB tuple.
80
+ */
81
+ bgRgb(col: RGB): Termark<ExtKey>;
82
+ /**
83
+ * Set the colour of the text to be a gradient.
84
+ *
85
+ * @param cols An array of colours. Each can be either a hex colour code (`#` optional) or an RGB tuple.
86
+ */
87
+ gradient(cols: Array<string | RGB>): Termark<ExtKey>;
88
+ /**
89
+ * Set the background colour of the text to be a gradient.
90
+ *
91
+ * @param cols An array of colours. Each can be either a hex colour code (`#` optional) or an RGB tuple.
92
+ */
93
+ bgGradient(cols: Array<string | RGB>): Termark<ExtKey>;
94
+ /**
95
+ * Construct an OSC 8 hyperlink.
96
+ *
97
+ * **Note:** Whether and how interactive the resulting hyperlink is entirely depends on the current terminal
98
+ * environment, not all support OSC 8 hyperlinks, especially not ones with custom display text. For a list of which
99
+ * terminal emulators support OSC 8 hyperlinks, see [here](https://github.com/Alhadis/OSC8-Adoption).
100
+ *
101
+ * @example
102
+ * ```ts
103
+ * import { fmt } from "termark";
104
+ *
105
+ * const l = fmt.link("https://example.com", "Website");
106
+ * ```
107
+ *
108
+ * @example Styling the link
109
+ * ```ts
110
+ * import { fmt } from "termark";
111
+ *
112
+ * const l = fmt.green.bold.link("https://example.com", "Website");
113
+ * ```
114
+ *
115
+ * @param url The URL the hyperlink points to. Required.
116
+ * @param text Text to display instead of the URL. Optional; if omitted, `url` is displayed instead.
117
+ */
118
+ link(url: string, text?: string): string;
119
+ /**
120
+ * Terminate a style chain and apply all collected styles to `input`.
121
+ *
122
+ * Can be called by any
123
+ *
124
+ * @param input A string to apply styles to.
125
+ */
126
+ text(input: string): string;
127
+ } & ((input: string) => string);
128
+ /**
129
+ * Built-in box border kinds.
130
+ */
131
+ type BoxBorderKind = "sharp" | "rounded" | "double" | "heavy" | "dashed" | "dotted" | "ascii";
132
+ /**
133
+ * Type representing an object containing the characters that make up a box border.
134
+ */
135
+ interface BoxBorder {
136
+ /**
137
+ * Top left corner.
138
+ */
139
+ tl: string;
140
+ /**
141
+ * Top right corner.
142
+ */
143
+ tr: string;
144
+ /**
145
+ * Bottom left corner.
146
+ */
147
+ bl: string;
148
+ /**
149
+ * Bottom right corner.
150
+ */
151
+ br: string;
152
+ /**
153
+ * Top/bottom.
154
+ */
155
+ h: string;
156
+ /**
157
+ * Left/right.
158
+ */
159
+ v: string;
160
+ }
161
+ /**
162
+ * Custom box spacing (padding/margin). Values are in characters.
163
+ */
164
+ interface BoxSpacing {
165
+ /**
166
+ * @default 0
167
+ */
168
+ top?: number;
169
+ /**
170
+ * @default 0
171
+ */
172
+ bottom?: number;
173
+ /**
174
+ * @default 0
175
+ */
176
+ left?: number;
177
+ /**
178
+ * @default 0
179
+ */
180
+ right?: number;
181
+ }
182
+ interface BoxOptions {
183
+ /**
184
+ * What the border of the box should be made of.
185
+ *
186
+ * This can be a string representing a built-in border style, or an object for custom styling.
187
+ *
188
+ * @default "sharp"
189
+ */
190
+ kind?: BoxBorderKind | BoxBorder;
191
+ /**
192
+ * Styling to apply to the border.
193
+ *
194
+ * @example fmt.bold.blue
195
+ *
196
+ * @default (str) => str
197
+ */
198
+ style?: (str: string) => string;
199
+ /**
200
+ * Spacing (in characters) between the border and the content. Can be a number or an object to customize padding.
201
+ *
202
+ * When a number is provided, the top-bottom padding will always be a quarter of left-right padding.
203
+ *
204
+ * @default 1
205
+ */
206
+ padding?: number | BoxSpacing;
207
+ /**
208
+ * Spacing (in characters) around the outside of the box. Can be a number or an object to customize margin.
209
+ *
210
+ * When a number is provided, the top-bottom margin will always be a quarter of left-right margin.
211
+ *
212
+ * @default 0
213
+ */
214
+ margin?: number | BoxSpacing;
215
+ }
216
+ type ColourObject = Record<string, string>;
217
+ type FromColObjectReturn<R extends ColourObject, GenBg extends boolean | undefined> = GenBg extends true ? keyof R | `bg${Capitalize<keyof R & string>}` : keyof R;
218
+ /**
219
+ * Check whether `NO_COLOR` is an existing environment variable with any value that is not an empty string, thereby
220
+ * disabling colours from being printed.
221
+ *
222
+ * This also checks the existence of the `NODE_DISABLE_COLORS` environment variable, behaving the same way if it
223
+ * exists and not an empty string.
224
+ *
225
+ * @see https://no-color.org
226
+ */
227
+ export declare function hasNoColour(): boolean;
228
+ /**
229
+ * Get the colour level of the terminal environment.
230
+ *
231
+ * @returns {@linkcode ColourLevel}
232
+ */
233
+ export declare function getColourLevel(): ColourLevel;
234
+ /**
235
+ * Style some text for terminal output.
236
+ *
237
+ * @example
238
+ * ```ts
239
+ * import { fmt } from "termark";
240
+ *
241
+ * const styled = fmt.bold.green.italic("Text");
242
+ *
243
+ * console.log(styled);
244
+ * // => "Text" printed in bold, green (if colours are supported/enabled), and italic.
245
+ * ```
246
+ *
247
+ * Each member of the chain can be called by passing a string, or can be accessed to apply further styling.
248
+ * Use `.text()` to finally terminate the styling.
249
+ *
250
+ * @example Terminating the chain with `.text()`
251
+ * ```ts
252
+ * import { fmt } from "termark";
253
+ *
254
+ * const styled = fmt.underline.bgBlue.black.text("Text");
255
+ *
256
+ * console.log(styled);
257
+ * // => "Text" printed in black with a blue background, and underlined.
258
+ * ```
259
+ *
260
+ * `.text()` is primarily for methods, such as `hex`, `rgb`, or `gradient`, that would be inconvenient to use without
261
+ * it.
262
+ *
263
+ * @example `.text()` on `hex` vs. not using `.text()`
264
+ * ```ts
265
+ * import { fmt } from "termark";
266
+ *
267
+ * const custom = fmt.hex("#ffa500").text("orange");
268
+ *
269
+ * // Not using `.text()` is also possible, but less elegant:
270
+ *
271
+ * const withoutTextCall = fmt.hex("#80b3ff")("Text");
272
+ * ```
273
+ */
274
+ export declare const fmt: Termark;
275
+ /**
276
+ * Create a box around some text.
277
+ *
278
+ * @example
279
+ * ```ts
280
+ * import { box } from "termark";
281
+ *
282
+ * const boxed = box("This text is boxed in.");
283
+ * ```
284
+ *
285
+ * Use `\n` to split the text along multiple lines.
286
+ *
287
+ * ---
288
+ *
289
+ * The inner text of the box can be styled with {@linkcode fmt} like regular terminal output.
290
+ *
291
+ * @example Styling inner text
292
+ * ```ts
293
+ * import { box, fmt } from "termark";
294
+ *
295
+ * const boxed = box(fmt.italic.blue("..."));
296
+ * ```
297
+ *
298
+ * ---
299
+ *
300
+ * The look of the box can be customized too, using the `options` parameter.
301
+ *
302
+ * @example Styling box
303
+ * ```ts
304
+ * import { box, fmt } from "termark";
305
+ *
306
+ * const boxed = box("...", {
307
+ * kind: "rounded", // can be an object with custom border characters
308
+ * style: fmt.bold.blue,
309
+ * padding: 2, // can be an object with custom spacing
310
+ * margin: 2, // can be an object with custom spacing
311
+ * });
312
+ * ```
313
+ *
314
+ * @param text The text within the box.
315
+ * @param options Configuration options.
316
+ * @returns A string that is the box.
317
+ */
318
+ export declare function box(text: string, options?: BoxOptions): string;
319
+ /**
320
+ * Extend the functionality of Termark with custom methods.
321
+ *
322
+ * **Note:** Methods created this way can only be used as the last item in the chain.
323
+ *
324
+ * @example
325
+ * ```ts
326
+ * import { extend } from "termark";
327
+ *
328
+ * const extended = extend((base) => ({
329
+ * shout: (str) => base.red.bold(str.toUpperCase()),
330
+ * orange: (str) => base.hex("#ffa500").text(str),
331
+ * }));
332
+ *
333
+ * console.log(
334
+ * extended.underline.shout("big red text"),
335
+ * extended.italic.orange("orange text"),
336
+ * );
337
+ * ```
338
+ *
339
+ * When not using arrow functions, it's possible to use an extension method within another extension method:
340
+ *
341
+ * @example Deriving methods from each other
342
+ * ```ts
343
+ * import { extend } from "termark";
344
+ *
345
+ * const extended = extend((base) => ({
346
+ * orange(str) {
347
+ * return base.hex("#ffa500").text(str);
348
+ * },
349
+ * uppercaseOrange(str) {
350
+ * return this.orange(str.toUpperCase());
351
+ * },
352
+ * }));
353
+ * ```
354
+ *
355
+ * @param fn A function that returns an object containing custom methods. This function has access to a
356
+ * {@linkcode Termark} instance so it does not need to be imported separately.
357
+ */
358
+ export declare function extend<E extends Record<PropertyKey, StyleFn>>(fn: (base: Termark) => E): Termark<keyof E>;
359
+ /**
360
+ * Generate colour-styling from an object literal. This primarily exists for use with
361
+ * [`css-color-names`](https://github.com/bahamas10/css-color-names).
362
+ *
363
+ * Because this function uses {@linkcode extend} under the hood, colour methods created this way must be called as the
364
+ * last one in the chain.
365
+ *
366
+ * @example Using `css-color-names`
367
+ * ```ts
368
+ * import cssColours from "css-color-names";
369
+ * import { fromColObject } from "termark";
370
+ *
371
+ * const css = fromColObject(cssColours);
372
+ *
373
+ * console.log(
374
+ * css.lemonchiffron("This text uses a CSS colour!"),
375
+ * css.bold.aliceblue("Works with other styles")
376
+ * );
377
+ * ```
378
+ *
379
+ * @example Enabling background colours
380
+ * ```ts
381
+ * import cssColours from "css-color-names";
382
+ * import { fromColObject } from "termark";
383
+ *
384
+ * const cssWithBg = fromColObject(cssColours, true);
385
+ * ```
386
+ *
387
+ * @example Using [`color-names`](https://github.com/meodai/color-names)
388
+ * ```ts
389
+ * import { colornames } from "color-name-list";
390
+ * import { fromColObject } from "termark";
391
+ *
392
+ * const mapped = colornames.reduce((acc, { name, hex }) => {
393
+ * acc[name] = hex;
394
+ * return acc;
395
+ * }, {});
396
+ *
397
+ * const colours = fromColObject(mapped);
398
+ *
399
+ * console.log(
400
+ * colours["100 Mph"]("This colour is from color-names"),
401
+ * colours.italic.Alaska("...")
402
+ * );
403
+ * ```
404
+ *
405
+ * @param obj An object whose keys are colour names (which will be used as the method name) and whose values are
406
+ * hex colour codes.
407
+ * @param generateBg Whether to generate background styling for all supplied colours. These will have the format
408
+ * `bgColourName` where `ColourName` is the original name of the colour, capitalized. This name is not formatted,
409
+ * so a name like `100 Mph` will retain its spaces.
410
+ */
411
+ export declare function fromColObject<R extends ColourObject, GenBg extends boolean | undefined = undefined>(obj: R, genBg?: GenBg): Termark<FromColObjectReturn<R, GenBg>>;
412
+ /**
413
+ * Construct an OSC 8 hyperlink.
414
+ *
415
+ * **Note:** Whether and how interactive the resulting hyperlink is entirely depends on the current terminal
416
+ * environment, not all support OSC 8 hyperlinks, especially not ones with custom display text. For a list of which
417
+ * terminal emulators support OSC 8 hyperlinks, see [here](https://github.com/Alhadis/OSC8-Adoption).
418
+ *
419
+ * @example
420
+ * ```ts
421
+ * import { link } from "termark";
422
+ *
423
+ * const l = link("https://example.com", "Website");
424
+ * ```
425
+ *
426
+ * @example Styled text
427
+ * ```ts
428
+ * import { link, fmt } from "termark";
429
+ *
430
+ * const l = link("https://example.com", fmt.italic.green("Website"));
431
+ * ```
432
+ *
433
+ * @param url The URL the hyperlink points to. Required.
434
+ * @param text Text to display instead of the URL. Optional; if omitted, `url` is displayed instead.
435
+ */
436
+ export declare function link(url: string, text?: string): string;
437
+ /**
438
+ * Check whether colours are supported in a given terminal environment.
439
+ *
440
+ * Use {@linkcode hasNoColour} for checking whether terminals that *could* support colour don't do so.
441
+ */
442
+ export declare function areColoursSupported(): boolean;
443
+ /**
444
+ * Check whether a terminal environment supports at least some level of colours.
445
+ *
446
+ * @param level A colour level.
447
+ */
448
+ export declare function supports(level: ColourLevel): boolean;
449
+ /**
450
+ * Check whether a terminal environment supports at most a given colour level.
451
+ *
452
+ * @param level A colour level.
453
+ */
454
+ export declare function supportsAtMost(level: ColourLevel): boolean;
455
+ /**
456
+ * Modify the plain text part of a string with ANSI escape sequences.
457
+ *
458
+ * @example Creating a `toUpperCase` method for ANSI strings
459
+ * ```ts
460
+ * import { transformPreserveAnsi } from "termark";
461
+ *
462
+ * const toUpperCase = transformPreserveAnsi((str) => str.toUpperCase());
463
+ * ```
464
+ *
465
+ * @param fn A function that transforms some string.
466
+ *
467
+ * @deprecated Function is no longer necessary.
468
+ */
469
+ export declare function transformPreserveAnsi(fn: (plain: string) => string): (str: string) => string;
470
+ /**
471
+ * Make some string upper-case while preserving ANSI escape sequences as-is.
472
+ *
473
+ * @str The string to transform.
474
+ *
475
+ * @deprecated Function is no longer necessary.
476
+ */
477
+ export declare const ansiUpperCase: (str: string) => string;
478
+ /**
479
+ * Make some string lower-case while preserving ANSI escape sequences as-is.
480
+ *
481
+ * @param str The string to transform.
482
+ *
483
+ * @deprecated Function is no longer necessary.
484
+ */
485
+ export declare const ansiLowerCase: (str: string) => string;
486
+ /**
487
+ * Remove ANSI escape sequences from some text.
488
+ *
489
+ * @param input The input to strip of ANSI escape sequences.
490
+ */
491
+ export declare function stripAnsi(input: string): string;
492
+ export { type AnyStyle, type BaseStyle, type BoxBorder, type BoxBorderKind, type BoxOptions, type BoxSpacing, type ColourLevel, type ColourObject, type DynamicStyle, type FromColObjectReturn, type GradientStyle, type RGB, type StyleData, type StyleFn, type Termark, fmt as termark, getColourLevel as getColorLevel, hasNoColour as hasNoColor };