node-personal-data-filter
Advanced tools
Comparing version 0.4.0 to 0.5.0-dev
@@ -11,3 +11,3 @@ declare module PersonalDataFilter { | ||
*/ | ||
additionalRegularExpressions?: string[]; | ||
additionalRegularExpressions?: (string | RegExp)[]; | ||
@@ -14,0 +14,0 @@ /** |
26
index.js
@@ -94,10 +94,15 @@ "use strict"; | ||
_filterString(input) { | ||
if (this._matchReplacer) { | ||
return input.replace(this._filterRegExp, this._matchReplacer); | ||
_replaceAll(input, replaceValue) { | ||
let result = input; | ||
for (const filterRegExp of this._filterRegExps) { | ||
result = result.replace(filterRegExp, replaceValue) | ||
} | ||
return input.replace(this._filterRegExp, this._mask) | ||
return result; | ||
} | ||
_filterString(input) { | ||
return this._replaceAll(input, this._matchReplacer || this._mask); | ||
} | ||
_setRegularExpressions(config) { | ||
@@ -110,13 +115,16 @@ const additionalRegularExpressionsSize = _.size(config.additionalRegularExpressions); | ||
if (config.regularExpression) { | ||
this._filterRegExp = config.regularExpression; | ||
this._filterRegExps = [config.regularExpression]; | ||
return; | ||
} | ||
let regExps = _.concat([], defaultRegularExpressions); | ||
let stringRegExps = _.concat([], defaultRegularExpressions); | ||
let additionalRegExpObjects = []; | ||
if (additionalRegularExpressionsSize > 0) { | ||
regExps = _.concat(regExps, config.additionalRegularExpressions); | ||
const additionalRegularExpressionStrings = _.filter(config.additionalRegularExpressions, expression => typeof expression === "string"); | ||
additionalRegExpObjects = _.difference(config.additionalRegularExpressions, additionalRegularExpressionStrings); | ||
stringRegExps = _.concat(stringRegExps, additionalRegularExpressionStrings); | ||
} | ||
const regExpString = regExps.map(r => `(${r})`).join("|"); | ||
this._filterRegExp = new RegExp(regExpString, "gi"); | ||
const regExpString = stringRegExps.map(r => `(${r})`).join("|"); | ||
this._filterRegExps = [new RegExp(regExpString, "gi"), ...additionalRegExpObjects]; | ||
} | ||
@@ -123,0 +131,0 @@ |
{ | ||
"name": "node-personal-data-filter", | ||
"version": "0.4.0", | ||
"version": "0.5.0-dev", | ||
"description": "node-personal-data-filter", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
207
24319
6