Skip to content

Commit d8fef60

Browse files
committed
Include ParserOptions#parse in TS typings
1 parent 9bf784d commit d8fef60

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
@@ -299,6 +299,16 @@ declare namespace $RefParser {
299299
* 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.
300300
*/
301301
canParse?: boolean | RegExp | string | string[] | ((file: FileInfo) => boolean)
302+
303+
/**
304+
* 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.
305+
*
306+
* 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:
307+
*/
308+
parse(
309+
file: FileInfo,
310+
callback?: (error: Error | null, data: string | null) => any
311+
): unknown | Promise<unknown>
302312
}
303313

304314
/**

0 commit comments

Comments
 (0)