Website Structure

This commit is contained in:
supalerk-ar66 2026-01-13 10:46:40 +07:00
parent 62812f2090
commit 71f0676a62
22365 changed files with 4265753 additions and 791 deletions

View file

@ -0,0 +1,2 @@
declare const _default: import("util").DebugLogger;
export default _default;

View file

@ -0,0 +1,55 @@
import type { Parser, Transformer, ParsedError, SourceLoader, YouchParserOptions } from './types.js';
/**
* ErrorParser exposes the API to parse an thrown value and extract
* the frames along with their location from it.
*/
export declare class ErrorParser {
#private;
/**
* FS source loader reads the file contents from the filesystem
* for all non-native frames
*/
static fsSourceLoader: SourceLoader;
constructor(options?: YouchParserOptions);
/**
* Register a parser. Parsers are synchronous functions
* that can be used to pre-process the source value
* before it get parsed.
*
* @example
* ```ts
* sourceFile.useParser((source) => {
* if (valueCanBeParsed) {
* return newValue
* }
* return source
* })
* ```
*/
useParser(parser: Parser): this;
/**
* Register a transformer. Transformers can be async functions
* to post-process the parsed error value.
*
* @example
* ```ts
* sourceFile.useTransformer((error, source) => {
* // mutate "error" properties
* })
* ```
*/
useTransformer(transformer: Transformer): this;
/**
* Define a custom source loader to load the contents of the
* source file within the error stack.
*
* For example: You might want to register a custom source loader
* that makes an fetch call to the server to read the source of
* the file within the error stack.
*/
defineSourceLoader(loader: SourceLoader): this;
/**
* Parse an unknown value into a parsed error object.
*/
parse(source: unknown): Promise<ParsedError>;
}

View file

@ -0,0 +1,24 @@
import type { Chunk } from './types.js';
/**
* SourceFile exposes the API to slice the contents of a file
* into chunks for displaying the source code of a stack
* frame
*/
export declare class SourceFile {
#private;
constructor(options: {
contents?: string;
});
/**
* Slice the file contents for the buffer size around a given
* line number.
*
* @example
* ```ts
* const chunks = sourceFile.slice(11, 7)
* // Here chunks will be an array of 7 items from line number
* // 8 to 14
* ```
*/
slice(lineNumber: number, bufferSize: number): undefined | Chunk[];
}

View file

@ -0,0 +1,111 @@
/**
* Representation of a source file chunk
*/
export type Chunk = {
chunk: string;
lineNumber: number;
};
/**
* Representation of a parsed error message
*/
export interface ParsedError {
message: string;
name: string;
frames: StackFrame[];
/**
* Referenced to the raw error property. The value will always
* be an Error object even if the thrown value was not an
* error
*/
raw: Error;
cause?: unknown;
hint?: string;
code?: string;
stack?: string;
}
/**
* Representation of a stack frame
*/
export interface StackFrame {
args?: any[];
/**
* The column number at which the error occurred.
*/
columnNumber?: number;
/**
* The line number at which the error occurred.
*/
lineNumber?: number;
/**
* The source file in which the error occurred.
*/
fileName?: string;
/**
* The function name
*/
functionName?: string;
/**
* Stack trace raw source
*/
raw?: string;
/**
* The source property refers to the file content
* chunks for a given frame.
*
* The source is only available for frame type "app"
* and "module"
*/
source?: Chunk[];
/**
* The frame type refers to the location from where the
* frame has originated.
*
* - native belongs to Node.js or v8 internals
* - module belongs to files inside `node_modules`
* - app belongs to application source code
*/
type?: 'native' | 'module' | 'app';
/**
* The file type refers to the type of the file path.
* It will either point to a file on the system or
* points to an HTTP URL in case of errors within
* the browser.
*/
fileType?: 'fs' | 'http' | 'https';
}
/**
* Source loaders are used to read the contents of the source
* file.
*/
export type SourceLoader = (frame: StackFrame) => Promise<undefined | {
contents: string;
}> | undefined | {
contents: string;
};
/**
* Parsers are synchronous functions that can be used to pre-process
* the source value before it get parsed.
*/
export type Parser = (source: unknown) => any;
/**
* Transformers can be async functions to post-process the parsed
* error value.
*/
export type Transformer = (error: ParsedError, source: unknown) => void | Promise<void>;
/**
* Options accepted by the Youch parser
*/
export type YouchParserOptions = {
/**
* Define the offset to skip certain stack frames from
* the top
*/
offset?: number;
/**
* Number of lines of code to display for the error stack frame.
* For example: If you set the frameSourceBuffer=7, then 3 lines
* above the error line and 3 lines after the error line will
* be displayed.
*/
frameSourceBuffer?: number;
};

View file