console-toolkit 1.2.9 → 1.2.10
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 +70 -26
- package/package.json +26 -6
- package/src/alphanumeric/arrows.d.ts +48 -0
- package/src/alphanumeric/arrows.js +23 -0
- package/src/alphanumeric/fractions.d.ts +65 -0
- package/src/alphanumeric/fractions.js +49 -0
- package/src/alphanumeric/number-formatters.d.ts +91 -0
- package/src/alphanumeric/number-formatters.js +45 -1
- package/src/alphanumeric/roman.d.ts +15 -0
- package/src/alphanumeric/roman.js +12 -0
- package/src/alphanumeric/unicode-cultural-numbers.d.ts +65 -0
- package/src/alphanumeric/unicode-cultural-numbers.js +1 -0
- package/src/alphanumeric/unicode-letters.d.ts +32 -0
- package/src/alphanumeric/unicode-letters.js +8 -0
- package/src/alphanumeric/unicode-numbers.d.ts +44 -0
- package/src/alphanumeric/unicode-numbers.js +21 -0
- package/src/alphanumeric/utils.d.ts +45 -0
- package/src/alphanumeric/utils.js +26 -0
- package/src/ansi/csi.d.ts +141 -0
- package/src/ansi/csi.js +51 -2
- package/src/ansi/index.d.ts +26 -0
- package/src/ansi/sgr-constants.d.ts +173 -0
- package/src/ansi/sgr-state.d.ts +91 -0
- package/src/ansi/sgr-state.js +45 -0
- package/src/ansi/sgr.d.ts +587 -0
- package/src/ansi/sgr.js +426 -6
- package/src/box.d.ts +160 -0
- package/src/box.js +113 -12
- package/src/charts/bars/block-frac-grouped.d.ts +12 -0
- package/src/charts/bars/block-frac-grouped.js +6 -0
- package/src/charts/bars/block-frac.d.ts +34 -0
- package/src/charts/bars/block-frac.js +13 -0
- package/src/charts/bars/block-grouped.d.ts +12 -0
- package/src/charts/bars/block-grouped.js +6 -0
- package/src/charts/bars/block.d.ts +43 -0
- package/src/charts/bars/block.js +13 -0
- package/src/charts/bars/draw-grouped.d.ts +41 -0
- package/src/charts/bars/draw-grouped.js +4 -0
- package/src/charts/bars/draw-stacked.d.ts +47 -0
- package/src/charts/bars/draw-stacked.js +4 -0
- package/src/charts/bars/frac-grouped.d.ts +32 -0
- package/src/charts/bars/frac-grouped.js +13 -0
- package/src/charts/bars/plain-grouped.d.ts +12 -0
- package/src/charts/bars/plain-grouped.js +6 -0
- package/src/charts/bars/plain.d.ts +75 -0
- package/src/charts/bars/plain.js +27 -0
- package/src/charts/columns/block-frac-grouped.d.ts +12 -0
- package/src/charts/columns/block-frac-grouped.js +6 -0
- package/src/charts/columns/block-frac.d.ts +39 -0
- package/src/charts/columns/block-frac.js +13 -0
- package/src/charts/columns/block-grouped.d.ts +12 -0
- package/src/charts/columns/block-grouped.js +6 -0
- package/src/charts/columns/block.d.ts +43 -0
- package/src/charts/columns/block.js +13 -0
- package/src/charts/columns/draw-grouped.d.ts +41 -0
- package/src/charts/columns/draw-grouped.js +4 -0
- package/src/charts/columns/draw-stacked.d.ts +39 -0
- package/src/charts/columns/draw-stacked.js +4 -0
- package/src/charts/columns/frac-grouped.d.ts +37 -0
- package/src/charts/columns/frac-grouped.js +13 -0
- package/src/charts/columns/plain-grouped.d.ts +12 -0
- package/src/charts/columns/plain-grouped.js +6 -0
- package/src/charts/columns/plain.d.ts +32 -0
- package/src/charts/columns/plain.js +13 -0
- package/src/charts/themes/default.d.ts +6 -0
- package/src/charts/themes/default.js +1 -0
- package/src/charts/themes/rainbow-reversed.d.ts +6 -0
- package/src/charts/themes/rainbow-reversed.js +2 -1
- package/src/charts/themes/rainbow.d.ts +6 -0
- package/src/charts/themes/rainbow.js +1 -0
- package/src/charts/utils.d.ts +79 -0
- package/src/charts/utils.js +32 -4
- package/src/draw-block-frac.d.ts +16 -0
- package/src/draw-block-frac.js +14 -0
- package/src/draw-block.d.ts +53 -0
- package/src/draw-block.js +25 -1
- package/src/meta.d.ts +84 -0
- package/src/meta.js +64 -0
- package/src/output/show.d.ts +55 -0
- package/src/output/show.js +28 -0
- package/src/output/updater.d.ts +114 -0
- package/src/output/updater.js +58 -4
- package/src/output/writer.d.ts +87 -0
- package/src/output/writer.js +57 -5
- package/src/panel.d.ts +402 -0
- package/src/panel.js +219 -5
- package/src/plot/bitmap.d.ts +80 -0
- package/src/plot/bitmap.js +33 -4
- package/src/plot/draw-line.d.ts +13 -0
- package/src/plot/draw-line.js +8 -0
- package/src/plot/draw-rect.d.ts +13 -0
- package/src/plot/draw-rect.js +38 -30
- package/src/plot/index.d.ts +39 -0
- package/src/plot/index.js +22 -0
- package/src/plot/to-quads.d.ts +10 -0
- package/src/plot/to-quads.js +5 -0
- package/src/spinner/index.d.ts +4 -0
- package/src/spinner/index.js +0 -2
- package/src/spinner/spin.d.ts +13 -0
- package/src/spinner/spin.js +13 -2
- package/src/spinner/spinner.d.ts +69 -0
- package/src/spinner/spinner.js +30 -2
- package/src/spinner/spinners.d.ts +34 -0
- package/src/spinner/spinners.js +23 -9
- package/src/strings/clip.d.ts +21 -0
- package/src/strings/clip.js +10 -0
- package/src/strings/parse.d.ts +23 -0
- package/src/strings/parse.js +7 -0
- package/src/strings/split.d.ts +38 -0
- package/src/strings/split.js +15 -0
- package/src/strings.d.ts +44 -0
- package/src/strings.js +34 -4
- package/src/style.d.ts +462 -0
- package/src/style.js +58 -4
- package/src/symbols.d.ts +167 -0
- package/src/symbols.js +91 -7
- package/src/table/draw-borders.d.ts +38 -0
- package/src/table/draw-borders.js +10 -2
- package/src/table/index.d.ts +8 -0
- package/src/table/index.js +1 -0
- package/src/table/table.d.ts +234 -0
- package/src/table/table.js +59 -1
- package/src/themes/blocks/unicode-half.d.ts +6 -0
- package/src/themes/blocks/unicode-half.js +1 -0
- package/src/themes/blocks/unicode-thin.d.ts +6 -0
- package/src/themes/blocks/unicode-thin.js +1 -0
- package/src/themes/lines/ascii-compact.d.ts +6 -0
- package/src/themes/lines/ascii-compact.js +1 -0
- package/src/themes/lines/ascii-dots.d.ts +6 -0
- package/src/themes/lines/ascii-dots.js +1 -0
- package/src/themes/lines/ascii-girder.d.ts +6 -0
- package/src/themes/lines/ascii-girder.js +1 -0
- package/src/themes/lines/ascii-github.d.ts +6 -0
- package/src/themes/lines/ascii-github.js +1 -0
- package/src/themes/lines/ascii-reddit.d.ts +6 -0
- package/src/themes/lines/ascii-reddit.js +1 -0
- package/src/themes/lines/ascii-rounded.d.ts +6 -0
- package/src/themes/lines/ascii-rounded.js +1 -0
- package/src/themes/lines/ascii.d.ts +6 -0
- package/src/themes/lines/ascii.js +1 -0
- package/src/themes/lines/unicode-bold.d.ts +6 -0
- package/src/themes/lines/unicode-bold.js +1 -0
- package/src/themes/lines/unicode-rounded.d.ts +6 -0
- package/src/themes/lines/unicode-rounded.js +1 -0
- package/src/themes/lines/unicode.d.ts +6 -0
- package/src/themes/lines/unicode.js +1 -0
- package/src/themes/utils.d.ts +33 -0
- package/src/themes/utils.js +7 -0
- package/src/turtle/draw-line-art.d.ts +19 -0
- package/src/turtle/draw-line-art.js +7 -0
- package/src/turtle/draw-unicode.d.ts +19 -0
- package/src/turtle/draw-unicode.js +8 -0
- package/src/turtle/index.d.ts +21 -0
- package/src/turtle/index.js +8 -0
- package/src/turtle/turtle.d.ts +269 -0
- package/src/turtle/turtle.js +124 -4
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {SymbolRange} from './utils.js';
|
|
2
|
+
|
|
3
|
+
/** Transcode tables for cultural number systems, mapping ASCII digits to their Unicode equivalents. */
|
|
4
|
+
export const transcodeTables: {
|
|
5
|
+
arabicIndic: SymbolRange;
|
|
6
|
+
arabicIndicExtended: SymbolRange;
|
|
7
|
+
tamil: SymbolRange;
|
|
8
|
+
nko: SymbolRange;
|
|
9
|
+
devanagari: SymbolRange;
|
|
10
|
+
bengali: SymbolRange;
|
|
11
|
+
gurmukhi: SymbolRange;
|
|
12
|
+
gujarati: SymbolRange;
|
|
13
|
+
oriya: SymbolRange;
|
|
14
|
+
telugu: SymbolRange;
|
|
15
|
+
kannada: SymbolRange;
|
|
16
|
+
malayalam: SymbolRange;
|
|
17
|
+
thai: SymbolRange;
|
|
18
|
+
lao: SymbolRange;
|
|
19
|
+
myanmar: SymbolRange;
|
|
20
|
+
myanmarShan: SymbolRange;
|
|
21
|
+
ethiopic: SymbolRange;
|
|
22
|
+
khmer: SymbolRange;
|
|
23
|
+
mongolian: SymbolRange;
|
|
24
|
+
limbu: SymbolRange;
|
|
25
|
+
balinese: SymbolRange;
|
|
26
|
+
sundanese: SymbolRange;
|
|
27
|
+
lepcha: SymbolRange;
|
|
28
|
+
vai: SymbolRange;
|
|
29
|
+
saurashtra: SymbolRange;
|
|
30
|
+
javanese: SymbolRange;
|
|
31
|
+
cham: SymbolRange;
|
|
32
|
+
osmanya: SymbolRange;
|
|
33
|
+
kharoshthi: SymbolRange;
|
|
34
|
+
rumi: SymbolRange;
|
|
35
|
+
brahmi: SymbolRange;
|
|
36
|
+
brahmiNumbers: SymbolRange;
|
|
37
|
+
chakma: SymbolRange;
|
|
38
|
+
sharada: SymbolRange;
|
|
39
|
+
khudawadi: SymbolRange;
|
|
40
|
+
newa: SymbolRange;
|
|
41
|
+
tirhuta: SymbolRange;
|
|
42
|
+
modi: SymbolRange;
|
|
43
|
+
takri: SymbolRange;
|
|
44
|
+
ahom: SymbolRange;
|
|
45
|
+
bhaiksuki: SymbolRange;
|
|
46
|
+
bhaiksukiNumbers: SymbolRange;
|
|
47
|
+
mro: SymbolRange;
|
|
48
|
+
medefaidrin: SymbolRange;
|
|
49
|
+
wancho: SymbolRange;
|
|
50
|
+
adlam: SymbolRange;
|
|
51
|
+
aegean: SymbolRange;
|
|
52
|
+
palmyren: SymbolRange;
|
|
53
|
+
nabataean: SymbolRange;
|
|
54
|
+
oldPersian: SymbolRange;
|
|
55
|
+
imperialAramaic: SymbolRange;
|
|
56
|
+
meroiticCursive: SymbolRange;
|
|
57
|
+
inscriptionalParthian: SymbolRange;
|
|
58
|
+
inscriptionalPahlavi: SymbolRange;
|
|
59
|
+
psalterPahlavi: SymbolRange;
|
|
60
|
+
oldSogdian: SymbolRange;
|
|
61
|
+
indicSiyaq: SymbolRange;
|
|
62
|
+
indicSiyaqPrefixed: SymbolRange;
|
|
63
|
+
indicSiyaqAlternate: SymbolRange;
|
|
64
|
+
copticEpact: SymbolRange;
|
|
65
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {SymbolRange} from './utils.js';
|
|
2
|
+
|
|
3
|
+
/** Transcode tables for mathematical and decorative letter styles. */
|
|
4
|
+
export const transcodeTables: {
|
|
5
|
+
bold: SymbolRange[];
|
|
6
|
+
italic: SymbolRange[];
|
|
7
|
+
boldItalic: SymbolRange[];
|
|
8
|
+
sansSerif: SymbolRange[];
|
|
9
|
+
sansSerifBold: SymbolRange[];
|
|
10
|
+
sansSerifItalic: SymbolRange[];
|
|
11
|
+
sansSerifBoldItalic: SymbolRange[];
|
|
12
|
+
script: SymbolRange[];
|
|
13
|
+
scriptBold: SymbolRange[];
|
|
14
|
+
fraktur: SymbolRange[];
|
|
15
|
+
frakturBold: SymbolRange[];
|
|
16
|
+
mono: SymbolRange[];
|
|
17
|
+
doubleStruck: SymbolRange[];
|
|
18
|
+
parens: SymbolRange[];
|
|
19
|
+
circled: SymbolRange[];
|
|
20
|
+
squared: SymbolRange[];
|
|
21
|
+
negativeCircled: SymbolRange[];
|
|
22
|
+
negativeSquared: SymbolRange[];
|
|
23
|
+
regionalIndicators: SymbolRange[];
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** Transcodes a string to a Unicode letter style.
|
|
27
|
+
* @param s - The string to transcode.
|
|
28
|
+
* @param name - Style name (key of `transcodeTables`) or an array of SymbolRanges.
|
|
29
|
+
* @param options - Options.
|
|
30
|
+
* @returns The transcoded string.
|
|
31
|
+
*/
|
|
32
|
+
export function transcode(s: string, name: string | SymbolRange[], options?: {missing?: string}): string;
|
|
@@ -5,6 +5,7 @@ const range = (fromCapital, fromSmall) =>
|
|
|
5
5
|
x => x
|
|
6
6
|
);
|
|
7
7
|
|
|
8
|
+
/** Transcode tables for mathematical and decorative letter styles. */
|
|
8
9
|
export const transcodeTables = {
|
|
9
10
|
bold: range('\u{1D400}', '\u{1D41A}'),
|
|
10
11
|
italic: range('\u{1D434}', '\u{1D44E}'),
|
|
@@ -56,6 +57,13 @@ transcodeTables.script[1].overlay = {e: '\u{212F}', g: '\u{210A}', o: '\u{2134}'
|
|
|
56
57
|
|
|
57
58
|
// API
|
|
58
59
|
|
|
60
|
+
/** Transcodes a string to a Unicode letter style.
|
|
61
|
+
* @param {string} s - The string to transcode.
|
|
62
|
+
* @param {string|import('./utils.js').SymbolRange[]} name - Style name (key of `transcodeTables`) or an array of SymbolRanges.
|
|
63
|
+
* @param {object} [options] - Options.
|
|
64
|
+
* @param {string} [options.missing] - Replacement for unmapped characters.
|
|
65
|
+
* @returns {string} The transcoded string.
|
|
66
|
+
*/
|
|
59
67
|
export const transcode = (s, name, options) => {
|
|
60
68
|
let tables = typeof name == 'string' ? transcodeTables[name] : name;
|
|
61
69
|
if (!tables) throw new Error(`There is no transcode table "${name}"`);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {SymbolRange} from './utils.js';
|
|
2
|
+
|
|
3
|
+
/** Transcode tables for Unicode number styles and embellishments. */
|
|
4
|
+
export const transcodeTables: {
|
|
5
|
+
circled: SymbolRange;
|
|
6
|
+
parens: SymbolRange;
|
|
7
|
+
dots: SymbolRange;
|
|
8
|
+
doubleCircled: SymbolRange;
|
|
9
|
+
bold: SymbolRange;
|
|
10
|
+
doubleStruck: SymbolRange;
|
|
11
|
+
sansSerif: SymbolRange;
|
|
12
|
+
sansSerifBold: SymbolRange;
|
|
13
|
+
mono: SymbolRange;
|
|
14
|
+
commas: SymbolRange;
|
|
15
|
+
roman: SymbolRange;
|
|
16
|
+
romanLower: SymbolRange;
|
|
17
|
+
dingbatsCircledSansSerif: SymbolRange;
|
|
18
|
+
dingbatsNegativeCircled: SymbolRange;
|
|
19
|
+
dingbatsNegativeCircledSansSerif: SymbolRange;
|
|
20
|
+
superscript: SymbolRange;
|
|
21
|
+
subscript: SymbolRange;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/** Transcodes a string of digits to a Unicode number style.
|
|
25
|
+
* @param s - The digit string to transcode.
|
|
26
|
+
* @param name - Style name (key of `transcodeTables`) or a SymbolRange.
|
|
27
|
+
* @param options - Options.
|
|
28
|
+
* @returns The transcoded string.
|
|
29
|
+
*/
|
|
30
|
+
export function transcode(s: string, name: string | SymbolRange, options?: {missing?: string}): string;
|
|
31
|
+
|
|
32
|
+
/** Replaces digit-punctuation pairs with Unicode enclosed digits.
|
|
33
|
+
* @param s - The string containing digits with commas/dots.
|
|
34
|
+
* @param options - Options for surrounding text.
|
|
35
|
+
* @returns The string with Unicode punctuation replacements.
|
|
36
|
+
*/
|
|
37
|
+
export function numberPunctuation(s: string, options?: {addBefore?: string; addAfter?: string}): string;
|
|
38
|
+
|
|
39
|
+
/** Converts scientific notation to Unicode superscript exponent form.
|
|
40
|
+
* @param s - The number string in scientific notation (e.g., '1.5e10').
|
|
41
|
+
* @param options - Options.
|
|
42
|
+
* @returns The formatted string with Unicode superscripts.
|
|
43
|
+
*/
|
|
44
|
+
export function numberExponent(s: string, options?: {useSpecialMinus?: boolean}): string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {SymbolRange, transcode as internalTranscode} from './utils.js';
|
|
2
2
|
import {minus, multiplication, superscriptPlus, superscriptMinus} from '../symbols.js';
|
|
3
3
|
|
|
4
|
+
/** Transcode tables for Unicode number styles and embellishments. */
|
|
4
5
|
export const transcodeTables = {
|
|
5
6
|
// Enclosed Alphanumeric
|
|
6
7
|
circled: new SymbolRange('①', 1, 20),
|
|
@@ -50,18 +51,38 @@ transcodeTables.superscript.overlay = {1: '¹', 2: '²', 3: '³'};
|
|
|
50
51
|
|
|
51
52
|
// API
|
|
52
53
|
|
|
54
|
+
/** Transcodes a string of digits to a Unicode number style.
|
|
55
|
+
* @param {string} s - The digit string to transcode.
|
|
56
|
+
* @param {string|import('./utils.js').SymbolRange} name - Style name (key of `transcodeTables`) or a SymbolRange.
|
|
57
|
+
* @param {object} [options] - Options.
|
|
58
|
+
* @param {string} [options.missing] - Replacement for unmapped characters.
|
|
59
|
+
* @returns {string} The transcoded string.
|
|
60
|
+
*/
|
|
53
61
|
export const transcode = (s, name, options) => {
|
|
54
62
|
const table = typeof name == 'string' ? transcodeTables[name] : name;
|
|
55
63
|
if (!table) throw new Error(`There is no transcode table "${name}"`);
|
|
56
64
|
return internalTranscode(s, table, options);
|
|
57
65
|
};
|
|
58
66
|
|
|
67
|
+
/** Replaces digit-punctuation pairs with Unicode enclosed digits.
|
|
68
|
+
* @param {string} s - The string containing digits with commas/dots.
|
|
69
|
+
* @param {object} [options] - Options for surrounding text.
|
|
70
|
+
* @param {string} [options.addBefore=''] - String to add before a digit.
|
|
71
|
+
* @param {string} [options.addAfter=' '] - String to add after a digit.
|
|
72
|
+
* @returns {string} The string with Unicode punctuation replacements.
|
|
73
|
+
*/
|
|
59
74
|
export const numberPunctuation = (s, {addBefore = '', addAfter = ' '} = {}) =>
|
|
60
75
|
s.replace(
|
|
61
76
|
/(\d)([\,\.])/g,
|
|
62
77
|
(_, d, p) => addBefore + transcodeTables[p === '.' ? 'dots' : 'commas'].transcode(d) + addAfter
|
|
63
78
|
);
|
|
64
79
|
|
|
80
|
+
/** Converts scientific notation to Unicode superscript exponent form.
|
|
81
|
+
* @param {string} s - The number string in scientific notation (e.g., '1.5e10').
|
|
82
|
+
* @param {object} [options] - Options.
|
|
83
|
+
* @param {boolean} [options.useSpecialMinus] - If true, use a special math minus symbol.
|
|
84
|
+
* @returns {string} The formatted string with Unicode superscripts.
|
|
85
|
+
*/
|
|
65
86
|
export const numberExponent = (s, {useSpecialMinus} = {}) => {
|
|
66
87
|
const r = /^([+-]?)([^e]+)e([+-]?)(.+)$/i.exec(s);
|
|
67
88
|
return r
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** Maps a range of numeric values to Unicode code points for transcoding digits/letters. */
|
|
2
|
+
export class SymbolRange {
|
|
3
|
+
/** Start of the numeric range. */
|
|
4
|
+
from: number;
|
|
5
|
+
/** End of the numeric range (inclusive). */
|
|
6
|
+
to: number;
|
|
7
|
+
/** Unicode code point base offset. */
|
|
8
|
+
base: number;
|
|
9
|
+
/** Code point of the input character corresponding to 0. */
|
|
10
|
+
inputBase: number;
|
|
11
|
+
/** Optional overlay for custom symbol replacements. */
|
|
12
|
+
overlay: SymbolRange | Record<string, string> | null;
|
|
13
|
+
|
|
14
|
+
/** Creates a new SymbolRange.
|
|
15
|
+
* @param fromSymbol - The Unicode character corresponding to the `from` value.
|
|
16
|
+
* @param from - Start of the range (default: 0).
|
|
17
|
+
* @param to - End of the range inclusive (default: 9).
|
|
18
|
+
* @param inputBase - The input character corresponding to 0 (default: '0').
|
|
19
|
+
*/
|
|
20
|
+
constructor(fromSymbol: string, from?: number, to?: number, inputBase?: string);
|
|
21
|
+
|
|
22
|
+
/** Gets the transcoded symbol for a value or character.
|
|
23
|
+
* @param i - Numeric index or input character.
|
|
24
|
+
* @returns The transcoded symbol, or `false` if out of range.
|
|
25
|
+
*/
|
|
26
|
+
get(i: number | string): string | false;
|
|
27
|
+
/** Transcodes a string by replacing each character with its mapped symbol.
|
|
28
|
+
* @param s - The string to transcode.
|
|
29
|
+
* @param options - Options.
|
|
30
|
+
* @returns The transcoded string.
|
|
31
|
+
*/
|
|
32
|
+
transcode(s: string, options?: {missing?: string}): string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Transcodes a string using one or more lookup tables.
|
|
36
|
+
* @param s - The string to transcode.
|
|
37
|
+
* @param tables - A function, SymbolRange, array of SymbolRanges, or a plain mapping object.
|
|
38
|
+
* @param options - Options.
|
|
39
|
+
* @returns The transcoded string.
|
|
40
|
+
*/
|
|
41
|
+
export function transcode(
|
|
42
|
+
s: string,
|
|
43
|
+
tables: ((m: string) => string | undefined) | SymbolRange | SymbolRange[] | Record<string, string>,
|
|
44
|
+
options?: {missing?: string}
|
|
45
|
+
): string;
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
+
/** Maps a range of numeric values to Unicode code points for transcoding digits/letters.
|
|
2
|
+
* Supports overlays for custom symbol replacements.
|
|
3
|
+
*/
|
|
1
4
|
export class SymbolRange {
|
|
5
|
+
/**
|
|
6
|
+
* @param {string} fromSymbol - The Unicode character corresponding to the `from` value.
|
|
7
|
+
* @param {number} [from=0] - Start of the range.
|
|
8
|
+
* @param {number} [to=9] - End of the range (inclusive).
|
|
9
|
+
* @param {string} [inputBase='0'] - The input character corresponding to 0.
|
|
10
|
+
*/
|
|
2
11
|
constructor(fromSymbol, from = 0, to = 9, inputBase = '0') {
|
|
3
12
|
this.from = from;
|
|
4
13
|
this.to = to;
|
|
@@ -6,6 +15,10 @@ export class SymbolRange {
|
|
|
6
15
|
this.inputBase = inputBase.codePointAt(0);
|
|
7
16
|
this.overlay = null;
|
|
8
17
|
}
|
|
18
|
+
/** Gets the transcoded symbol for a value or character.
|
|
19
|
+
* @param {number|string} i - Numeric index or input character.
|
|
20
|
+
* @returns {string|false} The transcoded symbol, or false if out of range.
|
|
21
|
+
*/
|
|
9
22
|
get(i) {
|
|
10
23
|
if (this.overlay) {
|
|
11
24
|
const result =
|
|
@@ -19,11 +32,24 @@ export class SymbolRange {
|
|
|
19
32
|
}
|
|
20
33
|
return this.from <= i && i <= this.to && String.fromCodePoint(this.base + i);
|
|
21
34
|
}
|
|
35
|
+
/** Transcodes a string by replacing each character with its mapped symbol.
|
|
36
|
+
* @param {string} s - The string to transcode.
|
|
37
|
+
* @param {object} [options] - Options.
|
|
38
|
+
* @param {string} [options.missing] - Replacement for unmapped characters.
|
|
39
|
+
* @returns {string} The transcoded string.
|
|
40
|
+
*/
|
|
22
41
|
transcode(s, {missing} = {}) {
|
|
23
42
|
return s.replace(/./g, missing ? m => this.get(m) || missing : m => this.get(m) || m);
|
|
24
43
|
}
|
|
25
44
|
}
|
|
26
45
|
|
|
46
|
+
/** Transcodes a string using one or more lookup tables.
|
|
47
|
+
* @param {string} s - The string to transcode.
|
|
48
|
+
* @param {Function|object|Array} tables - A function, object, SymbolRange, or array of them.
|
|
49
|
+
* @param {object} [options] - Options.
|
|
50
|
+
* @param {string} [options.missing] - Replacement for unmapped characters.
|
|
51
|
+
* @returns {string} The transcoded string.
|
|
52
|
+
*/
|
|
27
53
|
export const transcode = (s, tables, {missing} = {}) => {
|
|
28
54
|
let fn;
|
|
29
55
|
if (typeof tables == 'function') {
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
export * from './sgr.js';
|
|
2
|
+
|
|
3
|
+
/** RegExp matching CSI (Control Sequence Introducer) escape sequences. */
|
|
4
|
+
export const matchCsi: RegExp;
|
|
5
|
+
|
|
6
|
+
/** Moves cursor up 1 row. */
|
|
7
|
+
export const CURSOR_UP1: string;
|
|
8
|
+
/** Moves cursor down 1 row. */
|
|
9
|
+
export const CURSOR_DOWN1: string;
|
|
10
|
+
/** Moves cursor forward 1 column. */
|
|
11
|
+
export const CURSOR_FORWARD1: string;
|
|
12
|
+
/** Moves cursor back 1 column. */
|
|
13
|
+
export const CURSOR_BACK1: string;
|
|
14
|
+
/** Moves cursor to beginning of next line. */
|
|
15
|
+
export const CURSOR_NEXT_LINE1: string;
|
|
16
|
+
/** Moves cursor to beginning of previous line. */
|
|
17
|
+
export const CURSOR_PREV_LINE1: string;
|
|
18
|
+
/** Moves cursor to column 1. */
|
|
19
|
+
export const CURSOR_COLUMN1: string;
|
|
20
|
+
/** Moves cursor to home position (1,1). */
|
|
21
|
+
export const CURSOR_HOME: string;
|
|
22
|
+
|
|
23
|
+
/** Requests cursor position report. */
|
|
24
|
+
export const CURSOR_GET_POS: string;
|
|
25
|
+
/** Saves cursor position. */
|
|
26
|
+
export const CURSOR_SAVE_POS: string;
|
|
27
|
+
/** Restores saved cursor position. */
|
|
28
|
+
export const CURSOR_RESTORE_POS: string;
|
|
29
|
+
/** Shows the cursor. */
|
|
30
|
+
export const CURSOR_NORMAL: string;
|
|
31
|
+
/** Hides the cursor. */
|
|
32
|
+
export const CURSOR_INVISIBLE: string;
|
|
33
|
+
|
|
34
|
+
/** Moves the cursor up by `n` rows.
|
|
35
|
+
* @param n - Number of rows (default: 1).
|
|
36
|
+
* @returns CSI escape sequence.
|
|
37
|
+
*/
|
|
38
|
+
export function cursorUp(n?: number): string;
|
|
39
|
+
/** Moves the cursor down by `n` rows.
|
|
40
|
+
* @param n - Number of rows (default: 1).
|
|
41
|
+
* @returns CSI escape sequence.
|
|
42
|
+
*/
|
|
43
|
+
export function cursorDown(n?: number): string;
|
|
44
|
+
/** Moves the cursor forward by `n` columns.
|
|
45
|
+
* @param n - Number of columns (default: 1).
|
|
46
|
+
* @returns CSI escape sequence.
|
|
47
|
+
*/
|
|
48
|
+
export function cursorForward(n?: number): string;
|
|
49
|
+
/** Moves the cursor back by `n` columns.
|
|
50
|
+
* @param n - Number of columns (default: 1).
|
|
51
|
+
* @returns CSI escape sequence.
|
|
52
|
+
*/
|
|
53
|
+
export function cursorBack(n?: number): string;
|
|
54
|
+
/** Moves cursor to beginning of line `n` lines down.
|
|
55
|
+
* @param n - Number of lines (default: 1).
|
|
56
|
+
* @returns CSI escape sequence.
|
|
57
|
+
*/
|
|
58
|
+
export function cursorNextLine(n?: number): string;
|
|
59
|
+
/** Moves cursor to beginning of line `n` lines up.
|
|
60
|
+
* @param n - Number of lines (default: 1).
|
|
61
|
+
* @returns CSI escape sequence.
|
|
62
|
+
*/
|
|
63
|
+
export function cursorPrevLine(n?: number): string;
|
|
64
|
+
/** Moves cursor to column `n`.
|
|
65
|
+
* @param n - Column number (default: 1).
|
|
66
|
+
* @returns CSI escape sequence.
|
|
67
|
+
*/
|
|
68
|
+
export function cursorColumn(n?: number): string;
|
|
69
|
+
/** Sets the cursor to row `n`, column `m` (1-based).
|
|
70
|
+
* @param n - Row.
|
|
71
|
+
* @param m - Column.
|
|
72
|
+
* @returns CSI escape sequence.
|
|
73
|
+
*/
|
|
74
|
+
export function cursorSetPos(n: number, m: number): string;
|
|
75
|
+
/** Sets the cursor position (alternative sequence).
|
|
76
|
+
* @param n - Row.
|
|
77
|
+
* @param m - Column.
|
|
78
|
+
* @returns CSI escape sequence.
|
|
79
|
+
*/
|
|
80
|
+
export function cursorSetPosAlt(n: number, m: number): string;
|
|
81
|
+
|
|
82
|
+
/** Alias for CURSOR_FORWARD1. */
|
|
83
|
+
export const CURSOR_RIGHT1: string;
|
|
84
|
+
/** Alias for CURSOR_BACK1. */
|
|
85
|
+
export const CURSOR_LEFT1: string;
|
|
86
|
+
/** Alias for cursorForward. */
|
|
87
|
+
export const cursorRight: typeof cursorForward;
|
|
88
|
+
/** Alias for cursorBack. */
|
|
89
|
+
export const cursorLeft: typeof cursorBack;
|
|
90
|
+
|
|
91
|
+
/** Clears from cursor to end of screen. */
|
|
92
|
+
export const CLEAR_EOS: string;
|
|
93
|
+
/** Clears from cursor to beginning of screen. */
|
|
94
|
+
export const CLEAR_BOS: string;
|
|
95
|
+
/** Clears the entire screen. */
|
|
96
|
+
export const CLEAR_SCREEN: string;
|
|
97
|
+
/** Clears the entire screen and scrollback buffer. */
|
|
98
|
+
export const CLEAR_SCREEN_ALL: string;
|
|
99
|
+
/** Clears from cursor to end of line. */
|
|
100
|
+
export const CLEAR_EOL: string;
|
|
101
|
+
/** Clears from cursor to beginning of line. */
|
|
102
|
+
export const CLEAR_BOL: string;
|
|
103
|
+
/** Clears the entire line. */
|
|
104
|
+
export const CLEAR_LINE: string;
|
|
105
|
+
|
|
106
|
+
/** Saves the screen state. */
|
|
107
|
+
export const SCREEN_SAVE: string;
|
|
108
|
+
/** Restores the screen state. */
|
|
109
|
+
export const SCREEN_RESTORE: string;
|
|
110
|
+
/** Enables the alternative screen buffer. */
|
|
111
|
+
export const SCREEN_ALT_ON: string;
|
|
112
|
+
/** Disables the alternative screen buffer. */
|
|
113
|
+
export const SCREEN_ALT_OFF: string;
|
|
114
|
+
/** Scrolls screen up 1 line. */
|
|
115
|
+
export const SCREEN_SCROLL_UP1: string;
|
|
116
|
+
/** Scrolls screen down 1 line. */
|
|
117
|
+
export const SCREEN_SCROLL_DOWN1: string;
|
|
118
|
+
/** Enables focus reporting. */
|
|
119
|
+
export const SCREEN_REPORT_FOCUS_ON: string;
|
|
120
|
+
/** Disables focus reporting. */
|
|
121
|
+
export const SCREEN_REPORT_FOCUS_OFF: string;
|
|
122
|
+
|
|
123
|
+
/** Scrolls the screen up by `n` lines.
|
|
124
|
+
* @param n - Number of lines (default: 1).
|
|
125
|
+
* @returns CSI escape sequence.
|
|
126
|
+
*/
|
|
127
|
+
export function screenScrollUp(n?: number): string;
|
|
128
|
+
/** Scrolls the screen down by `n` lines.
|
|
129
|
+
* @param n - Number of lines (default: 1).
|
|
130
|
+
* @returns CSI escape sequence.
|
|
131
|
+
*/
|
|
132
|
+
export function screenScrollDown(n?: number): string;
|
|
133
|
+
|
|
134
|
+
/** Enables line wrapping. */
|
|
135
|
+
export const WRAPPING_ON: string;
|
|
136
|
+
/** Disables line wrapping. */
|
|
137
|
+
export const WRAPPING_OFF: string;
|
|
138
|
+
/** Enables bracketed paste mode. */
|
|
139
|
+
export const BRACKETED_PASTE_ON: string;
|
|
140
|
+
/** Disables bracketed paste mode. */
|
|
141
|
+
export const BRACKETED_PASTE_OFF: string;
|
package/src/ansi/csi.js
CHANGED
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
export * from './sgr.js';
|
|
8
8
|
|
|
9
9
|
// matcher
|
|
10
|
+
/** RegExp matching CSI (Control Sequence Introducer) escape sequences with parameter, intermediate, and final byte groups.
|
|
11
|
+
* @type {RegExp}
|
|
12
|
+
*/
|
|
10
13
|
export const matchCsi = /\x1B\[([\x30-\x3F]*)([\x20-\x2F]*)([\x40-\x7E])/g;
|
|
11
14
|
|
|
12
15
|
const CSI = '\x1B[';
|
|
@@ -26,14 +29,52 @@ export const CURSOR_RESTORE_POS = CSI + 'u';
|
|
|
26
29
|
export const CURSOR_NORMAL = CSI + '?25h';
|
|
27
30
|
export const CURSOR_INVISIBLE = CSI + '?25l';
|
|
28
31
|
|
|
32
|
+
/** Moves the cursor up by `n` rows.
|
|
33
|
+
* @param {number} [n=1]
|
|
34
|
+
* @returns {string} CSI sequence.
|
|
35
|
+
*/
|
|
29
36
|
export const cursorUp = (n = 1) => CSI + (n > 1 ? n.toFixed() : '') + 'A';
|
|
37
|
+
/** Moves the cursor down by `n` rows.
|
|
38
|
+
* @param {number} [n=1]
|
|
39
|
+
* @returns {string} CSI sequence.
|
|
40
|
+
*/
|
|
30
41
|
export const cursorDown = (n = 1) => CSI + (n > 1 ? n.toFixed() : '') + 'B';
|
|
42
|
+
/** Moves the cursor forward by `n` columns.
|
|
43
|
+
* @param {number} [n=1]
|
|
44
|
+
* @returns {string} CSI sequence.
|
|
45
|
+
*/
|
|
31
46
|
export const cursorForward = (n = 1) => CSI + (n > 1 ? n.toFixed() : '') + 'C';
|
|
47
|
+
/** Moves the cursor back by `n` columns.
|
|
48
|
+
* @param {number} [n=1]
|
|
49
|
+
* @returns {string} CSI sequence.
|
|
50
|
+
*/
|
|
32
51
|
export const cursorBack = (n = 1) => CSI + (n > 1 ? n.toFixed() : '') + 'D';
|
|
52
|
+
/** Moves cursor to beginning of line `n` lines down.
|
|
53
|
+
* @param {number} [n=1]
|
|
54
|
+
* @returns {string} CSI sequence.
|
|
55
|
+
*/
|
|
33
56
|
export const cursorNextLine = (n = 1) => CSI + (n > 1 ? n.toFixed() : '') + 'E';
|
|
57
|
+
/** Moves cursor to beginning of line `n` lines up.
|
|
58
|
+
* @param {number} [n=1]
|
|
59
|
+
* @returns {string} CSI sequence.
|
|
60
|
+
*/
|
|
34
61
|
export const cursorPrevLine = (n = 1) => CSI + (n > 1 ? n.toFixed() : '') + 'F';
|
|
62
|
+
/** Moves cursor to column `n`.
|
|
63
|
+
* @param {number} [n=1]
|
|
64
|
+
* @returns {string} CSI sequence.
|
|
65
|
+
*/
|
|
35
66
|
export const cursorColumn = (n = 1) => CSI + (n > 1 ? n.toFixed() : '') + 'G';
|
|
67
|
+
/** Sets the cursor to row `n`, column `m` (1-based).
|
|
68
|
+
* @param {number} n - Row.
|
|
69
|
+
* @param {number} m - Column.
|
|
70
|
+
* @returns {string} CSI sequence.
|
|
71
|
+
*/
|
|
36
72
|
export const cursorSetPos = (n, m) => CSI + (n > 1 ? n.toFixed() : '') + ';' + (m > 1 ? m.toFixed() : '') + 'H';
|
|
73
|
+
/** Sets the cursor position (alternative HVP sequence).
|
|
74
|
+
* @param {number} n - Row.
|
|
75
|
+
* @param {number} m - Column.
|
|
76
|
+
* @returns {string} CSI sequence.
|
|
77
|
+
*/
|
|
37
78
|
export const cursorSetPosAlt = (n, m) => CSI + (n > 1 ? n.toFixed() : '') + ';' + (m > 1 ? m.toFixed() : '') + 'f'; // HVP
|
|
38
79
|
|
|
39
80
|
export const CURSOR_RIGHT1 = CURSOR_FORWARD1;
|
|
@@ -53,12 +94,20 @@ export const SCREEN_SAVE = CSI + '?47h';
|
|
|
53
94
|
export const SCREEN_RESTORE = CSI + '?47l';
|
|
54
95
|
export const SCREEN_ALT_ON = CSI + '?1049h'; // alternative screen buffer
|
|
55
96
|
export const SCREEN_ALT_OFF = CSI + '?1049l';
|
|
56
|
-
export const SCREEN_SCROLL_UP1 = CSI + 'S'
|
|
57
|
-
export const SCREEN_SCROLL_DOWN1 = CSI + 'T'
|
|
97
|
+
export const SCREEN_SCROLL_UP1 = CSI + 'S';
|
|
98
|
+
export const SCREEN_SCROLL_DOWN1 = CSI + 'T';
|
|
58
99
|
export const SCREEN_REPORT_FOCUS_ON = CSI + '?1004h';
|
|
59
100
|
export const SCREEN_REPORT_FOCUS_OFF = CSI + '?1004l';
|
|
60
101
|
|
|
102
|
+
/** Scrolls the screen up by `n` lines.
|
|
103
|
+
* @param {number} [n=1]
|
|
104
|
+
* @returns {string} CSI sequence.
|
|
105
|
+
*/
|
|
61
106
|
export const screenScrollUp = (n = 1) => CSI + (n > 1 ? n.toFixed() : '') + 'S';
|
|
107
|
+
/** Scrolls the screen down by `n` lines.
|
|
108
|
+
* @param {number} [n=1]
|
|
109
|
+
* @returns {string} CSI sequence.
|
|
110
|
+
*/
|
|
62
111
|
export const screenScrollDown = (n = 1) => CSI + (n > 1 ? n.toFixed() : '') + 'T';
|
|
63
112
|
|
|
64
113
|
export const WRAPPING_ON = CSI + '=7h';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export * from './csi.js';
|
|
2
|
+
|
|
3
|
+
/** The ESC character (\x1B). */
|
|
4
|
+
export const ESC: string;
|
|
5
|
+
|
|
6
|
+
/** Deletes the character at the cursor. */
|
|
7
|
+
export const CURSOR_DELETE: string;
|
|
8
|
+
|
|
9
|
+
/** Moves cursor up 1 row (Fe sequence). */
|
|
10
|
+
export const CURSOR_GO_UP1: string;
|
|
11
|
+
|
|
12
|
+
/** Saves cursor position (Fe sequence). */
|
|
13
|
+
export const CURSOR_SAVE: string;
|
|
14
|
+
/** Restores cursor position (Fe sequence). */
|
|
15
|
+
export const CURSOR_RESTORE: string;
|
|
16
|
+
|
|
17
|
+
/** RegExp matching Fe escape sequences. */
|
|
18
|
+
export const matchFe: RegExp;
|
|
19
|
+
/** RegExp matching Fs escape sequences. */
|
|
20
|
+
export const matchFs: RegExp;
|
|
21
|
+
/** RegExp matching Fp escape sequences. */
|
|
22
|
+
export const matchFp: RegExp;
|
|
23
|
+
/** RegExp matching Nf escape sequences. */
|
|
24
|
+
export const matchNf: RegExp;
|
|
25
|
+
/** RegExp matching OSC escape sequences. */
|
|
26
|
+
export const matchOsc: RegExp;
|