Skip to content

Commit 3d7fc32

Browse files
committed
allow using custom regexes
1 parent ffc9cb0 commit 3d7fc32

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

index.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ declare module "node-email-reply-parser" {
1818
}
1919
type ReplyParserRegular = (emailContent: string) => Email;
2020
type ReplyParserVisibleTextOnly = (emailContent: string, visibleTextOnly: true) => string;
21-
const replyParser: ReplyParserRegular & ReplyParserVisibleTextOnly;
21+
type ReplyParserWithOptions = (emailContent: string, visibleTextOnly: boolean, options: { signatureRegex?: RegExp; quotedLineRegex?: RegExp; quoteHeadersRegex?: RegExp[] }) => Email;
22+
23+
const replyParser: ReplyParserRegular & ReplyParserVisibleTextOnly & ReplyParserWithOptions;
2224
export = replyParser;
2325
}

index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ var Parser = require("./lib/Parser");
99
* Parses the given text into an email
1010
* @param {string} text the email text to parse
1111
* @param {boolean} [visibleTextOnly] if true, the visible text will be returned instead of an Email
12+
* @param {object} [options] the options to pass to the parser
13+
* @param {RegExp} [options.signatureRegex] the regular expression used to match signatures
14+
* @param {RegExp} [options.quotedLineRegex] the regular expression used to match quoted lines
15+
* @param {RegExp[]} [options.quoteHeadersRegex] the regular expressions used to find quoted sections based on the header
1216
* @returns {Email|string} the parsed Email or visible text, depending on the second argument
1317
*/
14-
function parse(text, visibleTextOnly) {
15-
var parser = new Parser();
18+
function parse(text, visibleTextOnly, options) {
19+
var parser = new Parser(options?.signatureRegex, options?.quotedLineRegex, options?.quoteHeadersRegex);
1620
var email = parser.parse(text);
1721

1822
if (visibleTextOnly) {

0 commit comments

Comments
 (0)