From 3d7fc329891301f9d6885477e4af74c25ab80692 Mon Sep 17 00:00:00 2001 From: Bojan Joveski Date: Fri, 30 May 2025 09:40:25 -0700 Subject: [PATCH] allow using custom regexes --- index.d.ts | 4 +++- index.js | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index 298b04f..fb4f56c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -18,6 +18,8 @@ declare module "node-email-reply-parser" { } type ReplyParserRegular = (emailContent: string) => Email; type ReplyParserVisibleTextOnly = (emailContent: string, visibleTextOnly: true) => string; - const replyParser: ReplyParserRegular & ReplyParserVisibleTextOnly; + type ReplyParserWithOptions = (emailContent: string, visibleTextOnly: boolean, options: { signatureRegex?: RegExp; quotedLineRegex?: RegExp; quoteHeadersRegex?: RegExp[] }) => Email; + + const replyParser: ReplyParserRegular & ReplyParserVisibleTextOnly & ReplyParserWithOptions; export = replyParser; } diff --git a/index.js b/index.js index c1130fc..be7da38 100644 --- a/index.js +++ b/index.js @@ -9,10 +9,14 @@ var Parser = require("./lib/Parser"); * Parses the given text into an email * @param {string} text the email text to parse * @param {boolean} [visibleTextOnly] if true, the visible text will be returned instead of an Email + * @param {object} [options] the options to pass to the parser + * @param {RegExp} [options.signatureRegex] the regular expression used to match signatures + * @param {RegExp} [options.quotedLineRegex] the regular expression used to match quoted lines + * @param {RegExp[]} [options.quoteHeadersRegex] the regular expressions used to find quoted sections based on the header * @returns {Email|string} the parsed Email or visible text, depending on the second argument */ -function parse(text, visibleTextOnly) { - var parser = new Parser(); +function parse(text, visibleTextOnly, options) { + var parser = new Parser(options?.signatureRegex, options?.quotedLineRegex, options?.quoteHeadersRegex); var email = parser.parse(text); if (visibleTextOnly) {