Skip to content

Commit

Permalink
feat: create type for the parser options
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Nov 23, 2024
1 parent 0ff0de5 commit 2a163f9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ import { parse, StackFrame as ESFrame } from 'error-stack-parser-es'

import debug from './debug.js'
import { SourceFile } from './source_file.js'
import type { Chunk, ParsedError, Parser, SourceLoader, StackFrame, Transformer } from './types.js'
import type {
Chunk,
Parser,
StackFrame,
Transformer,
ParsedError,
SourceLoader,
YouchParserOptions,
} from './types.js'

/**
* ErrorParser exposes the API to parse an thrown value and extract
Expand Down Expand Up @@ -81,7 +89,7 @@ export class ErrorParser {
*/
#transformers: Transformer[] = []

constructor(options?: { offset?: number; frameSourceBuffer?: number }) {
constructor(options?: YouchParserOptions) {
options = options ?? {}
this.#offset = options.offset
}
Expand Down
19 changes: 19 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,22 @@ export type Parser = (source: unknown) => any
* 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
}

0 comments on commit 2a163f9

Please sign in to comment.