New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

node-personal-data-filter

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-personal-data-filter - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

.vscode/launch.json

17

index.d.ts

@@ -32,3 +32,20 @@ declare module PersonalDataFilter {

personalDataProperties?: string[];
/**
* Defines if the filter should use the default match replacer to replace each regular
* expression match.
*/
useDefaultMatchReplacer?: boolean;
/**
* Sets the match replacer which will be used to replace each regular
* expression match.
*/
matchReplacer: MatchReplacer;
}
/**
* Function which will be used to replace each regular expression match.
*/
type MatchReplacer = (match: string) => string
}

@@ -35,0 +52,0 @@

28

index.js
"use strict";
const _ = require("lodash");
const crypto = require("crypto");

@@ -24,2 +25,3 @@ const personalDataProperties = ["email", "useremail", "user", "username", "userid", "accountid", "account", "password", "pass", "pwd", "ip", "ipaddress"];

this._setPersonalDataProperties(config);
this._setMatchReplacer(config);
}

@@ -29,3 +31,3 @@

if (_.isString(data)) {
return data.replace(this._filterRegExp, this._mask);
return this._filterString(data);
} else if (_.isArray(data)) {

@@ -52,2 +54,10 @@ return _.map(data, v => this.filter(v));

_filterString(input) {
if (this._matchReplacer) {
return input.replace(this._filterRegExp, this._matchReplacer);
}
return input.replace(this._filterRegExp, this._mask)
}
_setRegularExpressions(config) {

@@ -96,4 +106,20 @@ const additionalRegularExpressionsSize = _.size(config.additionalRegularExpressions);

}
_setMatchReplacer(config) {
if (config.useDefaultMatchReplacer) {
if (config.matchReplacer) {
throw new Error("You can't use the default match replacer and a cutom one.");
}
this._matchReplacer = (match) => {
return crypto.createHash("sha256").update(match).digest("hex");
};
}
if (config.matchReplacer) {
this._matchReplacer = config.matchReplacer;
}
}
}
module.exports.newFilter = (cfg) => new PersonalDataFilter(cfg);

2

package.json
{
"name": "node-personal-data-filter",
"version": "0.1.0",
"version": "0.2.0",
"description": "node-personal-data-filter",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -84,1 +84,20 @@ # node-personal-data-filter

```
- Match replacers:
```JavaScript
const pdf = require("node-personal-data-filter");
const cfg = {
useDefaultMatchReplacer: true // Use the default match replacer - sha256 sum.
};
const f = pdf.newFilter(cfg);
```
```JavaScript
const pdf = require("node-personal-data-filter");
const cfg = {
matchReplacer: match => `not a secret - ${match}` // Set custom match replacer.
};
const f = pdf.newFilter(cfg);
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc