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.
@@ -2,10 +2,8 @@
2
2
  const maskData = require('../index');
3
3
  const expect = require('chai').expect;
4
4
 
5
- describe('Masking password', function() {
6
-
7
- describe('Mask with default options', function() {
8
-
5
+ describe('Masking password', function () {
6
+ describe('Mask with default options', function () {
9
7
  // default options are this - let tests fail when defaults change
10
8
  // const defaultPasswordMaskOptions = {
11
9
  // maskWith: "*",
@@ -18,7 +16,7 @@ describe('Masking password', function() {
18
16
  {
19
17
  title: 'test default string',
20
18
  input: '1234-5678-1234-5678',
21
- output: '****************' // equal maxMaskedChars
19
+ output: '****************' // equal maxMaskedChars
22
20
  },
23
21
  {
24
22
  title: 'test string shorter than maxMasked',
@@ -28,24 +26,23 @@ describe('Masking password', function() {
28
26
  {
29
27
  title: 'test longer than maxMasked',
30
28
  input: '1234567890abcdefghijkl',
31
- output: '****************' // equal maxMaskedChars
29
+ output: '****************' // equal maxMaskedChars
32
30
  }
33
- ]
31
+ ];
34
32
 
35
- testData.forEach(({title, input, output}) => {
36
- it(`default mask - ${title}`, function() {
33
+ testData.forEach(({ title, input, output }) => {
34
+ it(`default mask - ${title}`, function () {
37
35
  const masked = maskData.maskPassword(input);
38
36
  expect(masked).to.equal(output, 'masked output does not match expected value');
39
37
  });
40
- })
38
+ });
41
39
  });
42
40
 
43
- describe('Mask with custom options - maskWith, maxMaskedChars', function() {
44
-
41
+ describe('Mask with custom options - maskWith, maxMaskedChars', function () {
45
42
  const maskOptions = {
46
- maskWith: "x",
43
+ maskWith: 'x',
47
44
  maxMaskedCharacters: 6,
48
- unmaskedStartCharacters: 1, // use different numbers for start / end to check correct masking
45
+ unmaskedStartCharacters: 1, // use different numbers for start / end to check correct masking
49
46
  unmaskedEndCharacters: 2
50
47
  };
51
48
 
@@ -65,66 +62,70 @@ describe('Masking password', function() {
65
62
  input: '12',
66
63
  output: '12'
67
64
  }
68
- ]
65
+ ];
69
66
 
70
- testData.forEach(({title, input, output}) => {
71
- it(`custom mask - ${title}`, function() {
67
+ testData.forEach(({ title, input, output }) => {
68
+ it(`custom mask - ${title}`, function () {
72
69
  const masked = maskData.maskPassword(input, maskOptions);
73
70
  expect(masked).to.equal(output, 'masked output does not match expected value');
74
71
  });
75
72
  });
76
73
 
77
- it('custom mask - test with negative unmaskedStartDigits', function() {
74
+ it('custom mask - test with negative unmaskedStartDigits', function () {
78
75
  const negativeStartOption = {
79
76
  maskWith: 'x',
80
77
  maxMaskedCharacters: 6,
81
- unmaskedStartCharacters: -2, // internal set to 0
78
+ unmaskedStartCharacters: -2, // internal set to 0
82
79
  unmaskedEndCharacters: 2
83
- }
84
- const input = '1234-5678-1234-5678'
85
- const output = 'xxxx78'
80
+ };
81
+ const input = '1234-5678-1234-5678';
82
+ const output = 'xxxx78';
86
83
  const masked = maskData.maskPassword(input, negativeStartOption);
87
84
  expect(masked).to.equal(output, 'masked output does not match expected value');
88
85
  });
89
86
 
90
- it('custom mask - test with maxMasked shorter than start + end: No masking done', function() {
87
+ it('custom mask - test with maxMasked shorter than start + end: No masking done', function () {
91
88
  const shortMaxCharsOption = {
92
89
  maskWith: 'x',
93
90
  maxMaskedCharacters: 6,
94
- unmaskedStartCharacters: 4, // 4+4=8 > 6
91
+ unmaskedStartCharacters: 4, // 4+4=8 > 6
95
92
  unmaskedEndCharacters: 4
96
- }
97
- const input = '1234-5678-1234-5678'
98
- const output = '123478'
93
+ };
94
+ const input = '1234-5678-1234-5678';
95
+ const output = '123478';
99
96
  const masked = maskData.maskPassword(input, shortMaxCharsOption);
100
- expect(masked).to.equal(output, 'No masking done because maxMasked(max output characters) shorter than start + end');
97
+ expect(masked).to.equal(
98
+ output,
99
+ 'No masking done because maxMasked(max output characters) shorter than start + end'
100
+ );
101
101
  });
102
102
 
103
- it('custom mask - test with maxMasked equal to start + end: No masking done', function() {
103
+ it('custom mask - test with maxMasked equal to start + end: No masking done', function () {
104
104
  const shortMaxCharsOption = {
105
105
  maskWith: 'x',
106
106
  maxMaskedCharacters: 8,
107
- unmaskedStartCharacters: 4, // 4+4=8
107
+ unmaskedStartCharacters: 4, // 4+4=8
108
108
  unmaskedEndCharacters: 4
109
- }
110
- const input = '1234-abcd-efgh-5678'
111
- const output = '12345678'
109
+ };
110
+ const input = '1234-abcd-efgh-5678';
111
+ const output = '12345678';
112
112
  const masked = maskData.maskPassword(input, shortMaxCharsOption);
113
- expect(masked).to.equal(output, 'No masking done because maxMasked(max output characters) equal to start + end');
113
+ expect(masked).to.equal(
114
+ output,
115
+ 'No masking done because maxMasked(max output characters) equal to start + end'
116
+ );
114
117
  });
115
118
  });
116
119
 
117
- describe('Mask with special input strings', function() {
118
-
120
+ describe('Mask with special input strings', function () {
119
121
  const maskOptions = {
120
- maskWith: "x",
122
+ maskWith: 'x',
121
123
  maxMaskedCharacters: 6,
122
124
  unmaskedStartCharacters: 2,
123
125
  unmaskedEndCharacters: 2
124
126
  };
125
127
 
126
- describe('Mask with special input - input will generate an output', function() {
127
-
128
+ describe('Mask with special input - input will generate an output', function () {
128
129
  // first set with input generating an masked output
129
130
  let testData = [
130
131
  {
@@ -141,19 +142,18 @@ describe('Masking password', function() {
141
142
  title: 'test input as number',
142
143
  input: 12,
143
144
  output: '12'
144
- },
145
- ]
145
+ }
146
+ ];
146
147
 
147
- testData.forEach(({title, input, output}) => {
148
- it(`special input - ${title}`, function() {
148
+ testData.forEach(({ title, input, output }) => {
149
+ it(`special input - ${title}`, function () {
149
150
  const masked = maskData.maskPassword(input, maskOptions);
150
151
  expect(masked).to.equal(output, 'masked output does not match expected value');
151
152
  });
152
153
  });
153
154
  });
154
155
 
155
- describe('Mask with object type input - input won\'t be masked', function() {
156
-
156
+ describe("Mask with object type input - input won't be masked", function () {
157
157
  let testData = [
158
158
  {
159
159
  title: 'test input as array',
@@ -162,15 +162,15 @@ describe('Masking password', function() {
162
162
  },
163
163
  {
164
164
  title: 'test input as object',
165
- input: {a: 'b', x: 'y'},
166
- output: {a: 'b', x: 'y'}
165
+ input: { a: 'b', x: 'y' },
166
+ output: { a: 'b', x: 'y' }
167
167
  }
168
- ]
168
+ ];
169
169
 
170
- testData.forEach(({title, input, output}) => {
171
- it(`special input - ${title}`, function() {
170
+ testData.forEach(({ title, input, output }) => {
171
+ it(`special input - ${title}`, function () {
172
172
  const masked = maskData.maskPassword(input, maskOptions);
173
- expect(masked).to.equal(input, 'input won\'t be masked');
173
+ expect(masked).to.equal(input, "input won't be masked");
174
174
  });
175
175
  });
176
176
  });
@@ -2,10 +2,8 @@
2
2
  const maskData = require('../index');
3
3
  const expect = require('chai').expect;
4
4
 
5
- describe('Masking phone numbers', function() {
6
-
7
- describe('Mask with default options', function() {
8
-
5
+ describe('Masking phone numbers', function () {
6
+ describe('Mask with default options', function () {
9
7
  // default options are this - let tests fail when defaults change
10
8
  // const phoneMaskOptions = {
11
9
  // maskWith: "*",
@@ -29,21 +27,20 @@ describe('Masking phone 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.maskPhone(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, // use different numbers for start / end to check correct masking
43
+ unmaskedStartDigits: 2, // use different numbers for start / end to check correct masking
47
44
  unmaskedEndDigits: 3
48
45
  };
49
46
 
@@ -63,50 +60,48 @@ describe('Masking phone 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.maskPhone(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, // internal set to 0
75
+ unmaskedStartDigits: -2, // internal set to 0
79
76
  unmaskedEndDigits: 3
80
- }
81
- const input = '1234-5678'
82
- const output = 'xxxxxx678'
77
+ };
78
+ const input = '1234-5678';
79
+ const output = 'xxxxxx678';
83
80
  const masked = maskData.maskPhone(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 // internal set to 0
92
- }
93
- const input = '1234-5678'
94
- const output = '12xxxxxxx'
88
+ unmaskedEndDigits: -3 // internal set to 0
89
+ };
90
+ const input = '1234-5678';
91
+ const output = '12xxxxxxx';
95
92
  const masked = maskData.maskPhone(input, negativeEndOption);
96
93
  expect(masked).to.equal(output, 'masked output does not match expected value');
97
94
  });
98
95
  });
99
96
 
100
- describe('Mask with special input strings', function() {
101
-
97
+ describe('Mask with special input strings', function () {
102
98
  const maskOptions = {
103
- maskWith: "x",
99
+ maskWith: 'x',
104
100
  unmaskedStartDigits: 2,
105
101
  unmaskedEndDigits: 2
106
102
  };
107
103
 
108
- describe('Mask with special input - input will generate an output', function() {
109
-
104
+ describe('Mask with special input - input will generate an output', function () {
110
105
  // first set with input generating an masked output
111
106
  let testData = [
112
107
  {
@@ -123,35 +118,34 @@ describe('Masking phone numbers', function() {
123
118
  title: 'test input as number',
124
119
  input: 1234567,
125
120
  output: '12xxx67'
126
- },
127
- ]
121
+ }
122
+ ];
128
123
 
129
- testData.forEach(({title, input, output}) => {
130
- it(`special input - ${title}`, function() {
124
+ testData.forEach(({ title, input, output }) => {
125
+ it(`special input - ${title}`, function () {
131
126
  const masked = maskData.maskPhone(input, maskOptions);
132
127
  expect(masked).to.equal(output, 'masked output does not match expected value');
133
128
  });
134
129
  });
135
130
  });
136
131
 
137
- describe('Mask with special input - input won\'t be masked', function() {
138
-
132
+ describe("Mask with special input - input won't be masked", function () {
139
133
  // set with input generating an error / exception
140
134
  let testData = [
141
135
  {
142
136
  title: 'test input as array',
143
- input: ['12', '34'],
137
+ input: ['12', '34']
144
138
  },
145
139
  {
146
140
  title: 'test input as object',
147
- input: {a: 'b', x: 'y'},
141
+ input: { a: 'b', x: 'y' }
148
142
  }
149
- ]
143
+ ];
150
144
 
151
- testData.forEach(({title, input, output}) => {
152
- it(`special input - ${title}`, function() {
145
+ testData.forEach(({ title, input, output }) => {
146
+ it(`special input - ${title}`, function () {
153
147
  const masked = maskData.maskPhone(input, maskOptions);
154
- expect(masked).to.equal(input, 'input won\'t be masked');
148
+ expect(masked).to.equal(input, "input won't be masked");
155
149
  });
156
150
  });
157
151
  });
@@ -2,8 +2,7 @@
2
2
  const maskData = require('../index');
3
3
  const expect = require('chai').expect;
4
4
 
5
- describe('Masking strings', function() {
6
-
5
+ describe('Masking strings', function () {
7
6
  // common strings without output - used as base for all tests below
8
7
  let testData = [
9
8
  {
@@ -21,10 +20,9 @@ describe('Masking strings', function() {
21
20
  input: 'this is a\nstring with newline',
22
21
  output: ''
23
22
  }
24
- ]
25
-
26
- describe('Mask with default options', function() {
23
+ ];
27
24
 
25
+ describe('Mask with default options', function () {
28
26
  // default options are this - let tests fail when defaults change
29
27
  // const defaultStringMaskOptions = {
30
28
  // maskWith: "*",
@@ -40,19 +38,18 @@ describe('Masking strings', function() {
40
38
  localTestData[1].output = localTestData[1].input;
41
39
  localTestData[2].output = localTestData[2].input;
42
40
 
43
- localTestData.forEach(({title, input, output}) => {
44
- it(`default mask - ${title}`, function() {
41
+ localTestData.forEach(({ title, input, output }) => {
42
+ it(`default mask - ${title}`, function () {
45
43
  const masked = maskData.maskString(input);
46
44
  expect(masked).to.equal(output, 'masked output does not match expected value');
47
45
  });
48
- })
46
+ });
49
47
  });
50
48
 
51
- describe('Mask with custom options - maskWith, maskSpace', function() {
52
-
49
+ describe('Mask with custom options - maskWith, maskSpace', function () {
53
50
  // only maskWith and maskSpace set
54
51
  const maskOptions = {
55
- maskWith: "?",
52
+ maskWith: '?',
56
53
  maskOnlyFirstOccurance: false,
57
54
  values: [],
58
55
  maskAll: false,
@@ -65,19 +62,18 @@ describe('Masking strings', function() {
65
62
  localTestData[1].output = localTestData[1].input;
66
63
  localTestData[2].output = localTestData[2].input;
67
64
 
68
- localTestData.forEach(({title, input, output}) => {
69
- it(`custom mask - ${title}`, function() {
65
+ localTestData.forEach(({ title, input, output }) => {
66
+ it(`custom mask - ${title}`, function () {
70
67
  const masked = maskData.maskString(input, maskOptions);
71
68
  expect(masked).to.equal(output, 'masked output does not match expected value');
72
69
  });
73
70
  });
74
71
  });
75
72
 
76
- describe('Mask with custom options - maskWith, maskAll, no spaces', function() {
77
-
73
+ describe('Mask with custom options - maskWith, maskAll, no spaces', function () {
78
74
  // only maskWith, maskAll set
79
75
  const maskOptions = {
80
- maskWith: "?",
76
+ maskWith: '?',
81
77
  maskOnlyFirstOccurance: false,
82
78
  values: [],
83
79
  maskAll: true,
@@ -86,21 +82,20 @@ describe('Masking strings', function() {
86
82
 
87
83
  const localTestData = JSON.parse(JSON.stringify(testData));
88
84
  localTestData[0].output = '???? ?? ? ?????????? ??????';
89
- localTestData[1].output = '?'.repeat(localTestData[1].input.length); // no space here
85
+ localTestData[1].output = '?'.repeat(localTestData[1].input.length); // no space here
90
86
  localTestData[2].output = '???? ?? ???????? ???? ???????';
91
87
 
92
- localTestData.forEach(({title, input, output}) => {
93
- it(`custom mask - ${title}`, function() {
88
+ localTestData.forEach(({ title, input, output }) => {
89
+ it(`custom mask - ${title}`, function () {
94
90
  const masked = maskData.maskString(input, maskOptions);
95
91
  expect(masked).to.equal(output, 'masked output does not match expected value');
96
92
  });
97
93
  });
98
94
  });
99
95
 
100
- describe('Mask with custom options - maskWith multiple chars, maskAll, maskSpace', function() {
101
-
96
+ describe('Mask with custom options - maskWith multiple chars, maskAll, maskSpace', function () {
102
97
  // only maskWith, maskAll set
103
- const maskChar = "??"; // mask every char in input string with two chars in output
98
+ const maskChar = '??'; // mask every char in input string with two chars in output
104
99
  const maskOptions = {
105
100
  maskWith: maskChar,
106
101
  maskOnlyFirstOccurance: false,
@@ -114,18 +109,17 @@ describe('Masking strings', function() {
114
109
  localTestData[1].output = maskChar.repeat(localTestData[1].input.length);
115
110
  localTestData[2].output = maskChar.repeat(localTestData[2].input.length);
116
111
 
117
- localTestData.forEach(({title, input, output}) => {
118
- it(`custom mask - ${title}`, function() {
112
+ localTestData.forEach(({ title, input, output }) => {
113
+ it(`custom mask - ${title}`, function () {
119
114
  const masked = maskData.maskString(input, maskOptions);
120
115
  expect(masked).to.equal(output, 'masked output does not match expected value');
121
116
  });
122
117
  });
123
118
  });
124
119
 
125
- describe('Mask with custom options - values and maskAll set, no spaces', function() {
126
-
120
+ describe('Mask with custom options - values and maskAll set, no spaces', function () {
127
121
  const maskOptions = {
128
- maskWith: "x",
122
+ maskWith: 'x',
129
123
  maskOnlyFirstOccurance: false,
130
124
  values: ['is', 'ing'],
131
125
  maskAll: true,
@@ -135,21 +129,20 @@ describe('Masking strings', function() {
135
129
  // expected: values ignored and all masked, space remains
136
130
  const localTestData = JSON.parse(JSON.stringify(testData));
137
131
  localTestData[0].output = 'xxxx xx x xxxxxxxxxx xxxxxx';
138
- localTestData[1].output = 'x'.repeat(localTestData[1].input.length); // no spaces here
132
+ localTestData[1].output = 'x'.repeat(localTestData[1].input.length); // no spaces here
139
133
  localTestData[2].output = 'xxxx xx xxxxxxxx xxxx xxxxxxx';
140
134
 
141
- localTestData.forEach(({title, input, output}) => {
142
- it(`custom mask - ${title}`, function() {
135
+ localTestData.forEach(({ title, input, output }) => {
136
+ it(`custom mask - ${title}`, function () {
143
137
  const masked = maskData.maskString(input, maskOptions);
144
138
  expect(masked).to.equal(output, 'masked output does not match expected value');
145
139
  });
146
140
  });
147
141
  });
148
142
 
149
- describe('Mask with custom options - values and all occurrences', function() {
150
-
143
+ describe('Mask with custom options - values and all occurrences', function () {
151
144
  const maskOptions = {
152
- maskWith: "*",
145
+ maskWith: '*',
153
146
  maskOnlyFirstOccurance: false,
154
147
  values: ['is', 'ing'],
155
148
  maskAll: false,
@@ -161,18 +154,17 @@ describe('Masking strings', function() {
161
154
  localTestData[1].output = 'th****astr***';
162
155
  localTestData[2].output = 'th** ** a\nstr*** with newline';
163
156
 
164
- localTestData.forEach(({title, input, output}) => {
165
- it(`custom mask - ${title}`, function() {
157
+ localTestData.forEach(({ title, input, output }) => {
158
+ it(`custom mask - ${title}`, function () {
166
159
  const masked = maskData.maskString(input, maskOptions);
167
160
  expect(masked).to.equal(output, 'masked output does not match expected value');
168
161
  });
169
162
  });
170
163
  });
171
164
 
172
- describe('Mask with custom options - values and first occureances', function() {
173
-
165
+ describe('Mask with custom options - values and first occureances', function () {
174
166
  const maskOptions = {
175
- maskWith: "*",
167
+ maskWith: '*',
176
168
  maskOnlyFirstOccurance: true,
177
169
  values: ['is', 'ing'],
178
170
  maskAll: false,
@@ -184,26 +176,24 @@ describe('Masking strings', function() {
184
176
  localTestData[1].output = 'th**isastr***';
185
177
  localTestData[2].output = 'th** is a\nstr*** with newline';
186
178
 
187
- localTestData.forEach(({title, input, output}) => {
188
- it(`custom mask - ${title}`, function() {
179
+ localTestData.forEach(({ title, input, output }) => {
180
+ it(`custom mask - ${title}`, function () {
189
181
  const masked = maskData.maskString(input, maskOptions);
190
182
  expect(masked).to.equal(output, 'masked output does not match expected value');
191
183
  });
192
184
  });
193
185
  });
194
186
 
195
- describe('Mask with special input strings', function() {
196
-
187
+ describe('Mask with special input strings', function () {
197
188
  const maskOptions = {
198
- maskWith: "x",
189
+ maskWith: 'x',
199
190
  maskOnlyFirstOccurance: true,
200
191
  values: [],
201
192
  maskAll: true,
202
193
  maskSpace: true
203
194
  };
204
195
 
205
- describe('Mask with special input - input will generate an output', function() {
206
-
196
+ describe('Mask with special input - input will generate an output', function () {
207
197
  // first set with input generating an masked output
208
198
  let testData = [
209
199
  {
@@ -220,34 +210,33 @@ describe('Masking strings', function() {
220
210
  title: 'test input as number',
221
211
  input: 12,
222
212
  output: 'xx'
223
- },
224
- ]
213
+ }
214
+ ];
225
215
 
226
- testData.forEach(({title, input, output}) => {
227
- it(`special input - ${title}`, function() {
216
+ testData.forEach(({ title, input, output }) => {
217
+ it(`special input - ${title}`, function () {
228
218
  const masked = maskData.maskString(input, maskOptions);
229
219
  expect(masked).to.equal(output, 'masked output does not match expected value');
230
220
  });
231
221
  });
232
222
  });
233
223
 
234
- describe('Mask with improper input - input won\'t be masked', function() {
235
-
224
+ describe("Mask with improper input - input won't be masked", function () {
236
225
  let testData = [
237
226
  {
238
227
  title: 'test input as array',
239
- input: ['12', 'ab'],
228
+ input: ['12', 'ab']
240
229
  },
241
230
  {
242
231
  title: 'test input as object',
243
- input: {a: 'b', x: 'y'},
232
+ input: { a: 'b', x: 'y' }
244
233
  }
245
- ]
234
+ ];
246
235
 
247
- testData.forEach(({title, input, output}) => {
248
- it(`special input - ${title}`, function() {
236
+ testData.forEach(({ title, input, output }) => {
237
+ it(`special input - ${title}`, function () {
249
238
  const masked = maskData.maskString(input, maskOptions);
250
- expect(masked).to.equal(input, 'input won\'t be masked');
239
+ expect(masked).to.equal(input, "input won't be masked");
251
240
  });
252
241
  });
253
242
  });