Skip to content

Commit ee4498e

Browse files
Merge pull request #152 from stoplightio/fix/parser-options-typings
Include ParserOptions#parse in TS typings
2 parents 5e99a84 + d8fef60 commit ee4498e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/index.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,16 @@ declare namespace $RefParser {
301301
* A regular expression can be used to match files by their full path. A string (or array of strings) can be used to match files by their file extension. Or a function can be used to perform more complex matching logic. See the custom parser docs for details.
302302
*/
303303
canParse?: boolean | RegExp | string | string[] | ((file: FileInfo) => boolean)
304+
305+
/**
306+
* This is where the real work of a parser happens. The `parse` method accepts the same [file info object](file-info-object.md) as the `canParse` function, but rather than returning a boolean value, the `parse` method should return a JavaScript representation of the file contents. For our CSV parser, that is a two-dimensional array of lines and values. For your parser, it might be an object, a string, a custom class, or anything else.
307+
*
308+
* Unlike the `canParse` function, the `parse` method can also be asynchronous. This might be important if your parser needs to retrieve data from a database or if it relies on an external HTTP service to return the parsed value. You can return your asynchronous value via a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) or a Node.js-style error-first callback. Here are examples of both approaches:
309+
*/
310+
parse(
311+
file: FileInfo,
312+
callback?: (error: Error | null, data: string | null) => any
313+
): unknown | Promise<unknown>
304314
}
305315

306316
/**

0 commit comments

Comments
 (0)