@remotex-labs/xmap 1.0.4 → 2.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.
Files changed (35) hide show
  1. package/README.md +206 -143
  2. package/dist/{components → cjs/components}/formatter.component.d.ts +3 -3
  3. package/dist/{components → cjs/components}/highlighter.component.d.ts +1 -1
  4. package/dist/{components → cjs/components}/parser.component.d.ts +1 -1
  5. package/dist/cjs/index.d.ts +9 -0
  6. package/dist/cjs/index.js +7 -0
  7. package/dist/cjs/index.js.map +8 -0
  8. package/dist/cjs/providers/interfaces/mapping.interface.d.ts +52 -0
  9. package/dist/cjs/providers/mapping.provider.d.ts +229 -0
  10. package/dist/cjs/services/interfaces/source.interface.d.ts +53 -0
  11. package/dist/cjs/services/source.service.d.ts +217 -0
  12. package/dist/esm/components/base64.component.d.ts +26 -0
  13. package/dist/esm/components/formatter.component.d.ts +66 -0
  14. package/dist/esm/components/highlighter.component.d.ts +186 -0
  15. package/dist/esm/components/interfaces/formatter.interface.d.ts +42 -0
  16. package/dist/esm/components/interfaces/highlighter.interface.d.ts +48 -0
  17. package/dist/esm/components/interfaces/parse.interface.d.ts +31 -0
  18. package/dist/esm/components/parser.component.d.ts +11 -0
  19. package/dist/esm/index.d.ts +9 -0
  20. package/dist/esm/index.js +7 -0
  21. package/dist/esm/index.js.map +8 -0
  22. package/dist/esm/providers/interfaces/mapping.interface.d.ts +52 -0
  23. package/dist/esm/providers/mapping.provider.d.ts +229 -0
  24. package/dist/esm/services/interfaces/source.interface.d.ts +53 -0
  25. package/dist/esm/services/source.service.d.ts +217 -0
  26. package/package.json +27 -12
  27. package/dist/index.d.ts +0 -9
  28. package/dist/index.js +0 -9
  29. package/dist/index.js.map +0 -7
  30. package/dist/services/interfaces/source.interface.d.ts +0 -252
  31. package/dist/services/source.service.d.ts +0 -399
  32. /package/dist/{components → cjs/components}/base64.component.d.ts +0 -0
  33. /package/dist/{components → cjs/components}/interfaces/formatter.interface.d.ts +0 -0
  34. /package/dist/{components → cjs/components}/interfaces/highlighter.interface.d.ts +0 -0
  35. /package/dist/{components → cjs/components}/interfaces/parse.interface.d.ts +0 -0
