console-toolkit 1.2.9 → 1.2.11

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.
Files changed (158) hide show
  1. package/README.md +74 -29
  2. package/llms-full.txt +429 -0
  3. package/llms.txt +80 -0
  4. package/package.json +29 -7
  5. package/src/alphanumeric/arrows.d.ts +48 -0
  6. package/src/alphanumeric/arrows.js +23 -0
  7. package/src/alphanumeric/fractions.d.ts +65 -0
  8. package/src/alphanumeric/fractions.js +49 -0
  9. package/src/alphanumeric/number-formatters.d.ts +91 -0
  10. package/src/alphanumeric/number-formatters.js +45 -1
  11. package/src/alphanumeric/roman.d.ts +15 -0
  12. package/src/alphanumeric/roman.js +12 -0
  13. package/src/alphanumeric/unicode-cultural-numbers.d.ts +65 -0
  14. package/src/alphanumeric/unicode-cultural-numbers.js +1 -0
  15. package/src/alphanumeric/unicode-letters.d.ts +32 -0
  16. package/src/alphanumeric/unicode-letters.js +8 -0
  17. package/src/alphanumeric/unicode-numbers.d.ts +44 -0
  18. package/src/alphanumeric/unicode-numbers.js +21 -0
  19. package/src/alphanumeric/utils.d.ts +45 -0
  20. package/src/alphanumeric/utils.js +26 -0
  21. package/src/ansi/csi.d.ts +141 -0
  22. package/src/ansi/csi.js +51 -2
  23. package/src/ansi/index.d.ts +26 -0
  24. package/src/ansi/sgr-constants.d.ts +173 -0
  25. package/src/ansi/sgr-state.d.ts +91 -0
  26. package/src/ansi/sgr-state.js +45 -0
  27. package/src/ansi/sgr.d.ts +587 -0
  28. package/src/ansi/sgr.js +426 -6
  29. package/src/box.d.ts +160 -0
  30. package/src/box.js +113 -12
  31. package/src/charts/bars/block-frac-grouped.d.ts +12 -0
  32. package/src/charts/bars/block-frac-grouped.js +6 -0
  33. package/src/charts/bars/block-frac.d.ts +34 -0
  34. package/src/charts/bars/block-frac.js +13 -0
  35. package/src/charts/bars/block-grouped.d.ts +12 -0
  36. package/src/charts/bars/block-grouped.js +6 -0
  37. package/src/charts/bars/block.d.ts +43 -0
  38. package/src/charts/bars/block.js +13 -0
  39. package/src/charts/bars/draw-grouped.d.ts +46 -0
  40. package/src/charts/bars/draw-grouped.js +4 -0
  41. package/src/charts/bars/draw-stacked.d.ts +52 -0
  42. package/src/charts/bars/draw-stacked.js +4 -0
  43. package/src/charts/bars/frac-grouped.d.ts +32 -0
  44. package/src/charts/bars/frac-grouped.js +13 -0
  45. package/src/charts/bars/plain-grouped.d.ts +12 -0
  46. package/src/charts/bars/plain-grouped.js +6 -0
  47. package/src/charts/bars/plain.d.ts +85 -0
  48. package/src/charts/bars/plain.js +27 -0
  49. package/src/charts/columns/block-frac-grouped.d.ts +12 -0
  50. package/src/charts/columns/block-frac-grouped.js +6 -0
  51. package/src/charts/columns/block-frac.d.ts +39 -0
  52. package/src/charts/columns/block-frac.js +13 -0
  53. package/src/charts/columns/block-grouped.d.ts +12 -0
  54. package/src/charts/columns/block-grouped.js +6 -0
  55. package/src/charts/columns/block.d.ts +43 -0
  56. package/src/charts/columns/block.js +13 -0
  57. package/src/charts/columns/draw-grouped.d.ts +46 -0
  58. package/src/charts/columns/draw-grouped.js +4 -0
  59. package/src/charts/columns/draw-stacked.d.ts +44 -0
  60. package/src/charts/columns/draw-stacked.js +4 -0
  61. package/src/charts/columns/frac-grouped.d.ts +37 -0
  62. package/src/charts/columns/frac-grouped.js +13 -0
  63. package/src/charts/columns/plain-grouped.d.ts +12 -0
  64. package/src/charts/columns/plain-grouped.js +6 -0
  65. package/src/charts/columns/plain.d.ts +32 -0
  66. package/src/charts/columns/plain.js +13 -0
  67. package/src/charts/themes/default.d.ts +6 -0
  68. package/src/charts/themes/default.js +1 -0
  69. package/src/charts/themes/rainbow-reversed.d.ts +6 -0
  70. package/src/charts/themes/rainbow-reversed.js +2 -1
  71. package/src/charts/themes/rainbow.d.ts +6 -0
  72. package/src/charts/themes/rainbow.js +1 -0
  73. package/src/charts/utils.d.ts +79 -0
  74. package/src/charts/utils.js +32 -4
  75. package/src/draw-block-frac.d.ts +16 -0
  76. package/src/draw-block-frac.js +14 -0
  77. package/src/draw-block.d.ts +43 -0
  78. package/src/draw-block.js +25 -1
  79. package/src/meta.d.ts +84 -0
  80. package/src/meta.js +64 -0
  81. package/src/output/show.d.ts +55 -0
  82. package/src/output/show.js +28 -0
  83. package/src/output/updater.d.ts +114 -0
  84. package/src/output/updater.js +58 -4
  85. package/src/output/writer.d.ts +87 -0
  86. package/src/output/writer.js +57 -5
  87. package/src/panel.d.ts +402 -0
  88. package/src/panel.js +219 -5
  89. package/src/plot/bitmap.d.ts +80 -0
  90. package/src/plot/bitmap.js +33 -4
  91. package/src/plot/draw-line.d.ts +13 -0
  92. package/src/plot/draw-line.js +8 -0
  93. package/src/plot/draw-rect.d.ts +13 -0
  94. package/src/plot/draw-rect.js +38 -30
  95. package/src/plot/index.d.ts +39 -0
  96. package/src/plot/index.js +22 -0
  97. package/src/plot/to-quads.d.ts +10 -0
  98. package/src/plot/to-quads.js +5 -0
  99. package/src/spinner/index.d.ts +4 -0
  100. package/src/spinner/index.js +0 -2
  101. package/src/spinner/spin.d.ts +13 -0
  102. package/src/spinner/spin.js +13 -2
  103. package/src/spinner/spinner.d.ts +69 -0
  104. package/src/spinner/spinner.js +30 -2
  105. package/src/spinner/spinners.d.ts +34 -0
  106. package/src/spinner/spinners.js +23 -9
  107. package/src/strings/clip.d.ts +21 -0
  108. package/src/strings/clip.js +10 -0
  109. package/src/strings/parse.d.ts +23 -0
  110. package/src/strings/parse.js +7 -0
  111. package/src/strings/split.d.ts +38 -0
  112. package/src/strings/split.js +15 -0
  113. package/src/strings.d.ts +44 -0
  114. package/src/strings.js +34 -4
  115. package/src/style.d.ts +462 -0
  116. package/src/style.js +58 -4
  117. package/src/symbols.d.ts +167 -0
  118. package/src/symbols.js +91 -7
  119. package/src/table/draw-borders.d.ts +38 -0
  120. package/src/table/draw-borders.js +10 -2
  121. package/src/table/index.d.ts +8 -0
  122. package/src/table/index.js +1 -0
  123. package/src/table/table.d.ts +239 -0
  124. package/src/table/table.js +59 -1
  125. package/src/themes/blocks/unicode-half.d.ts +6 -0
  126. package/src/themes/blocks/unicode-half.js +1 -0
  127. package/src/themes/blocks/unicode-thin.d.ts +6 -0
  128. package/src/themes/blocks/unicode-thin.js +1 -0
  129. package/src/themes/lines/ascii-compact.d.ts +6 -0
  130. package/src/themes/lines/ascii-compact.js +1 -0
  131. package/src/themes/lines/ascii-dots.d.ts +6 -0
  132. package/src/themes/lines/ascii-dots.js +1 -0
  133. package/src/themes/lines/ascii-girder.d.ts +6 -0
  134. package/src/themes/lines/ascii-girder.js +1 -0
  135. package/src/themes/lines/ascii-github.d.ts +6 -0
  136. package/src/themes/lines/ascii-github.js +1 -0
  137. package/src/themes/lines/ascii-reddit.d.ts +6 -0
  138. package/src/themes/lines/ascii-reddit.js +1 -0
  139. package/src/themes/lines/ascii-rounded.d.ts +6 -0
  140. package/src/themes/lines/ascii-rounded.js +1 -0
  141. package/src/themes/lines/ascii.d.ts +6 -0
  142. package/src/themes/lines/ascii.js +1 -0
  143. package/src/themes/lines/unicode-bold.d.ts +6 -0
  144. package/src/themes/lines/unicode-bold.js +1 -0
  145. package/src/themes/lines/unicode-rounded.d.ts +6 -0
  146. package/src/themes/lines/unicode-rounded.js +1 -0
  147. package/src/themes/lines/unicode.d.ts +6 -0
  148. package/src/themes/lines/unicode.js +1 -0
  149. package/src/themes/utils.d.ts +33 -0
  150. package/src/themes/utils.js +7 -0
  151. package/src/turtle/draw-line-art.d.ts +19 -0
  152. package/src/turtle/draw-line-art.js +7 -0
  153. package/src/turtle/draw-unicode.d.ts +19 -0
  154. package/src/turtle/draw-unicode.js +8 -0
  155. package/src/turtle/index.d.ts +21 -0
  156. package/src/turtle/index.js +8 -0
  157. package/src/turtle/turtle.d.ts +269 -0
  158. package/src/turtle/turtle.js +124 -4
