maskdata 1.2.1 → 1.2.3
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 +68 -149
- package/index.d.ts +76 -72
- package/index.js +6 -3
- package/lib/ExceptionsHandler/BadOption.js +2 -2
- package/lib/helpers/Constants.js +47 -48
- package/lib/helpers/MaskHelper.js +119 -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 +163 -87
- 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 +14 -7
- package/tests/scribble.js +298 -126
- package/tests/testCard.js +35 -40
- package/tests/testEmail.js +46 -53
- package/tests/testJsonFields.js +668 -231
- package/tests/testJsonGetSet.js +54 -21
- 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
package/tests/testCard.js
CHANGED
|
@@ -2,10 +2,8 @@
|
|
|
2
2
|
const maskData = require('../index');
|
|
3
3
|
const expect = require('chai').expect;
|
|
4
4
|
|
|
5
|
-
describe('Masking card numbers', function() {
|
|
6
|
-
|
|
7
|
-
describe('Mask with default options', function() {
|
|
8
|
-
|
|
5
|
+
describe('Masking card numbers', function () {
|
|
6
|
+
describe('Mask with default options', function () {
|
|
9
7
|
// default options are this - let tests fail when defaults change
|
|
10
8
|
// const defaultCardMaskOptions = {
|
|
11
9
|
// maskWith: '*',
|
|
@@ -29,21 +27,20 @@ describe('Masking card numbers', function() {
|
|
|
29
27
|
input: '1234',
|
|
30
28
|
output: '1234'
|
|
31
29
|
}
|
|
32
|
-
]
|
|
30
|
+
];
|
|
33
31
|
|
|
34
|
-
testData.forEach(({title, input, output}) => {
|
|
35
|
-
it(`default mask - ${title}`, function() {
|
|
32
|
+
testData.forEach(({ title, input, output }) => {
|
|
33
|
+
it(`default mask - ${title}`, function () {
|
|
36
34
|
const masked = maskData.maskCard(input);
|
|
37
35
|
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
38
36
|
});
|
|
39
|
-
})
|
|
37
|
+
});
|
|
40
38
|
});
|
|
41
39
|
|
|
42
|
-
describe('Mask with custom options', function() {
|
|
43
|
-
|
|
40
|
+
describe('Mask with custom options', function () {
|
|
44
41
|
const maskOptions = {
|
|
45
42
|
maskWith: 'x',
|
|
46
|
-
unmaskedStartDigits: 2,
|
|
43
|
+
unmaskedStartDigits: 2, // use different numbers for start / end to check correct masking
|
|
47
44
|
unmaskedEndDigits: 3
|
|
48
45
|
};
|
|
49
46
|
|
|
@@ -63,74 +60,72 @@ describe('Masking card numbers', function() {
|
|
|
63
60
|
input: '1234',
|
|
64
61
|
output: '1234'
|
|
65
62
|
}
|
|
66
|
-
]
|
|
63
|
+
];
|
|
67
64
|
|
|
68
|
-
testData.forEach(({title, input, output}) => {
|
|
69
|
-
it(`custom mask - ${title}`, function() {
|
|
65
|
+
testData.forEach(({ title, input, output }) => {
|
|
66
|
+
it(`custom mask - ${title}`, function () {
|
|
70
67
|
const masked = maskData.maskCard(input, maskOptions);
|
|
71
68
|
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
72
69
|
});
|
|
73
70
|
});
|
|
74
71
|
|
|
75
|
-
it('test with negative unmaskedStartDigits', function() {
|
|
72
|
+
it('test with negative unmaskedStartDigits', function () {
|
|
76
73
|
const negativeStartOption = {
|
|
77
74
|
maskWith: 'x',
|
|
78
|
-
unmaskedStartDigits: -2,
|
|
75
|
+
unmaskedStartDigits: -2, // internal set to 0
|
|
79
76
|
unmaskedEndDigits: 3
|
|
80
|
-
}
|
|
81
|
-
const input = '1234-5678-1234-5678'
|
|
82
|
-
const output = 'xxxx-xxxx-xxxx-x678'
|
|
77
|
+
};
|
|
78
|
+
const input = '1234-5678-1234-5678';
|
|
79
|
+
const output = 'xxxx-xxxx-xxxx-x678';
|
|
83
80
|
const masked = maskData.maskCard(input, negativeStartOption);
|
|
84
81
|
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
85
82
|
});
|
|
86
83
|
|
|
87
|
-
it('test with negative unmaskedEndDigits', function() {
|
|
84
|
+
it('test with negative unmaskedEndDigits', function () {
|
|
88
85
|
const negativeEndOption = {
|
|
89
86
|
maskWith: 'x',
|
|
90
87
|
unmaskedStartDigits: 2,
|
|
91
|
-
unmaskedEndDigits: -3
|
|
92
|
-
}
|
|
93
|
-
const input = '1234-5678-1234-5678'
|
|
94
|
-
const output = '12xx-xxxx-xxxx-xxxx'
|
|
88
|
+
unmaskedEndDigits: -3 // internal set to 0
|
|
89
|
+
};
|
|
90
|
+
const input = '1234-5678-1234-5678';
|
|
91
|
+
const output = '12xx-xxxx-xxxx-xxxx';
|
|
95
92
|
const masked = maskData.maskCard(input, negativeEndOption);
|
|
96
93
|
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
97
94
|
});
|
|
98
95
|
|
|
99
|
-
it('test with 0 unmasked start and end digits', function() {
|
|
96
|
+
it('test with 0 unmasked start and end digits', function () {
|
|
100
97
|
const _0UnmaskedOption = {
|
|
101
98
|
maskWith: 'x',
|
|
102
99
|
unmaskedStartDigits: 0,
|
|
103
100
|
unmaskedEndDigits: 0
|
|
104
|
-
}
|
|
105
|
-
const input = '1234-5678-1234-5678'
|
|
106
|
-
const output = 'xxxx-xxxx-xxxx-xxxx'
|
|
101
|
+
};
|
|
102
|
+
const input = '1234-5678-1234-5678';
|
|
103
|
+
const output = 'xxxx-xxxx-xxxx-xxxx';
|
|
107
104
|
const masked = maskData.maskCard(input, _0UnmaskedOption);
|
|
108
105
|
expect(masked).to.equal(output);
|
|
109
106
|
});
|
|
110
107
|
|
|
111
|
-
it('test with non number card data', function() {
|
|
108
|
+
it('test with non number card data', function () {
|
|
112
109
|
const cardMaskOptions = {
|
|
113
110
|
maskWith: 'x',
|
|
114
111
|
unmaskedStartDigits: 1,
|
|
115
112
|
unmaskedEndDigits: 1
|
|
116
|
-
}
|
|
117
|
-
const input = 'm1234-5678-1234-5678'
|
|
118
|
-
const output = 'm1xxx-xxxx-xxxx-xxx8'
|
|
113
|
+
};
|
|
114
|
+
const input = 'm1234-5678-1234-5678';
|
|
115
|
+
const output = 'm1xxx-xxxx-xxxx-xxx8';
|
|
119
116
|
const masked = maskData.maskCard(input, cardMaskOptions);
|
|
120
117
|
expect(masked).to.equal(output);
|
|
121
118
|
});
|
|
122
119
|
});
|
|
123
120
|
|
|
124
|
-
describe('Mask with special input strings', function() {
|
|
125
|
-
|
|
121
|
+
describe('Mask with special input strings', function () {
|
|
126
122
|
const maskOptions = {
|
|
127
|
-
maskWith:
|
|
123
|
+
maskWith: 'x',
|
|
128
124
|
unmaskedStartDigits: 2,
|
|
129
125
|
unmaskedEndDigits: 3
|
|
130
126
|
};
|
|
131
127
|
|
|
132
|
-
describe('Mask with special input - input will generate an output', function() {
|
|
133
|
-
|
|
128
|
+
describe('Mask with special input - input will generate an output', function () {
|
|
134
129
|
// first set with input generating an masked output
|
|
135
130
|
let testData = [
|
|
136
131
|
{
|
|
@@ -143,10 +138,10 @@ describe('Masking card numbers', function() {
|
|
|
143
138
|
input: null,
|
|
144
139
|
output: null
|
|
145
140
|
}
|
|
146
|
-
]
|
|
141
|
+
];
|
|
147
142
|
|
|
148
|
-
testData.forEach(({title, input, output}) => {
|
|
149
|
-
it(`special input - ${title}`, function() {
|
|
143
|
+
testData.forEach(({ title, input, output }) => {
|
|
144
|
+
it(`special input - ${title}`, function () {
|
|
150
145
|
const masked = maskData.maskCard(input, maskOptions);
|
|
151
146
|
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
152
147
|
});
|
package/tests/testEmail.js
CHANGED
|
@@ -3,10 +3,8 @@ const maskData = require('../index');
|
|
|
3
3
|
const BadOption = require('../lib/ExceptionsHandler/BadOption');
|
|
4
4
|
const expect = require('chai').expect;
|
|
5
5
|
|
|
6
|
-
describe('Masking email addresses', function() {
|
|
7
|
-
|
|
8
|
-
describe('Mask with default options', function() {
|
|
9
|
-
|
|
6
|
+
describe('Masking email addresses', function () {
|
|
7
|
+
describe('Mask with default options', function () {
|
|
10
8
|
// default options are this - let tests fail when defaults change
|
|
11
9
|
// const defaultCardMaskOptions = {
|
|
12
10
|
// maskWith: '*',
|
|
@@ -46,22 +44,21 @@ describe('Masking email addresses', function() {
|
|
|
46
44
|
input: 'user@x',
|
|
47
45
|
output: 'use*@x'
|
|
48
46
|
}
|
|
49
|
-
]
|
|
47
|
+
];
|
|
50
48
|
|
|
51
|
-
testData.forEach(({title, input, output}) => {
|
|
52
|
-
it(`default mask - ${title}`, function() {
|
|
49
|
+
testData.forEach(({ title, input, output }) => {
|
|
50
|
+
it(`default mask - ${title}`, function () {
|
|
53
51
|
const masked = maskData.maskEmail2(input);
|
|
54
52
|
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
55
53
|
});
|
|
56
|
-
})
|
|
54
|
+
});
|
|
57
55
|
});
|
|
58
56
|
|
|
59
|
-
describe('Mask with custom options (char, before, after)', function() {
|
|
60
|
-
|
|
57
|
+
describe('Mask with custom options (char, before, after)', function () {
|
|
61
58
|
const maskOptions = {
|
|
62
59
|
maskWith: 'x',
|
|
63
60
|
unmaskedStartCharactersBeforeAt: 4,
|
|
64
|
-
unmaskedEndCharactersAfterAt: 6,
|
|
61
|
+
unmaskedEndCharactersAfterAt: 6, // full tld and part of sld
|
|
65
62
|
maskAtTheRate: false
|
|
66
63
|
};
|
|
67
64
|
|
|
@@ -71,22 +68,21 @@ describe('Masking email addresses', function() {
|
|
|
71
68
|
input: 'testuser@dummy.org',
|
|
72
69
|
output: 'testxxxx@xxxmy.org'
|
|
73
70
|
}
|
|
74
|
-
]
|
|
71
|
+
];
|
|
75
72
|
|
|
76
|
-
testData.forEach(({title, input, output}) => {
|
|
77
|
-
it(`default mask - ${title}`, function() {
|
|
73
|
+
testData.forEach(({ title, input, output }) => {
|
|
74
|
+
it(`default mask - ${title}`, function () {
|
|
78
75
|
const masked = maskData.maskEmail2(input, maskOptions);
|
|
79
76
|
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
80
77
|
});
|
|
81
|
-
})
|
|
78
|
+
});
|
|
82
79
|
});
|
|
83
80
|
|
|
84
|
-
describe('Mask with custom options (maskAtTheRate)', function() {
|
|
85
|
-
|
|
81
|
+
describe('Mask with custom options (maskAtTheRate)', function () {
|
|
86
82
|
const maskOptions = {
|
|
87
83
|
maskWith: '*',
|
|
88
84
|
unmaskedStartCharactersBeforeAt: 4,
|
|
89
|
-
unmaskedEndCharactersAfterAt: 6,
|
|
85
|
+
unmaskedEndCharactersAfterAt: 6, // full tld and part of sld
|
|
90
86
|
maskAtTheRate: true
|
|
91
87
|
};
|
|
92
88
|
|
|
@@ -99,31 +95,31 @@ describe('Masking email addresses', function() {
|
|
|
99
95
|
{
|
|
100
96
|
title: 'test user and domain part to short',
|
|
101
97
|
input: 'we@a.de',
|
|
102
|
-
output: 'we*a.de'
|
|
98
|
+
output: 'we*a.de' // before and after are shorter than visible, only @ replaced
|
|
103
99
|
},
|
|
104
100
|
{
|
|
105
101
|
title: 'test user part to short',
|
|
106
102
|
input: 'we@dummy.org',
|
|
107
|
-
output: 'we****my.org'
|
|
103
|
+
output: 'we****my.org' // before and after are shorter than visible, only @ replaced
|
|
108
104
|
},
|
|
109
105
|
{
|
|
110
106
|
title: 'test domain part to short',
|
|
111
107
|
input: 'testuser@a.de',
|
|
112
|
-
output: 'test*****a.de'
|
|
108
|
+
output: 'test*****a.de' // before and after are shorter than visible, only @ replaced
|
|
113
109
|
}
|
|
114
|
-
]
|
|
110
|
+
];
|
|
115
111
|
|
|
116
|
-
testData.forEach(({title, input, output}) => {
|
|
117
|
-
it(`custom mask - ${title}`, function() {
|
|
112
|
+
testData.forEach(({ title, input, output }) => {
|
|
113
|
+
it(`custom mask - ${title}`, function () {
|
|
118
114
|
const masked = maskData.maskEmail2(input, maskOptions);
|
|
119
115
|
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
120
116
|
});
|
|
121
117
|
});
|
|
122
118
|
|
|
123
|
-
it('custom mask - negative start digits', function() {
|
|
119
|
+
it('custom mask - negative start digits', function () {
|
|
124
120
|
const negativeStartOptions = {
|
|
125
121
|
maskWith: '*',
|
|
126
|
-
unmaskedStartCharactersBeforeAt: -1,
|
|
122
|
+
unmaskedStartCharactersBeforeAt: -1, // replaced with 0 internally
|
|
127
123
|
unmaskedEndCharactersAfterAt: 1,
|
|
128
124
|
maskAtTheRate: false
|
|
129
125
|
};
|
|
@@ -133,10 +129,10 @@ describe('Masking email addresses', function() {
|
|
|
133
129
|
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
134
130
|
});
|
|
135
131
|
|
|
136
|
-
it('custom mask - negative end digits', function() {
|
|
132
|
+
it('custom mask - negative end digits', function () {
|
|
137
133
|
const negativeEndOptions = {
|
|
138
134
|
maskWith: '*',
|
|
139
|
-
unmaskedStartCharactersBeforeAt: 1,
|
|
135
|
+
unmaskedStartCharactersBeforeAt: 1, // replaced with 0 internally
|
|
140
136
|
unmaskedEndCharactersAfterAt: -1,
|
|
141
137
|
maskAtTheRate: false
|
|
142
138
|
};
|
|
@@ -147,40 +143,38 @@ describe('Masking email addresses', function() {
|
|
|
147
143
|
});
|
|
148
144
|
});
|
|
149
145
|
|
|
150
|
-
describe('test error cases for email addresses', function() {
|
|
151
|
-
|
|
146
|
+
describe('test error cases for email addresses', function () {
|
|
152
147
|
let testData = [
|
|
153
148
|
{
|
|
154
149
|
title: 'test no email address at all',
|
|
155
150
|
input: 'user-dummy.org',
|
|
156
151
|
output: 'use*@x'
|
|
157
152
|
}
|
|
158
|
-
]
|
|
153
|
+
];
|
|
159
154
|
|
|
160
|
-
testData.forEach(({title, input, output}) => {
|
|
161
|
-
it(`default mask - ${title}`, function() {
|
|
155
|
+
testData.forEach(({ title, input, output }) => {
|
|
156
|
+
it(`default mask - ${title}`, function () {
|
|
162
157
|
try {
|
|
163
158
|
const masked = maskData.maskEmail2(input);
|
|
164
159
|
expect.fail('maskEmail2 should throw error');
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
|
|
160
|
+
} catch (e) {
|
|
161
|
+
expect(e)
|
|
162
|
+
.to.be.a('string')
|
|
163
|
+
.and.match(/Bad config.*Email must.*@/);
|
|
168
164
|
}
|
|
169
165
|
});
|
|
170
|
-
})
|
|
166
|
+
});
|
|
171
167
|
});
|
|
172
168
|
|
|
173
|
-
describe('Mask with special input strings', function() {
|
|
174
|
-
|
|
169
|
+
describe('Mask with special input strings', function () {
|
|
175
170
|
const maskOptions = {
|
|
176
|
-
maskWith:
|
|
171
|
+
maskWith: 'x',
|
|
177
172
|
unmaskedStartCharactersBeforeAt: 1,
|
|
178
173
|
unmaskedEndCharactersAfterAt: 1,
|
|
179
174
|
maskAtTheRate: false
|
|
180
175
|
};
|
|
181
176
|
|
|
182
|
-
describe('Mask with special input - input will generate an output', function() {
|
|
183
|
-
|
|
177
|
+
describe('Mask with special input - input will generate an output', function () {
|
|
184
178
|
// first set with input generating an masked output
|
|
185
179
|
let testData = [
|
|
186
180
|
{
|
|
@@ -193,35 +187,34 @@ describe('Masking email addresses', function() {
|
|
|
193
187
|
input: null,
|
|
194
188
|
output: null
|
|
195
189
|
}
|
|
196
|
-
]
|
|
190
|
+
];
|
|
197
191
|
|
|
198
|
-
testData.forEach(({title, input, output}) => {
|
|
199
|
-
it(`special input - ${title}`, function() {
|
|
192
|
+
testData.forEach(({ title, input, output }) => {
|
|
193
|
+
it(`special input - ${title}`, function () {
|
|
200
194
|
const masked = maskData.maskEmail2(input, maskOptions);
|
|
201
195
|
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
202
196
|
});
|
|
203
197
|
});
|
|
204
198
|
});
|
|
205
199
|
|
|
206
|
-
describe('Mask with non string input - input will not be masked', function() {
|
|
207
|
-
|
|
200
|
+
describe('Mask with non string input - input will not be masked', function () {
|
|
208
201
|
let testData = [
|
|
209
202
|
{
|
|
210
203
|
title: 'test input as number',
|
|
211
|
-
input: 12
|
|
204
|
+
input: 12
|
|
212
205
|
},
|
|
213
206
|
{
|
|
214
207
|
title: 'test input as array',
|
|
215
|
-
input: ['12']
|
|
208
|
+
input: ['12']
|
|
216
209
|
},
|
|
217
210
|
{
|
|
218
211
|
title: 'test input as object',
|
|
219
|
-
input: {a: 'b', x: 'y'}
|
|
212
|
+
input: { a: 'b', x: 'y' }
|
|
220
213
|
}
|
|
221
|
-
]
|
|
214
|
+
];
|
|
222
215
|
|
|
223
|
-
testData.forEach(({title, input, output}) => {
|
|
224
|
-
it(`special input - ${title}`, function() {
|
|
216
|
+
testData.forEach(({ title, input, output }) => {
|
|
217
|
+
it(`special input - ${title}`, function () {
|
|
225
218
|
const masked = maskData.maskEmail2(input, maskOptions);
|
|
226
219
|
expect(masked).to.equal(input, 'Improper input');
|
|
227
220
|
});
|