@@ -0,0 +1,217 @@
1
+ /**
2
+ * Import will remove at compile time
3
+ */
4
+ import type { PositionInterface, SourceMapInterface, SourceOptionsInterface, PositionWithCodeInterface, PositionWithContentInterface } from "./interfaces/source.interface";
5
+ /**
6
+ * Imports
7
+ */
8
+ import { MappingProvider } from "../providers/mapping.provider";
9
+ import { Bias } from "../providers/interfaces/mapping.interface";
10
+ /**
11
+ * A service for validating and processing source maps.
12
+ * This class allows parsing and manipulation of source maps, providing functionality such as
13
+ * retrieving position mappings between original and generated code, concatenating source maps,
14
+ * and getting code snippets based on mappings.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * const sourceMapJSON = '{"version": 3, "file": "bundle.js", "sources": ["foo.ts"], "names": [], "mappings": "AAAA"}';
19
+ * const sourceService = new SourceService(sourceMapJSON);
20
+ *
21
+ * console.log(sourceService.file); // Outputs: 'bundle.js'
22
+ * ```
23
+ */
24
+ export declare class SourceService {
25
+ /**
26
+ * The name of the generated file (bundle) that this source map applies to.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * console.log(sourceService.file); // 'bundle.js'
31
+ * ```
32
+ */
33
+ readonly file: string | null;
34
+ /**
35
+ * A MappingProvider instance of base64 VLQ-encoded mappings.
36
+ */
37
+ readonly mappings: MappingProvider;
38
+ /**
39
+ * The root URL for the sources, if present in the source map.
40
+ */
41
+ readonly sourceRoot: string | null;
42
+ /**
43
+ * A list of symbol names used by the “mappings” entry.
44
+ */
45
+ readonly names: Array<string>;
46
+ /**
47
+ * An array of source file paths.
48
+ */
49
+ readonly sources: Array<string>;
50
+ /**
51
+ * An array of source files contents.
52
+ */
53
+ readonly sourcesContent: Array<string>;
54
+ /**
55
+ * Creates a new instance of the `SourceService` class.
56
+ *
57
+ * This constructor initializes the class using either a `SourceMapInterface` object,
58
+ * a JSON string representing the source map, or an existing `SourceService` instance.
59
+ * It validates the source map and populates its properties such as `file`, `sources`, and `mappings`.
60
+ *
61
+ * @param source - Can be one of the following:
62
+ * - An object conforming to the `SourceMapInterface`.
63
+ * - A JSON string representing the source map.
64
+ * - A `SourceService` instance to copy the properties.
65
+ * @param file - (Optional) A string representing the file name of the generated bundle.
66
+ * Defaults to `null`. It will overwrite any existing `file` property in the source map.
67
+ * @throws {Error} - If the source map does not contain required properties or has an invalid format.
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * const sourceMapJSON = '{"version": 3, "file": "bundle.js", "sources": ["foo.ts"], "names": [], "mappings": "AAAA"}';
72
+ * const sourceService = new SourceService(sourceMapJSON);
73
+ * ```
74
+ */
75
+ constructor(source: SourceService);
76
+ constructor(source: SourceMapInterface | string, file?: string | null);
77
+ /**
78
+ * Converts the current source map data into a plain object format.
79
+ *
80
+ * @returns The source map json object.
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * const mapObject = sourceService.getMapObject();
85
+ * console.log(mapObject.file); // 'bundle.js'
86
+ * ```
87
+ */
88
+ getMapObject(): SourceMapInterface;
89
+ /**
90
+ * Concatenates one or more source maps to the current source map.
91
+ *
92
+ * This method merges additional source maps into the current source map,
93
+ * updating the `mappings`, `names`, `sources`, and `sourcesContent` arrays.
94
+ *
95
+ * @param maps - An array of `SourceMapInterface` or `SourceService` instances to be concatenated.
96
+ * @throws { Error } If no source maps are provided for concatenation.
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * sourceService.concat(anotherSourceMap);
101
+ * console.log(sourceService.sources); // Updated source paths
102
+ * ```
103
+ */
104
+ concat(...maps: Array<SourceMapInterface | SourceService>): void;
105
+ /**
106
+ * Creates a new instance of `SourceService` with concatenated source maps.
107
+ *
108
+ * @param maps - An array of `SourceMapInterface` or `SourceService` instances to be concatenated.
109
+ * @returns { SourceService } A new `SourceService` instance with the concatenated maps.
110
+ * @throws { Error } If no source maps are provided.
111
+ *
112
+ * @example
113
+ * ```ts
114
+ * const newService = sourceService.concatNewMap(anotherSourceMap);
115
+ * console.log(newService.file); // The file from the new source map
116
+ * ```
117
+ */
118
+ concatNewMap(...maps: Array<SourceMapInterface | SourceService>): SourceService;
119
+ /**
120
+ * Retrieves the position information based on the original source line and column.
121
+ *
122
+ * @param line - The line number in the generated code.
123
+ * @param column - The column number in the generated code.
124
+ * @param sourceIndex - The index or file path of the original source.
125
+ * @param bias - The bias to use when matching positions (`Bias.LOWER_BOUND`, `Bias.UPPER_BOUND`, or `Bias.BOUND`).
126
+ * @returns { PositionInterface | null } The corresponding position in the original source, or `null` if not found.
127
+ *
128
+ * @example
129
+ * ```ts
130
+ * const position = sourceService.getPositionByOriginal(1, 10, 'foo.ts');
131
+ * console.log(position?.line); // The line number in the original source
132
+ * ```
133
+ */
134
+ getPositionByOriginal(line: number, column: number, sourceIndex: number | string, bias?: Bias): PositionInterface | null;
135
+ /**
136
+ * Retrieves the position in the original source code based on a given line and column
137
+ * in the generated code.
138
+ *
139
+ * @param line - Line number in the generated code.
140
+ * @param column - Column number in the generated code.
141
+ * @param bias - The bias to use for matching positions. Defaults to `Bias.BOUND`.
142
+ * @returns {PositionInterface | null} The position in the original source, or null if not found.
143
+ *
144
+ * @example
145
+ * ```ts
146
+ * const position = sourceService.getPosition(2, 15);
147
+ * console.log(position?.source); // The original source file
148
+ * ```
149
+ */
150
+ getPosition(line: number, column: number, bias?: Bias): PositionInterface | null;
151
+ /**
152
+ * Retrieves the position and original source content for a given position in the generated code.
153
+ *
154
+ * @param line - Line number in the generated code.
155
+ * @param column - Column number in the generated code.
156
+ * @param bias - Bias used for position matching.
157
+ * @returns { PositionWithContentInterface | null } The position and its associated content, or `null` if not found.
158
+ *
159
+ * @example
160
+ * ```ts
161
+ * const positionWithContent = sourceService.getPositionWithContent(3, 5);
162
+ * console.log(positionWithContent?.sourcesContent); // The source code content
163
+ * ```
164
+ */
165
+ getPositionWithContent(line: number, column: number, bias?: Bias): PositionWithContentInterface | null;
166
+ /**
167
+ * Retrieves the position and a code snippet from the original source based on the given
168
+ * generated code position, with additional lines of code around the matching line.
169
+ *
170
+ * @param line - Line number in the generated code.
171
+ * @param column - Column number in the generated code.
172
+ * @param bias - Bias used for position matching.
173
+ * @param options - (Optional) Extra options for the amount of surrounding lines to include.
174
+ * @returns { PositionWithCodeInterface | null } The position and code snippet.
175
+ *
176
+ * @example
177
+ * ```ts
178
+ * const positionWithCode = sourceService.getPositionWithCode(4, 8, Bias.BOUND, { linesBefore: 2, linesAfter: 2 });
179
+ * console.log(positionWithCode?.code); // The code snippet from the original source
180
+ * ```
181
+ */
182
+ getPositionWithCode(line: number, column: number, bias?: Bias, options?: SourceOptionsInterface): PositionWithCodeInterface | null;
183
+ /**
184
+ * Converts the current source map object to a JSON string.
185
+ *
186
+ * @returns A stringified version of the source map object.
187
+ *
188
+ * @example
189
+ * ```ts
190
+ * console.log(sourceService.toString()); // JSON string of the source map
191
+ * ```
192
+ */
193
+ toString(): string;
194
+ /**
195
+ * Validates the provided source map object.
196
+ *
197
+ * This method checks whether all required keys are present in the source map object.
198
+ * It throws an error if any required keys are missing.
199
+ *
200
+ * @private
201
+ * @param input - The source map object to be validated.
202
+ * @throws Error If any required key is missing from the source map.
203
+ *
204
+ * @example
205
+ * ```ts
206
+ * const sourceMap = {
207
+ * version: 3,
208
+ * file: 'example.js',
209
+ * names: ['src', 'maps', 'example', 'function', 'line', 'column'],
210
+ * sources: ['source1.js', 'source2.js'],
211
+ * mappings: 'AAAA,SAASA,CAAC,CAAC,CAAC;AAAA,CAAC,CAAC;AAAC,CAAC',
212
+ * };
213
+ * sourceService['validateSource'](sourceMap); // Throws if invalid
214
+ * ```
215
+ */
216
+ private validateSourceMap;
217
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Encodes a given number using Variable-Length Quantity (VLQ) encoding.
3
+ * Negative numbers are encoded by converting to a non-negative representation.
4
+ * The continuation bit is used to indicate if more bytes follow.
5
+ *
6
+ * @param value - The number to be encoded.
7
+ * @returns The VLQ encoded string.
8
+ */
9
+ export declare function encodeVLQ(value: number): string;
10
+ /**
11
+ * Encodes an array of numbers using VLQ encoding.
12
+ * Each number in the array is individually encoded and the results are concatenated.
13
+ *
14
+ * @param values - The array of numbers to be encoded.
15
+ * @returns The concatenated VLQ encoded string.
16
+ */
17
+ export declare function encodeArrayVLQ(values: number[]): string;
18
+ /**
19
+ * Decodes a VLQ encoded string back into an array of numbers.
20
+ * Each character is decoded using the Base64 map and continuation bits are processed.
21
+ *
22
+ * @param data - The VLQ encoded string.
23
+ * @returns The array of decoded numbers.
24
+ * @throws Error If the string contains invalid Base64 characters.
25
+ */
26
+ export declare function decodeVLQ(data: string): number[];
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Import will remove at compile time
3
+ */
4
+ import type { PositionWithCodeInterface } from "../services/interfaces/source.interface";
5
+ import type { AnsiOptionInterface, FormatCodeInterface } from "./interfaces/formatter.interface";
6
+ /**
7
+ * Formats a code snippet with optional line padding and custom actions.
8
+ *
9
+ * This function takes a code string and an options object to format the code snippet.
10
+ * It applies padding to line numbers and can trigger custom actions for specific lines.
11
+ *
12
+ * @param code - The source code | stack to be formatted.
13
+ * @param options - Configuration options for formatting the code.
14
+ * - `padding` (number, optional): Number of characters for line number padding. Defaults to 10.
15
+ * - `startLine` (number, optional): The starting line number for formatting. Defaults to 1.
16
+ * - `action` (object, optional): Custom actions to apply to specific lines.
17
+ * - `triggerLine` (number): The line number where the action should be triggered.
18
+ * - `callback` (function): A callback function to format the line string when `triggerLine` is matched.
19
+ * The callback receives the formatted line string, the padding value, and the current line number as arguments.
20
+ *
21
+ * @returns A formatted string of the code snippet with applied padding and custom actions.
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * const formattedCode = formatCode(code, {
26
+ * padding: 8,
27
+ * startLine: 5,
28
+ * action: {
29
+ * triggerLine: 7,
30
+ * callback: (lineString, padding, lineNumber) => {
31
+ * return `Custom formatting for line ${lineNumber}: ${lineString}`;
32
+ * }
33
+ * }
34
+ * });
35
+ * console.log(formattedCode);
36
+ * ```
37
+ */
38
+ export declare function formatCode(code: string, options?: FormatCodeInterface): string;
39
+ /**
40
+ * Formats a code snippet around an error location with special highlighting.
41
+ *
42
+ * This function takes a `sourcePosition` object containing information about the source code
43
+ * and error location, then uses `formatCode` to format and highlight the relevant code snippet.
44
+ *
45
+ * @param sourcePosition - An object containing information about the source code and error location.
46
+ * - `code` (string): The entire source code content.
47
+ * - `line` (number): The line number where the error occurred (1-based indexing).
48
+ * - `column` (number): The column number within the line where the error occurred (1-based indexing).
49
+ * - `startLine` (number, optional): The starting line number of the code snippet (defaults to 1).
50
+ * @param ansiOption - Optional configuration for ANSI color codes.
51
+ * - `color` (string): The ANSI escape sequence to colorize the error marker and prefix (e.g., `'\x1b[38;5;160m'`).
52
+ * - `reset` (string): The ANSI escape sequence to reset the color (e.g., `'\x1b[0m'`).
53
+ *
54
+ * @throws Error - If the provided `sourcePosition` object has invalid line or column numbers,
55
+ * or if the error line is outside the boundaries of the provided code content.
56
+ *
57
+ * @returns A formatted string representing the relevant code snippet around the error location,
58
+ * including special highlighting for the error line and column.
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * const formattedErrorCode = formatErrorCode(sourcePosition);
63
+ * console.log(formattedErrorCode);
64
+ * ```
65
+ */
66
+ export declare function formatErrorCode(sourcePosition: PositionWithCodeInterface, ansiOption?: AnsiOptionInterface): string;
@@ -0,0 +1,186 @@
1
+ /**
2
+ * Import will remove at compile time
3
+ */
4
+ import type { HighlightSchemeInterface } from "./interfaces/highlighter.interface";
5
+ /**
6
+ * Imports
7
+ */
8
+ import * as ts from 'typescript';
9
+ /**
10
+ * An enum containing ANSI escape sequences for various colors.
11
+ *
12
+ * This enum is primarily intended for terminal output and won't work directly in JavaScript for web development.
13
+ * It defines color codes for various colors and a reset code to return to
14
+ * the default text color.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * console.log(`${Colors.red}This the text will be red in the terminal.${Colors.reset}`);
19
+ * ```
20
+ *
21
+ * This functionality is limited to terminal environments.
22
+ * Consider alternative methods
23
+ * for color highlighting in web development contexts, such as CSS classes.
24
+ */
25
+ export declare const enum Colors {
26
+ reset = "\u001B[0m",
27
+ gray = "\u001B[38;5;243m",
28
+ darkGray = "\u001B[38;5;238m",
29
+ lightCoral = "\u001B[38;5;203m",
30
+ lightOrange = "\u001B[38;5;215m",
31
+ oliveGreen = "\u001B[38;5;149m",
32
+ burntOrange = "\u001B[38;5;208m",
33
+ lightGoldenrodYellow = "\u001B[38;5;221m",
34
+ lightYellow = "\u001B[38;5;230m",
35
+ canaryYellow = "\u001B[38;5;227m",
36
+ deepOrange = "\u001B[38;5;166m",
37
+ lightGray = "\u001B[38;5;252m",
38
+ brightPink = "\u001B[38;5;197m"
39
+ }
40
+ /**
41
+ * Class responsible for applying semantic highlighting to a source code string based on a given color scheme.
42
+ *
43
+ * @class
44
+ *
45
+ * @param sourceFile - The TypeScript AST node representing the source file.
46
+ * @param code - The source code string to be highlighted.
47
+ * @param schema - The color scheme used for highlighting different elements in the code.
48
+ *
49
+ * const highlighter = new CodeHighlighter(sourceFile, code, schema);
50
+ */
51
+ export declare class CodeHighlighter {
52
+ private sourceFile;
53
+ private code;
54
+ private schema;
55
+ /**
56
+ * A Map of segments where the key is a combination of start and end positions,
57
+ * and the value is an object containing the color and reset code.
58
+ * This structure ensures unique segments and allows for fast lookups and updates.
59
+ *
60
+ * @example
61
+ * this.segments = new Map([
62
+ * ['0-10', { start: 1, end: 11, color: '\x1b[31m', reset: '\x1b[0m' }],
63
+ * ['11-20', { start: 12, end: 20, color: '\x1b[32m', reset: '\x1b[0m' }]
64
+ * ]);
65
+ */
66
+ private segments;
67
+ /**
68
+ * Creates an instance of the CodeHighlighter class.
69
+ *
70
+ * @param sourceFile - The TypeScript AST node representing the source file.
71
+ * @param code - The source code string to be highlighted.
72
+ * @param schema - The color scheme used for highlighting different elements in the code.
73
+ */
74
+ constructor(sourceFile: ts.Node, code: string, schema: HighlightSchemeInterface);
75
+ /**
76
+ * Parses a TypeScript AST node and processes its comments to identify segments that need highlighting.
77
+ *
78
+ * @param node - The TypeScript AST node to be parsed.
79
+ */
80
+ parseNode(node: ts.Node): void;
81
+ /**
82
+ * Generates a string with highlighted code segments based on the provided color scheme.
83
+ *
84
+ * This method processes the stored segments, applies the appropriate colors to each segment,
85
+ * and returns the resulting highlighted code as a single string.
86
+ *
87
+ * @returns The highlighted code as a string, with ANSI color codes applied to the segments.
88
+ */
89
+ highlight(): string;
90
+ /**
91
+ * Extracts a substring from the code based on the specified start and end positions.
92
+ *
93
+ * This method is used to retrieve the source code segment that corresponds to the
94
+ * given start and end positions. It is primarily used for highlighting specific
95
+ * segments of the code.
96
+ *
97
+ * @param start - The starting index of the segment to be extracted.
98
+ * @param end - The ending index of the segment to be extracted.
99
+ * @returns The extracted substring from the code.
100
+ */
101
+ private getSegmentSource;
102
+ /**
103
+ * Adds a new segment to the list of segments to be highlighted.
104
+ * The segment is defined by its start and end positions, the color to apply, and an optional reset code.
105
+ *
106
+ * @param start - The starting index of the segment in the code string.
107
+ * @param end - The ending index of the segment in the code string.
108
+ * @param color - The color code to apply to the segment.
109
+ * @param reset - The color reset code to apply after the segment, Defaults to the reset code defined in `Colors.reset`.
110
+ */
111
+ private addSegment;
112
+ /**
113
+ * Processes comments within a TypeScript AST node and adds segments for highlighting.
114
+ * Extracts trailing and leading comments from the node and adds them as segments using the color defined in `this.colorSchema.comments`.
115
+ *
116
+ * @param node - The TypeScript AST node whose comments are to be processed.
117
+ */
118
+ private processComments;
119
+ /**
120
+ * Processes the keywords within a TypeScript AST node and adds them as segments for highlighting.
121
+ *
122
+ * This method identifies potential keyword tokens within the provided node and adds them to the
123
+ * list of segments with the color defined in `this.schema.keywordColor`.
124
+ * The method considers the current node, its first token, and its last token to determine if they should be highlighted
125
+ * as keywords.
126
+ *
127
+ * The method checks if the node's kind falls within the range of keyword kinds defined by TypeScript.
128
+ * If the node or any of its tokens are identified as keywords, a segment is added to `this.segments`
129
+ * with the start and end positions of the node and the specified color for keywords.
130
+ *
131
+ * @param node - The TypeScript AST node to be processed for keywords.
132
+ */
133
+ private processKeywords;
134
+ /**
135
+ * Processes identifiers within a TypeScript AST node and adds them as segments for highlighting
136
+ * based on the node's parent type.
137
+ *
138
+ * This method determines the appropriate color for an identifier based on its parent node's kind.
139
+ * If the parent node matches one of the specified kinds, the identifier is highlighted with a cyan color.
140
+ * Supported parent kinds include various declarations, expressions, and signatures.
141
+ *
142
+ * @param node - The TypeScript AST node representing the identifier to be processed.
143
+ */
144
+ private processIdentifier;
145
+ /**
146
+ * Processes a TypeScript template expression and adds segments for highlighting its literal parts.
147
+ *
148
+ * This method adds a segment for the head of the template expression with the color specified in `this.schema.stringColor`.
149
+ * It also processes each template span within the expression, adding
150
+ * segments for each span's literal part.
151
+ *
152
+ * @param templateExpression - The TypeScript template expression to be processed.
153
+ */
154
+ private processTemplateExpression;
155
+ /**
156
+ * Processes a TypeScript AST node and adds segments for highlighting based on the node's kind.
157
+ *
158
+ * This method identifies the kind of the node and determines the appropriate color for highlighting.
159
+ * It handles various node kinds including string literals, regular expressions, template expressions, and identifiers.
160
+ * Specific methods are invoked for more complex node kinds, such as template expressions and identifiers.
161
+ *
162
+ * @param node - The TypeScript AST node to be processed.
163
+ */
164
+ private processNode;
165
+ }
166
+ /**
167
+ * Applies semantic highlighting to the provided code string using the specified color scheme.
168
+ *
169
+ * @param code - The source code to be highlighted.
170
+ * @param schema - An optional partial schema defining the color styles for various code elements.
171
+ * Defaults to an empty object, which means no specific highlighting will be applied.
172
+ *
173
+ * @returns A string with the code elements wrapped in the appropriate color styles as specified by the schema.
174
+ *
175
+ * @example
176
+ * const code = 'const x: number = 42;';
177
+ * const schema = {
178
+ * keywordColor: '\x1b[34m', // Blue
179
+ * stringColor: '\x1b[32m', // Green
180
+ * numberColor: '\x1b[31m', // Red
181
+ * reset: '\x1b[0m' // Reset
182
+ * };
183
+ * const highlightedCode = highlightCode(code, schema);
184
+ * console.log(highlightedCode);
185
+ */
186
+ export declare function highlightCode(code: string, schema?: Partial<HighlightSchemeInterface>): string;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * A callback function type used for formatting code lines.
3
+ *
4
+ * @param lineString - The content of the line to be formatted.
5
+ * @param padding - The amount of padding to be applied to the line.
6
+ * @param line - The line number of the line to be formatted.
7
+ * @returns The formatted line string.
8
+ */
9
+ export type FormatCodeCallbackType = (lineString: string, padding: number, line: number) => string;
10
+ /**
11
+ * Configuration options for formatting code.
12
+ */
13
+ export interface FormatCodeInterface {
14
+ /**
15
+ * The amount of padding to be applied to each line. If not specified, defaults to 0.
16
+ */
17
+ padding?: number;
18
+ /**
19
+ * The starting line number for formatting. If not specified, defaults to 1.
20
+ */
21
+ startLine?: number;
22
+ /**
23
+ * An optional action object specifying a line where a callback function should be triggered.
24
+ */
25
+ action?: {
26
+ /**
27
+ * The line number at which the callback function should be triggered.
28
+ */
29
+ triggerLine: number;
30
+ /**
31
+ * The callback function to be executed when the trigger line is encountered.
32
+ */
33
+ callback: FormatCodeCallbackType;
34
+ };
35
+ }
36
+ /**
37
+ * Set color to an error pointer
38
+ */
39
+ export interface AnsiOptionInterface {
40
+ color: string;
41
+ reset: string;
42
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * HighlightSchemeInterface defines the structure for a color style schema
3
+ * used in semantic highlighting.
4
+ * This interface ensures that the highlighting styles are consistent and easily configurable.
5
+ */
6
+ export interface HighlightSchemeInterface {
7
+ enumColor: string;
8
+ typeColor: string;
9
+ classColor: string;
10
+ stringColor: string;
11
+ keywordColor: string;
12
+ commentColor: string;
13
+ functionColor: string;
14
+ variableColor: string;
15
+ interfaceColor: string;
16
+ parameterColor: string;
17
+ getAccessorColor: string;
18
+ numericLiteralColor: string;
19
+ methodSignatureColor: string;
20
+ regularExpressionColor: string;
21
+ propertyAssignmentColor: string;
22
+ propertyAccessExpressionColor: string;
23
+ expressionWithTypeArgumentsColor: string;
24
+ }
25
+ /**
26
+ * Represents a segment of a code string that needs to be highlighted.
27
+ *
28
+ * @interface
29
+ *
30
+ * @property start - The starting index of the segment in the code string.
31
+ * @property end - The ending index of the segment in the code string.
32
+ * @property color - The color code to apply to the segment.
33
+ * @property reset - The color reset code to apply after the segment.
34
+ *
35
+ * @example
36
+ * const segment: HighlightNodeSegment = {
37
+ * start: 0,
38
+ * end: 10,
39
+ * color: '\x1b[31m', // Red
40
+ * reset: '\x1b[0m' // Reset
41
+ * };
42
+ */
43
+ export interface HighlightNodeSegmentInterface {
44
+ end: number;
45
+ start: number;
46
+ color: string;
47
+ reset: string;
48
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Represents an entry in the stack trace.
3
+ */
4
+ export interface StackInterface {
5
+ /**
6
+ * The function or method where the error occurred.
7
+ */
8
+ at: string;
9
+ /**
10
+ * The file path where the error occurred.
11
+ */
12
+ file: string;
13
+ /**
14
+ * The line number where the error occurred.
15
+ */
16
+ line: number;
17
+ /**
18
+ * The column number where the error occurred.
19
+ */
20
+ column: number;
21
+ }
22
+ /**
23
+ * Represents a detailed entry in the stack trace, which may include an executor stack entry.
24
+ */
25
+ export interface StackEntryInterface extends StackInterface {
26
+ /**
27
+ * The executor information if the error occurred within an eval function.
28
+ * This will be `null` if the error did not occur within an eval function.
29
+ */
30
+ executor?: StackInterface | null;
31
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Import will remove at compile time
3
+ */
4
+ import type { StackEntryInterface } from "./interfaces/parse.interface";
5
+ /**
6
+ * Parses an error stack trace and returns an object with a message and an array of stack entries.
7
+ *
8
+ * @param stackString - The error stack trace.
9
+ * @returns The parsed stack trace object.
10
+ */
11
+ export declare function parseErrorStack(stackString: string): Array<StackEntryInterface>;
@@ -0,0 +1,9 @@
1
+ export type * from "./components/interfaces/parse.interface";
2
+ export type * from "./components/interfaces/formatter.interface";
3
+ export type * from "./components/interfaces/highlighter.interface";
4
+ export type * from "./services/interfaces/source.interface";
5
+ export * from "./components/parser.component";
6
+ export * from "./components/base64.component";
7
+ export * from "./components/formatter.component";
8
+ export * from "./components/highlighter.component";
9
+ export * from "./services/source.service";