Skip to content

Commit

Permalink
Fix: Extend and update regex patterns (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
justbbetter authored Dec 22, 2016
1 parent 13f6c88 commit 9e88539
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lib/patterns.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ module.exports = {
zipcode: /\b\d{5}\b(-\d{4})?\b/gi,
phoneNumber: /(\(?\+?[0-9]{1,2}\)?[-. ]?)?(\(?[0-9]{3}\)?|[0-9]{3})[-. ]?([0-9]{3}[-. ]?[0-9]{4}|\b[A-Z0-9]{7}\b)/g,
ipAddress: /(\d{1,3}(\.\d{1,3}){3}|[0-9A-F]{4}(:[0-9A-F]{4}){5}(::|(:0000)+))/gi,
emailAddress: /([a-z0-9_\-.+]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-z0-9-]+\.)+))([a-z]{2,4}|[0-9]{1,3})(]?)/gi,
emailAddress: /([a-z0-9_\-.+]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-z0-9-]+\.?)+))([a-z]{2,4}|[0-9]{1,3})(]?)/gi,
username: /(user( ?name)?|login): \S+/gi,
password: /(pass(word|phrase)?|secret): \S+/gi,
credentials: /(login( cred(ential)?s| info(rmation)?)?|cred(ential)?s) ?:\s*\S+\s+\/?\s*\S+/gi,
company: /([A-Z&][\w,]* )+(I[Nn][Cc](orporated)?|C[Oo](rp(oration)?)?|LLP|llc|LLC|plc|gmbh)\.?(\b|$)/g,
salutation: /(^|\n(\s+)?)(dear|hi|hey|hello|greetings) ([^,:;\s]+(,? )?){1,5}[,;\n]/gi,
valediction: /(thanks|cheers|sincerely|regards|respectfully|best|best regards|yours truly)\s*,?\n\s*([\w&]+( )?){1,5}/gi,
valediction: /([Tt]hank(s| you)( for [^!,.]+| again)?|[Cc]heers|[Ss]incerely|[Rr]egards|[Rr]espectfully|[Bb]est|[Bb]est regards|[Yy]ours truly)\s*[!,.]?\s*([A-Z&]([\w&]+)?\.?( )?)+[^a-z]*$/g,
digits: /\d+/
};
8 changes: 4 additions & 4 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ defineTest('index.js', function (Redactor) {

it('should replace credit card numbers', function () {
redactor.redact('my card: 1234 5678 8765 4321.').should.equal('my card: CREDIT_CARD_NUMBER.');
redactor.redact('my 2nd card: 1234-5678-8765-4321.').should.equal('my 2nd card: CREDIT_CARD_NUMBER.');
redactor.redact('my 3rd card: 1234567887654321.').should.equal('my 3rd card: CREDIT_CARD_NUMBER.');
redactor.redact('my 2nd card: 1234-5678-8765-4321.').should.equal('my DIGITSnd card: CREDIT_CARD_NUMBER.');
redactor.redact('my 3rd card: 1234567887654321.').should.equal('my DIGITSrd card: CREDIT_CARD_NUMBER.');
});

it('should replace phone numbers', function () {
Expand Down Expand Up @@ -69,7 +69,7 @@ defineTest('index.js', function (Redactor) {
verify([
'Oh no worries I live right down the street and up the boulevard',
'There is no way that I will pay for that circle in court',
'I have thought of 1000 ways to finish that drive',
'I have thought of many ways to finish that drive',
]);
});

Expand Down Expand Up @@ -138,7 +138,7 @@ defineTest('index.js', function (Redactor) {
}
});

redactor.redact('my CC is 1234567812345678').should.equal('my CC is XXXXXXXXXXXX5678');
redactor.redact('my CC is 1234567812345678').should.equal('my CC is XXXXXXXXXXXXDIGITS');
redactor.redact('David Johnson lives in 90210').should.equal('FULL_NAME lives in ZIPCODE');
});

Expand Down

0 comments on commit 9e88539

Please sign in to comment.