Skip to content

Commit

Permalink
fix: support for more closing utterances
Browse files Browse the repository at this point in the history
  • Loading branch information
justbbetter committed Dec 20, 2017
1 parent b6a8cd1 commit 5156a5f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/patterns.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ var aptRegex = /(apt|bldg|dept|fl|hngr|lot|pier|rm|ste|slip|trlr|unit|#)\.? *[a-
var poBoxRegex = /P\.? ?O\.? *Box +\d+/gi;
var roadRegex = /(street|st|road|rd|avenue|ave|drive|dr|loop|court|ct|circle|cir|lane|ln|boulevard|blvd|way)\.?\b/gi;
var greetingRegex = /(^|\.\s+)(dear|hi|hello|greetings|hey|hey there)/gi;
var closingRegex = /(thx|thanks|thank you|regards|best|sincerely|best regards|warm regards|warmest regards|warmly|all the best)/gi;
var closingRegex = /(thx|thanks|thank you|regards|best|[a-z]+ly|[a-z]+ regards|all the best|happy [a-z]+ing|take care|have a [a-z]+ (weekend|night|day))/gi;
var newlineRegex = /([\n\f\r-]+\s*)/gi;

module.exports = {
greetOrClose: new RegExp(`(((${greetingRegex.source})|(${closingRegex.source}[,.]?))[\\s-]+)`, 'gi'),
greetOrClose: new RegExp(`(((${greetingRegex.source})|(${closingRegex.source}[,.!]?))[\\s-]+)`, 'gi'),
nameGeneric: new RegExp(`( ?(([A-Z][a-z]+)|([A-Z]\\.)))+([,.]|[,.]?$)`, 'gm'),
names: new RegExp(`${newlineRegex.source}( ?(${names.join('|')}))+`, 'gi'),
creditCardNumber: /\d{4}[ -]?\d{4}[ -]?\d{4}[ -]?\d{4}|\d{4}[ -]?\d{6}[ -]?\d{4}\d?/g,
Expand Down
10 changes: 8 additions & 2 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,14 @@ defineTest('index.js', function (Redactor) {
redactor.redact('blah blah\n\n\nAll the best,\n\n--Meg C.\n\nAcme Support').should.equal('blah blah\n\n\nAll the best,\n\n--NAME\n\nAcme Support');
redactor.redact('blah blah\n\n\nAll the best,\n\n-John\n\nAcme Support').should.equal('blah blah\n\n\nAll the best,\n\n-NAME\n\nAcme Support');
redactor.redact('blah blah\nthanks Joshua.\n blah blah').should.equal('blah blah\nthanks NAME.\n blah blah');
redactor.redact('Hi David Johnson,\nHow are you?\n\nthanks Joshua.\n blah blah').should.equal('Hi NAME,\nHow are you?\n\nthanks NAME.\n blah blah');;
redactor.redact('Subject. Hi David Johnson.').should.equal('Subject. Hi NAME.');;
redactor.redact('Hi David Johnson,\nHow are you?\n\nthanks Joshua.\n blah blah').should.equal('Hi NAME,\nHow are you?\n\nthanks NAME.\n blah blah');
redactor.redact('Subject. Hi David Johnson.').should.equal('Subject. Hi NAME.');
redactor.redact('to hearing from you.\n\nAll the best,\n\nAngel\nCustomer Experience\nwww.foo.com').should.equal('to hearing from you.\n\nAll the best,\n\nNAME\nCustomer Experience\nwww.foo.com');
redactor.redact('getting this sorted out.\n\nKindest regards,\n\nFoo Bar\nCustomer Experience').should.equal('getting this sorted out.\n\nKindest regards,\n\nNAME\nCustomer Experience');
redactor.redact('blah.\n\nAffectionately,\n\nFoo Bar\nblah').should.equal('blah.\n\nAffectionately,\n\nNAME\nblah');
redactor.redact('blah.\n\nHappy Meditating!\n\nFoo Bar\nblah').should.equal('blah.\n\nHappy Meditating!\n\nNAME\nblah');
redactor.redact('blah.\n\nTake care!\n\nFoo Bar\nblah').should.equal('blah.\n\nTake care!\n\nNAME\nblah');
redactor.redact('blah.\n\nHave a wonderful weekend.\n\nFoo Bar\nblah').should.equal('blah.\n\nHave a wonderful weekend.\n\nNAME\nblah');
});

it('should replace credit card numbers', function () {
Expand Down

0 comments on commit 5156a5f

Please sign in to comment.