maskdata 1.2.2 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc.js +7 -0
- package/README.md +213 -144
- package/index.d.ts +86 -72
- package/index.js +11 -3
- package/lib/ExceptionsHandler/BadOption.js +2 -2
- package/lib/helpers/Constants.js +57 -48
- package/lib/helpers/MaskHelper.js +156 -95
- package/lib/helpers/jsonGetSet.js +8 -9
- package/lib/maskService/CardMask.js +51 -51
- package/lib/maskService/EmailMask.js +26 -20
- package/lib/maskService/JsonMask.js +166 -87
- package/lib/maskService/JwtMask.js +92 -0
- package/lib/maskService/PasswordMask.js +34 -33
- package/lib/maskService/PhoneMask.js +19 -15
- package/lib/maskService/StringMask.js +33 -34
- package/lib/maskService/UuidMask.js +28 -21
- package/package.json +18 -7
- package/tests/scribble.js +379 -122
- package/tests/testCard.js +35 -40
- package/tests/testEmail.js +46 -53
- package/tests/testJsonFields.js +486 -240
- package/tests/testJsonGetSet.js +54 -21
- package/tests/testJwt.js +262 -0
- package/tests/testMaskHelper.js +109 -103
- package/tests/testPassword.js +51 -51
- package/tests/testPhone.js +35 -41
- package/tests/testString.js +46 -57
- package/tests/testUuid.js +55 -43
|
@@ -3,42 +3,41 @@ const MaskHelper = require('../helpers/MaskHelper');
|
|
|
3
3
|
const Constants = require('../helpers/Constants');
|
|
4
4
|
|
|
5
5
|
class StringMask {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return result;
|
|
30
|
-
}
|
|
31
|
-
else if(options.maskOnlyFirstOccurance == true) {
|
|
32
|
-
for(const value of Object.values(values)) {
|
|
33
|
-
str = str.replace(value, `${options.maskWith}`.repeat(value.length));
|
|
34
|
-
}
|
|
35
|
-
} else {
|
|
36
|
-
for(const value of Object.values(values)) {
|
|
37
|
-
str = str.replace(new RegExp(value, 'g'), `${options.maskWith}`.repeat(value.length));
|
|
6
|
+
static maskString(str, options) {
|
|
7
|
+
if (!str || typeof str === 'object') return str;
|
|
8
|
+
str = str + '';
|
|
9
|
+
if (options) {
|
|
10
|
+
options = MaskHelper.mapWithDefaultValues(options, Constants.defaultStringMaskOptions);
|
|
11
|
+
MaskHelper.validateStringOptions(options);
|
|
12
|
+
} else {
|
|
13
|
+
options = Constants.defaultStringMaskOptions;
|
|
14
|
+
}
|
|
15
|
+
let values = options.values;
|
|
16
|
+
if (options.maskAll === true) {
|
|
17
|
+
let result = '';
|
|
18
|
+
if (options.maskSpace === true) {
|
|
19
|
+
result = options.maskWith.repeat(str.length);
|
|
20
|
+
} else {
|
|
21
|
+
for (let eachChar of str) {
|
|
22
|
+
if (eachChar === ' ') {
|
|
23
|
+
result += ' ';
|
|
24
|
+
} else {
|
|
25
|
+
result += options.maskWith;
|
|
38
26
|
}
|
|
39
27
|
}
|
|
40
|
-
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
30
|
+
} else if (options.maskOnlyFirstOccurance == true) {
|
|
31
|
+
for (const value of Object.values(values)) {
|
|
32
|
+
str = str.replace(value, `${options.maskWith}`.repeat(value.length));
|
|
33
|
+
}
|
|
34
|
+
} else {
|
|
35
|
+
for (const value of Object.values(values)) {
|
|
36
|
+
str = str.replace(new RegExp(value, 'g'), `${options.maskWith}`.repeat(value.length));
|
|
37
|
+
}
|
|
41
38
|
}
|
|
39
|
+
return str;
|
|
40
|
+
}
|
|
42
41
|
}
|
|
43
42
|
|
|
44
|
-
module.exports = StringMask
|
|
43
|
+
module.exports = StringMask;
|
|
@@ -5,30 +5,37 @@ const Constants = require('../helpers/Constants');
|
|
|
5
5
|
const uuidFormat = /[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}/g;
|
|
6
6
|
|
|
7
7
|
class UuidMask {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
static maskUuid(uuid, options) {
|
|
9
|
+
if (!uuid || typeof uuid !== 'string' || !uuid.match(uuidFormat) || uuid.length !== 36)
|
|
10
|
+
return uuid;
|
|
11
|
+
if (!options) {
|
|
12
|
+
options = Constants.defaultUuidMaskOptions;
|
|
13
|
+
} else {
|
|
14
|
+
options = MaskHelper.mapWithDefaultValues(options, Constants.defaultUuidMaskOptions);
|
|
15
|
+
MaskHelper.validateUuidMaskOptions(options);
|
|
16
|
+
}
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
const toBeProcessedUuid = uuid.replaceAll('-', '');
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
const start = toBeProcessedUuid.slice(0, options.unmaskedStartCharacters);
|
|
21
|
+
const end = toBeProcessedUuid.slice(32 - options.unmaskedEndCharacters);
|
|
22
|
+
const maskLength =
|
|
23
|
+
toBeProcessedUuid.length - options.unmaskedStartCharacters - options.unmaskedEndCharacters;
|
|
24
|
+
const tempMaskedUuid = start + options.maskWith.repeat(maskLength) + end;
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
let maskedUuid =
|
|
27
|
+
tempMaskedUuid.slice(0, 8) +
|
|
28
|
+
'-' +
|
|
29
|
+
tempMaskedUuid.slice(8, 12) +
|
|
30
|
+
'-' +
|
|
31
|
+
tempMaskedUuid.slice(12, 16) +
|
|
32
|
+
'-' +
|
|
33
|
+
tempMaskedUuid.slice(16, 20) +
|
|
34
|
+
'-' +
|
|
35
|
+
tempMaskedUuid.slice(20);
|
|
29
36
|
|
|
30
|
-
|
|
31
|
-
|
|
37
|
+
return maskedUuid;
|
|
38
|
+
}
|
|
32
39
|
}
|
|
33
40
|
|
|
34
|
-
module.exports = UuidMask
|
|
41
|
+
module.exports = UuidMask;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "maskdata",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.4",
|
|
4
4
|
"description": "Node module to mask various kinds of data in the required formats",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
12
|
"test": "mocha tests/test*.js --timeout 5000 --exit",
|
|
13
|
-
"coverage": "nyc --reporter=html --reporter=text npm run test"
|
|
13
|
+
"coverage": "nyc --reporter=html --reporter=text npm run test",
|
|
14
|
+
"format": "prettier --write '**/*.{ts,js,json}'"
|
|
14
15
|
},
|
|
15
16
|
"keywords": [
|
|
16
17
|
"mask",
|
|
@@ -27,19 +28,29 @@
|
|
|
27
28
|
"mask object",
|
|
28
29
|
"Get json fields",
|
|
29
30
|
"Set json fields",
|
|
30
|
-
"Replcae json fields"
|
|
31
|
+
"Replcae json fields",
|
|
32
|
+
"email",
|
|
33
|
+
"phone",
|
|
34
|
+
"uuid",
|
|
35
|
+
"string",
|
|
36
|
+
"sensitive",
|
|
37
|
+
"JWT",
|
|
38
|
+
"jwt mask",
|
|
39
|
+
"jwt token",
|
|
40
|
+
"token"
|
|
31
41
|
],
|
|
32
42
|
"author": "sumukha.hs<sumukha.hs369@gmail.com>",
|
|
33
|
-
"homepage": "https://
|
|
43
|
+
"homepage": "https://www.npmjs.com/package/maskdata?activeTab=readme",
|
|
34
44
|
"license": "MIT",
|
|
35
45
|
"dependencies": {
|
|
36
46
|
"lodash": "^4.17.21"
|
|
37
47
|
},
|
|
38
48
|
"devDependencies": {
|
|
39
|
-
"chai": "^4.3.
|
|
49
|
+
"chai": "^4.3.10",
|
|
40
50
|
"mocha": "^10.2.0",
|
|
41
|
-
"mocha-junit-reporter": "^2.2.
|
|
51
|
+
"mocha-junit-reporter": "^2.2.1",
|
|
42
52
|
"nyc": "^15.1.0",
|
|
43
|
-
"
|
|
53
|
+
"prettier": "^3.0.3",
|
|
54
|
+
"typescript": "^5.2.2"
|
|
44
55
|
}
|
|
45
56
|
}
|