@@ -0,0 +1,91 @@
1
+ /** SGR (Select Graphics Rendition) state object. Properties are `null` for reset, a command string when set, or `undefined` when unspecified. */
2
+ export interface SgrState {
3
+ /** Bold attribute command or `null` to reset. */
4
+ bold?: string | null;
5
+ /** Dim/faint attribute command or `null` to reset. */
6
+ dim?: string | null;
7
+ /** Italic attribute command or `null` to reset. */
8
+ italic?: string | null;
9
+ /** Underline attribute command or `null` to reset. */
10
+ underline?: string | null;
11
+ /** Blink attribute command or `null` to reset. */
12
+ blink?: string | null;
13
+ /** Inverse/reverse attribute command or `null` to reset. */
14
+ inverse?: string | null;
15
+ /** Hidden attribute command or `null` to reset. */
16
+ hidden?: string | null;
17
+ /** Strikethrough attribute command or `null` to reset. */
18
+ strikethrough?: string | null;
19
+ /** Overline attribute command or `null` to reset. */
20
+ overline?: string | null;
21
+ /** Foreground color command(s) or `null` to reset. */
22
+ foreground?: string | string[] | null;
23
+ /** Background color command(s) or `null` to reset. */
24
+ background?: string | string[] | null;
25
+ /** Decoration (underline) color command(s) or `null` to reset. */
26
+ decoration?: string | string[] | null;
27
+ /** Font command or `null` to reset. */
28
+ font?: string | null;
29
+ }
30
+
31
+ /** The fully reset SGR state with all properties set to `null`. */
32
+ export const RESET_STATE: SgrState;
33
+
34
+ /** Extracts the cumulative SGR state from a string by parsing all SGR sequences.
35
+ * @param s - The string to parse for SGR sequences.
36
+ * @param initState - Initial state to build upon.
37
+ * @returns The resulting SGR state.
38
+ */
39
+ export function extractState(s: string, initState?: SgrState): SgrState;
40
+ /** Converts a value to an SGR state object.
41
+ * @param value - An SgrState object, a string containing SGR sequences, an object with `getState()`, or `null` for reset.
42
+ * @returns The resulting SGR state.
43
+ */
44
+ export function toState(value: SgrState | string | {getState(): SgrState} | null): SgrState;
45
+
46
+ /** Combines multiple SGR states, with later states overriding earlier ones.
47
+ * @param states - States to combine (SgrState objects, strings, or nulls).
48
+ * @returns The combined state.
49
+ */
50
+ export function combineStates(...states: (SgrState | string | {getState(): SgrState} | null)[]): SgrState;
51
+ /** Converts an array of SGR command strings into an SGR state object.
52
+ * @param commands - Array of SGR command strings.
53
+ * @returns The resulting state.
54
+ */
55
+ export function commandsToState(commands: string[]): SgrState;
56
+ /** Adds SGR commands to an existing state.
57
+ * @param state - The base state.
58
+ * @param commands - SGR command strings to add.
59
+ * @returns The updated state.
60
+ */
61
+ export function addCommandsToState(state: SgrState, commands: string[]): SgrState;
62
+
63
+ /** Converts an SGR state to an array of SGR command strings.
64
+ * @param state - The SGR state to convert.
65
+ * @returns Array of SGR command strings.
66
+ */
67
+ export function stateToCommands(state: SgrState): string[];
68
+ /** Computes the minimal SGR commands needed to transition from one state to another.
69
+ * @param prev - The previous SGR state.
70
+ * @param next - The target SGR state.
71
+ * @returns Array of SGR command strings for the transition.
72
+ */
73
+ export function stateTransition(prev: SgrState, next: SgrState): string[];
74
+ /** Computes the minimal SGR commands to reverse a state transition.
75
+ * @param prev - The previous SGR state.
76
+ * @param next - The target SGR state.
77
+ * @returns Array of SGR command strings for the reverse transition.
78
+ */
79
+ export function stateReverseTransition(prev: SgrState, next: SgrState): string[];
80
+
81
+ /** Converts an array of SGR commands to an escape sequence string.
82
+ * @param commands - Array of SGR command strings, or null/undefined.
83
+ * @returns The SGR escape sequence string.
84
+ */
85
+ export function stringifyCommands(commands: string[] | undefined | null): string;
86
+ /** Optimizes SGR sequences in a string by computing minimal state transitions.
87
+ * @param s - The string containing SGR sequences.
88
+ * @param initState - Initial SGR state.
89
+ * @returns The optimized string.
90
+ */
91
+ export function optimize(s: string, initState?: SgrState): string;
@@ -10,6 +10,9 @@ import {
10
10
  matchSgr
11
11
  } from './sgr.js';
12
12
 
13
+ /** The fully reset SGR state with all properties set to `null`.
14
+ * @type {object}
15
+ */
13
16
  export const RESET_STATE = {
14
17
  bold: null,
15
18
  dim: null,
@@ -30,6 +33,11 @@ const defaultState = Symbol('defaultState');
30
33
 
31
34
  let toState;
32
35
 
36
+ /** Extracts the cumulative SGR state from a string by parsing all SGR sequences.
37
+ * @param {string} s - The string to parse.
38
+ * @param {object} [initState] - Initial state to build upon.
39
+ * @returns {object} The resulting SGR state.
40
+ */
33
41
  export const extractState = (s, initState = defaultState) => {
34
42
  let state = toState(initState);
35
43
  matchSgr.lastIndex = 0;
@@ -63,6 +71,10 @@ const getStateResets = state => {
63
71
  return resetCount;
64
72
  };
65
73
 
74
+ /** Combines multiple SGR states, with later states overriding earlier ones.
75
+ * @param {...(object|string)} states - States to combine.
76
+ * @returns {object} The combined state.
77
+ */
66
78
  export const combineStates = (...states) => {
67
79
  let state = {};
68
80
  for (const s of states) {
@@ -74,6 +86,10 @@ export const combineStates = (...states) => {
74
86
  return state;
75
87
  };
76
88
 
89
+ /** Converts an array of SGR command strings into an SGR state object.
90
+ * @param {string[]} commands - Array of SGR command strings.
91
+ * @returns {object} The resulting state.
92
+ */
77
93
  export const commandsToState = commands => {
78
94
  let state = {};
79
95
  for (let i = 0; i < commands.length; ++i) {
@@ -191,6 +207,11 @@ export const commandsToState = commands => {
191
207
  return state;
192
208
  };
193
209
 
210
+ /** Adds SGR commands to an existing state.
211
+ * @param {object} state - The current state.
212
+ * @param {string[]} commands - Commands to add.
213
+ * @returns {object} The updated state.
214
+ */
194
215
  export const addCommandsToState = (state, commands) => combineStates(state, commandsToState(commands));
195
216
 
196
217
  const equalColors = (a, b) => {
@@ -217,6 +238,10 @@ const resetColorProperties = {
217
238
 
218
239
  const chainedStates = {bold: 1, dim: 1};
219
240
 
241
+ /** Converts an SGR state to an array of SGR command strings.
242
+ * @param {object|string} state - The state to convert.
243
+ * @returns {string[]} The command strings.
244
+ */
220
245
  export const stateToCommands = state => {
221
246
  state = toState(state);
222
247
  const commands = [];
@@ -257,6 +282,11 @@ export const stateToCommands = state => {
257
282
  return resetCount === TOTAL_RESETS ? [''] : commands;
258
283
  };
259
284
 
285
+ /** Computes the minimal SGR commands needed to transition from one state to another.
286
+ * @param {object|string} prev - The previous state.
287
+ * @param {object|string} next - The next state.
288
+ * @returns {string[]} The transition commands.
289
+ */
260
290
  export const stateTransition = (prev, next) => {
261
291
  prev = toState(prev);
262
292
  next = toState(next);
@@ -318,6 +348,11 @@ export const stateTransition = (prev, next) => {
318
348
  return commands;
319
349
  };
320
350
 
351
+ /** Computes the minimal SGR commands to reverse a state transition (from next back to prev).
352
+ * @param {object|string} prev - The state to restore.
353
+ * @param {object|string} next - The current state.
354
+ * @returns {string[]} The reverse transition commands.
355
+ */
321
356
  export const stateReverseTransition = (prev, next) => {
322
357
  prev = toState(prev);
323
358
  next = toState(next);
@@ -347,6 +382,7 @@ export const stateReverseTransition = (prev, next) => {
347
382
  if (prev.dim === null) ++resetCount;
348
383
 
349
384
  for (const name of Object.keys(RESET_STATE)) {
385
+ if (chainedStates[name] === 1) continue; // skip chained states
350
386
  const value = prev[name];
351
387
  if (resetColorProperties.hasOwnProperty(name)) {
352
388
  // color
@@ -374,8 +410,17 @@ export const stateReverseTransition = (prev, next) => {
374
410
  return commands;
375
411
  };
376
412
 
413
+ /** Converts an array of SGR commands to an escape sequence string, or empty string if no commands.
414
+ * @param {string[]} commands
415
+ * @returns {string}
416
+ */
377
417
  export const stringifyCommands = commands => (commands?.length ? setCommands(commands) : '');
378
418
 
419
+ /** Optimizes SGR sequences in a string by computing minimal state transitions.
420
+ * @param {string} s - The string to optimize.
421
+ * @param {object} [initState] - Initial state.
422
+ * @returns {string} The optimized string.
423
+ */
379
424
  export const optimize = (s, initState = defaultState) => {
380
425
  let state = toState(initState),
381
426
  result = '',