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.
@@ -2,10 +2,9 @@ const BadOption = require('../ExceptionsHandler/BadOption');
2
2
  const Constants = require('./Constants');
3
3
 
4
4
  class MaskHelper {
5
-
6
5
  static mapWithDefaultValues(options, defaultOptions) {
7
- for(let key of Object.keys(defaultOptions)) {
8
- if(options[key] === undefined || options[key] === null) {
6
+ for (let key of Object.keys(defaultOptions)) {
7
+ if (options[key] === undefined || options[key] === null) {
9
8
  options[key] = defaultOptions[key];
10
9
  }
11
10
  }
@@ -14,30 +13,35 @@ class MaskHelper {
14
13
 
15
14
  static validatePasswordOptions(options) {
16
15
  let reasons = [];
17
- try{
16
+ try {
18
17
  options.maxMaskedCharacters = parseInt(options.maxMaskedCharacters);
19
18
  options.unmaskedStartCharacters = parseInt(options.unmaskedStartCharacters);
20
19
  options.unmaskedEndCharacters = parseInt(options.unmaskedEndCharacters);
21
- if(isNaN(options.maxMaskedCharacters) || isNaN(options.unmaskedStartCharacters) ||
22
- isNaN(options.unmaskedEndCharacters)) {
20
+ if (
21
+ isNaN(options.maxMaskedCharacters) ||
22
+ isNaN(options.unmaskedStartCharacters) ||
23
+ isNaN(options.unmaskedEndCharacters)
24
+ ) {
23
25
  throw Error();
24
- };
25
- } catch(err) {
26
- reasons.push('maxMaskedCharacters, unmaskedStartCharacters and unmaskedEndCharacters must be positive integer');
26
+ }
27
+ } catch (err) {
28
+ reasons.push(
29
+ 'maxMaskedCharacters, unmaskedStartCharacters and unmaskedEndCharacters must be positive integer'
30
+ );
27
31
  }
28
- if(options.maxMaskedCharacters < 0) {
32
+ if (options.maxMaskedCharacters < 0) {
29
33
  options.maxMaskedCharacters = 16;
30
34
  }
31
- if(options.unmaskedStartCharacters < 0) {
35
+ if (options.unmaskedStartCharacters < 0) {
32
36
  options.unmaskedStartCharacters = 0;
33
37
  }
34
- if(options.unmaskedEndCharacters < 0) {
38
+ if (options.unmaskedEndCharacters < 0) {
35
39
  options.unmaskedEndCharacters = 0;
36
40
  }
37
- if((!options.maskWith) || options.maskWith.toString().length <= 0) {
41
+ if (!options.maskWith || options.maskWith.toString().length <= 0) {
38
42
  options.maskWith = '*';
39
43
  }
40
- if(reasons.length > 0) {
44
+ if (reasons.length > 0) {
41
45
  const badOptions = new BadOption('Password mask configuration', reasons);
42
46
  badOptions.throwBadOptionException();
43
47
  }
@@ -45,25 +49,25 @@ class MaskHelper {
45
49
 
46
50
  static validatePhoneOptions(options) {
47
51
  let reasons = [];
48
- try{
52
+ try {
49
53
  options.unmaskedStartDigits = parseInt(options.unmaskedStartDigits);
50
54
  options.unmaskedEndDigits = parseInt(options.unmaskedEndDigits);
51
- if(isNaN(options.unmaskedStartDigits) || isNaN(options.unmaskedEndDigits)){
55
+ if (isNaN(options.unmaskedStartDigits) || isNaN(options.unmaskedEndDigits)) {
52
56
  throw Error();
53
- };
54
- }catch(err) {
57
+ }
58
+ } catch (err) {
55
59
  reasons.push('unmaskedStartDigits and unmaskedEndDigits must be positive integers');
56
60
  }
57
- if(options.unmaskedStartDigits < 0) {
61
+ if (options.unmaskedStartDigits < 0) {
58
62
  options.unmaskedStartDigits = 0;
59
63
  }
60
- if(options.unmaskedEndDigits < 0) {
64
+ if (options.unmaskedEndDigits < 0) {
61
65
  options.unmaskedEndDigits = 0;
62
66
  }
63
- if((!options.maskWith) || options.maskWith.toString().length <= 0) {
67
+ if (!options.maskWith || options.maskWith.toString().length <= 0) {
64
68
  options.maskWith = '*';
65
69
  }
66
- if(reasons.length > 0) {
70
+ if (reasons.length > 0) {
67
71
  const badOptions = new BadOption('Phone mask configuration', reasons);
68
72
  badOptions.throwBadOptionException();
69
73
  }
@@ -71,72 +75,87 @@ class MaskHelper {
71
75
 
72
76
  static validateEmailOptions(email, options) {
73
77
  let reasons = [];
74
- if(!email || email.indexOf('@') < 0) {
78
+ if (!email || email.indexOf('@') < 0) {
75
79
  reasons.push(`Email must contain one '@'`);
76
80
  }
77
- try{
81
+ try {
78
82
  options.unmaskedStartCharacters = parseInt(options.unmaskedStartCharacters);
79
83
  options.unmaskedEndCharacters = parseInt(options.unmaskedEndCharacters);
80
- options.maxMaskedCharactersBeforeAtTheRate = parseInt(options.maxMaskedCharactersBeforeAtTheRate);
81
- options.maxMaskedCharactersAfterAtTheRate = parseInt(options.maxMaskedCharactersAfterAtTheRate);
82
- if(isNaN(options.unmaskedStartCharacters) || isNaN(options.unmaskedEndCharacters) ||
83
- isNaN(options.maxMaskedCharactersBeforeAtTheRate) || isNaN(options.maxMaskedCharactersAfterAtTheRate)){
84
+ options.maxMaskedCharactersBeforeAtTheRate = parseInt(
85
+ options.maxMaskedCharactersBeforeAtTheRate
86
+ );
87
+ options.maxMaskedCharactersAfterAtTheRate = parseInt(
88
+ options.maxMaskedCharactersAfterAtTheRate
89
+ );
90
+ if (
91
+ isNaN(options.unmaskedStartCharacters) ||
92
+ isNaN(options.unmaskedEndCharacters) ||
93
+ isNaN(options.maxMaskedCharactersBeforeAtTheRate) ||
94
+ isNaN(options.maxMaskedCharactersAfterAtTheRate)
95
+ ) {
84
96
  throw Error();
85
- };
86
- }catch(err) {
87
- reasons.push('unmaskedStartCharacters, unmaskedEndCharacters, maxMaskedCharactersBeforeAtTheRate and maxMaskedCharactersAfterAtTheRate must be positive integers');
97
+ }
98
+ } catch (err) {
99
+ reasons.push(
100
+ 'unmaskedStartCharacters, unmaskedEndCharacters, maxMaskedCharactersBeforeAtTheRate and maxMaskedCharactersAfterAtTheRate must be positive integers'
101
+ );
88
102
  }
89
- if(options.unmaskedStartCharacters < 0) {
103
+ if (options.unmaskedStartCharacters < 0) {
90
104
  options.unmaskedStartCharacters = 0;
91
105
  }
92
- if(options.unmaskedEndCharacters < 0) {
106
+ if (options.unmaskedEndCharacters < 0) {
93
107
  options.unmaskedEndCharacters = 0;
94
108
  }
95
- if(options.maxMaskedCharactersBeforeAtTheRate < 0) {
109
+ if (options.maxMaskedCharactersBeforeAtTheRate < 0) {
96
110
  options.maxMaskedCharactersBeforeAtTheRate = 20;
97
111
  }
98
- if(options.maxMaskedCharactersAfterAtTheRate < 0) {
112
+ if (options.maxMaskedCharactersAfterAtTheRate < 0) {
99
113
  options.maxMaskedCharactersAfterAtTheRate = 20;
100
114
  }
101
- if((!options.maskWith) || options.maskWith.toString().length <= 0) {
115
+ if (!options.maskWith || options.maskWith.toString().length <= 0) {
102
116
  options.maskWith = '*';
103
117
  }
104
- if(typeof(options.maskAtTheRate) !== 'boolean') {
118
+ if (typeof options.maskAtTheRate !== 'boolean') {
105
119
  reasons.push('maskAtTheRate should be a boolean field');
106
120
  }
107
- if(reasons.length > 0) {
121
+ if (reasons.length > 0) {
108
122
  const badOptions = new BadOption('Email mask configuration', reasons);
109
123
  badOptions.throwBadOptionException();
110
124
  }
111
125
  }
112
-
126
+
113
127
  static validateEmailOptions2(email, options) {
114
128
  let reasons = [];
115
- if(!email || email.indexOf('@') < 0) {
129
+ if (!email || email.indexOf('@') < 0) {
116
130
  reasons.push(`Email must contain one '@'`);
117
131
  }
118
- try{
132
+ try {
119
133
  options.unmaskedStartCharactersBeforeAt = parseInt(options.unmaskedStartCharactersBeforeAt);
120
134
  options.unmaskedEndCharactersAfterAt = parseInt(options.unmaskedEndCharactersAfterAt);
121
- if(isNaN(options.unmaskedStartCharactersBeforeAt) || isNaN(options.unmaskedEndCharactersAfterAt)){
135
+ if (
136
+ isNaN(options.unmaskedStartCharactersBeforeAt) ||
137
+ isNaN(options.unmaskedEndCharactersAfterAt)
138
+ ) {
122
139
  throw Error();
123
- };
124
- }catch(err) {
125
- reasons.push('unmaskedStartCharactersBeforeAt, unmaskedEndCharactersAfterAt must be positive integers');
140
+ }
141
+ } catch (err) {
142
+ reasons.push(
143
+ 'unmaskedStartCharactersBeforeAt, unmaskedEndCharactersAfterAt must be positive integers'
144
+ );
126
145
  }
127
- if(options.unmaskedStartCharactersBeforeAt < 0) {
146
+ if (options.unmaskedStartCharactersBeforeAt < 0) {
128
147
  options.unmaskedStartCharactersBeforeAt = 0;
129
148
  }
130
- if(options.unmaskedEndCharactersAfterAt < 0) {
149
+ if (options.unmaskedEndCharactersAfterAt < 0) {
131
150
  options.unmaskedEndCharactersAfterAt = 0;
132
151
  }
133
- if((!options.maskWith) || options.maskWith.toString().length <= 0) {
152
+ if (!options.maskWith || options.maskWith.toString().length <= 0) {
134
153
  options.maskWith = '*';
135
154
  }
136
- if(typeof(options.maskAtTheRate) !== 'boolean') {
155
+ if (typeof options.maskAtTheRate !== 'boolean') {
137
156
  reasons.push('maskAtTheRate should be a boolean field');
138
157
  }
139
- if(reasons.length > 0) {
158
+ if (reasons.length > 0) {
140
159
  const badOptions = new BadOption('Email mask configuration', reasons);
141
160
  badOptions.throwBadOptionException();
142
161
  }
@@ -144,16 +163,20 @@ class MaskHelper {
144
163
 
145
164
  static validateJSONOptions(options) {
146
165
  let reasons = [];
147
- if(!(options.fields instanceof Array)) {
166
+ if (!(options.fields instanceof Array)) {
148
167
  reasons.push(`fields should be an Array`);
149
168
  }
150
- if((!options.maskWith) || options.maskWith.toString().length <= 0) {
169
+ if (!options.maskWith || options.maskWith.toString().length <= 0) {
151
170
  options.maskWith = '*';
152
171
  }
153
- if(!options.maxMaskedCharactersStr || typeof(options.maxMaskedCharactersStr) !== 'number' || options.maxMaskedCharactersStr <= 0) {
172
+ if (
173
+ !options.maxMaskedCharactersStr ||
174
+ typeof options.maxMaskedCharactersStr !== 'number' ||
175
+ options.maxMaskedCharactersStr <= 0
176
+ ) {
154
177
  options.maxMaskedCharactersStr = -1;
155
178
  }
156
- if(reasons.length > 0) {
179
+ if (reasons.length > 0) {
157
180
  const badOptions = new BadOption('JSON mask configuration', reasons);
158
181
  badOptions.throwBadOptionException();
159
182
  }
@@ -161,22 +184,22 @@ class MaskHelper {
161
184
 
162
185
  static validateStringOptions(options) {
163
186
  let reasons = [];
164
- if(!(options.values instanceof Array)) {
187
+ if (!(options.values instanceof Array)) {
165
188
  reasons.push(`values should be an Array`);
166
189
  }
167
- if(typeof(options.maskOnlyFirstOccurance) !== 'boolean') {
190
+ if (typeof options.maskOnlyFirstOccurance !== 'boolean') {
168
191
  reasons.push('maskOnlyFirstOccurance should be a boolean field');
169
192
  }
170
- if(typeof(options.maskAll) !== 'boolean') {
193
+ if (typeof options.maskAll !== 'boolean') {
171
194
  reasons.push('maskAll should be a boolean field');
172
195
  }
173
- if(typeof(options.maskSpace) !== 'boolean') {
196
+ if (typeof options.maskSpace !== 'boolean') {
174
197
  reasons.push('maskSpace should be a boolean field');
175
198
  }
176
- if((!options.maskWith) || options.maskWith.toString().length <= 0) {
199
+ if (!options.maskWith || options.maskWith.toString().length <= 0) {
177
200
  options.maskWith = '*';
178
201
  }
179
- if(reasons.length > 0) {
202
+ if (reasons.length > 0) {
180
203
  const badOptions = new BadOption('string mask configuration', reasons);
181
204
  badOptions.throwBadOptionException();
182
205
  }
@@ -184,25 +207,25 @@ class MaskHelper {
184
207
 
185
208
  static validateUuidMaskOptions(options) {
186
209
  let reasons = [];
187
- try{
210
+ try {
188
211
  options.unmaskedStartCharacters = parseInt(options.unmaskedStartCharacters);
189
212
  options.unmaskedEndCharacters = parseInt(options.unmaskedEndCharacters);
190
- if(isNaN(options.unmaskedStartCharacters) || isNaN(options.unmaskedEndCharacters)){
213
+ if (isNaN(options.unmaskedStartCharacters) || isNaN(options.unmaskedEndCharacters)) {
191
214
  throw Error();
192
- };
193
- }catch(err) {
215
+ }
216
+ } catch (err) {
194
217
  reasons.push('unmaskedStartCharacters, unmaskedEndCharacters must be positive integers');
195
218
  }
196
219
 
197
- if(options.unmaskedStartCharacters > 32 || options.unmaskedEndCharacters > 32) {
220
+ if (options.unmaskedStartCharacters > 32 || options.unmaskedEndCharacters > 32) {
198
221
  options.unmaskedStartCharacters = 32;
199
222
  options.unmaskedEndCharacters = 0;
200
223
  }
201
-
202
- if((!options.maskWith) || options.maskWith.toString().length <= 0) {
224
+
225
+ if (!options.maskWith || options.maskWith.toString().length <= 0) {
203
226
  options.maskWith = '*';
204
227
  }
205
- if(reasons.length > 0) {
228
+ if (reasons.length > 0) {
206
229
  const badOptions = new BadOption('Uuid mask configuration: ', reasons);
207
230
  badOptions.throwBadOptionException();
208
231
  }
@@ -210,88 +233,89 @@ class MaskHelper {
210
233
 
211
234
  static validateCardMaskOptions(options, cardLength) {
212
235
  let reasons = [];
213
- try{
236
+ try {
214
237
  options.unmaskedStartDigits = parseInt(options.unmaskedStartDigits);
215
238
  options.unmaskedEndDigits = parseInt(options.unmaskedEndDigits);
216
- if(isNaN(options.unmaskedStartDigits) || isNaN(options.unmaskedEndDigits)){
239
+ if (isNaN(options.unmaskedStartDigits) || isNaN(options.unmaskedEndDigits)) {
217
240
  throw Error();
218
- };
219
- }catch(err) {
241
+ }
242
+ } catch (err) {
220
243
  reasons.push('unmaskedStartDigits and unmaskedEndDigits must be positive integers');
221
244
  }
222
- if(options.unmaskedStartDigits < 0) {
245
+ if (options.unmaskedStartDigits < 0) {
223
246
  options.unmaskedStartDigits = 0;
224
- } else if(options.unmaskedStartDigits > cardLength) {
247
+ } else if (options.unmaskedStartDigits > cardLength) {
225
248
  options.unmaskedStartDigits = cardLength;
226
249
  }
227
- if(options.unmaskedEndDigits < 0) {
250
+ if (options.unmaskedEndDigits < 0) {
228
251
  options.unmaskedEndDigits = 0;
229
- } else if(options.unmaskedEndDigits > cardLength) {
252
+ } else if (options.unmaskedEndDigits > cardLength) {
230
253
  options.unmaskedEndDigits = cardLength;
231
254
  }
232
- if((!options.maskWith) || options.maskWith.toString().length <= 0) {
255
+ if (!options.maskWith || options.maskWith.toString().length <= 0) {
233
256
  options.maskWith = '*';
234
257
  }
235
- if(reasons.length > 0) {
258
+ if (reasons.length > 0) {
236
259
  const badOptions = new BadOption('Phone mask configuration', reasons);
237
260
  badOptions.throwBadOptionException();
238
261
  }
239
262
  }
240
263
 
241
264
  static getValidatedJsonMask2Configs(configs) {
242
- if(!configs) return JSON.parse(JSON.stringify(Constants.defaultjsonMask2Configs));
265
+ if (!configs) return JSON.parse(JSON.stringify(Constants.defaultjsonMask2Configs));
243
266
 
244
- if(!configs.cardMaskOptions) {
267
+ if (!configs.cardMaskOptions) {
245
268
  configs.cardMaskOptions = JSON.parse(JSON.stringify(Constants.defaultCardMaskOptions));
246
269
  }
247
270
 
248
- if(!configs.cardFields) {
271
+ if (!configs.cardFields) {
249
272
  configs.cardFields = [];
250
273
  }
251
274
 
252
- if(!configs.emailFields) {
275
+ if (!configs.emailFields) {
253
276
  configs.emailFields = [];
254
277
  }
255
278
 
256
- if(!configs.passwordFields) {
279
+ if (!configs.passwordFields) {
257
280
  configs.passwordFields = [];
258
281
  }
259
282
 
260
- if(!configs.phoneFields) {
283
+ if (!configs.phoneFields) {
261
284
  configs.phoneFields = [];
262
285
  }
263
286
 
264
- if(!configs.stringFields) {
287
+ if (!configs.stringFields) {
265
288
  configs.stringFields = [];
266
289
  }
267
290
 
268
- if(!configs.uuidFields) {
291
+ if (!configs.uuidFields) {
269
292
  configs.uuidFields = [];
270
293
  }
271
294
 
272
- if(!configs.emailMaskOptions) {
295
+ if (!configs.emailMaskOptions) {
273
296
  configs.emailMaskOptions = JSON.parse(JSON.stringify(Constants.defaultEmailMask2Options));
274
297
  }
275
298
 
276
- if(!configs.passwordMaskOptions) {
277
- configs.passwordMaskOptions = JSON.parse(JSON.stringify(Constants.defaultPasswordMaskOptions));
299
+ if (!configs.passwordMaskOptions) {
300
+ configs.passwordMaskOptions = JSON.parse(
301
+ JSON.stringify(Constants.defaultPasswordMaskOptions)
302
+ );
278
303
  }
279
304
 
280
- if(!configs.phoneMaskOptions) {
305
+ if (!configs.phoneMaskOptions) {
281
306
  configs.phoneMaskOptions = JSON.parse(JSON.stringify(Constants.defaultPhoneMaskOptions));
282
307
  }
283
308
 
284
- if(!configs.stringMaskOptions) {
309
+ if (!configs.stringMaskOptions) {
285
310
  configs.stringMaskOptions = JSON.parse(JSON.stringify(Constants.defaultStringMaskOptions));
286
311
  }
287
312
 
288
- if(!configs.uuidMaskOptions) {
313
+ if (!configs.uuidMaskOptions) {
289
314
  configs.uuidMaskOptions = JSON.parse(JSON.stringify(Constants.defaultUuidMaskOptions));
290
315
  }
291
-
316
+
292
317
  return configs;
293
318
  }
294
-
295
319
  }
296
320
 
297
- module.exports = MaskHelper;
321
+ module.exports = MaskHelper;
@@ -1,14 +1,13 @@
1
- const {get, set} = require('lodash');
1
+ const { get, set } = require('lodash');
2
2
 
3
3
  class JsonGetSet {
4
- static get(object, field) {
5
- return get(object, field);
6
- }
4
+ static get(object, field) {
5
+ return get(object, field);
6
+ }
7
7
 
8
- static set(object, field, value) {
9
- return set(object, field, value);
10
- }
8
+ static set(object, field, value) {
9
+ return set(object, field, value);
10
+ }
11
11
  }
12
12
 
13
- module.exports = JsonGetSet
14
-
13
+ module.exports = JsonGetSet;
@@ -3,59 +3,59 @@ const MaskHelper = require('../helpers/MaskHelper');
3
3
  const Constants = require('../helpers/Constants');
4
4
 
5
5
  class CardMask {
6
- static maskCard(card, options) {
7
- if(!card) return card;
8
- let cardToProcess = (card + '').trim();
9
- if(options) {
10
- options = MaskHelper.mapWithDefaultValues(options, Constants.defaultCardMaskOptions);
11
- MaskHelper.validateCardMaskOptions(options, cardToProcess.length);
12
- } else {
13
- options = Constants.defaultCardMaskOptions;
14
- }
15
- let countOfNumbers = 0;
16
- let lastIndex = 0;
17
- let flag = true;
18
- for(let i = cardToProcess.length-1; i >= 0; i--) {
19
- if(!isNaN(cardToProcess[i])) {
20
- if(flag && countOfNumbers === options.unmaskedEndDigits) {
21
- lastIndex = i;
22
- flag = false;
23
- }
24
- countOfNumbers++;
25
- }
26
- }
27
- if((options.unmaskedStartDigits + options.unmaskedEndDigits) >= countOfNumbers) {
28
- return cardToProcess;
29
- }
30
- let maskedCard = '';
31
- let i = 0;
32
- let j = 0;
33
- while(i < options.unmaskedStartDigits) {
34
- if(!isNaN(cardToProcess[j])) {
35
- i++;
36
- }
37
- maskedCard += cardToProcess[j++];
6
+ static maskCard(card, options) {
7
+ if (!card) return card;
8
+ let cardToProcess = (card + '').trim();
9
+ if (options) {
10
+ options = MaskHelper.mapWithDefaultValues(options, Constants.defaultCardMaskOptions);
11
+ MaskHelper.validateCardMaskOptions(options, cardToProcess.length);
12
+ } else {
13
+ options = Constants.defaultCardMaskOptions;
14
+ }
15
+ let countOfNumbers = 0;
16
+ let lastIndex = 0;
17
+ let flag = true;
18
+ for (let i = cardToProcess.length - 1; i >= 0; i--) {
19
+ if (!isNaN(cardToProcess[i])) {
20
+ if (flag && countOfNumbers === options.unmaskedEndDigits) {
21
+ lastIndex = i;
22
+ flag = false;
38
23
  }
24
+ countOfNumbers++;
25
+ }
26
+ }
27
+ if (options.unmaskedStartDigits + options.unmaskedEndDigits >= countOfNumbers) {
28
+ return cardToProcess;
29
+ }
30
+ let maskedCard = '';
31
+ let i = 0;
32
+ let j = 0;
33
+ while (i < options.unmaskedStartDigits) {
34
+ if (!isNaN(cardToProcess[j])) {
35
+ i++;
36
+ }
37
+ maskedCard += cardToProcess[j++];
38
+ }
39
39
 
40
- while(j <= lastIndex) {
41
- if(isNaN(parseInt(cardToProcess[j]))) {
42
- maskedCard += cardToProcess[j];
43
- } else {
44
- maskedCard += options.maskWith;
45
- }
46
- j++;
47
- }
48
-
49
- i = 0;
50
- j = lastIndex+1;
51
- while(i < options.unmaskedEndDigits) {
52
- if(!isNaN(cardToProcess[j])) {
53
- i++;
54
- }
55
- maskedCard += cardToProcess[j++];
56
- }
57
- return maskedCard;
40
+ while (j <= lastIndex) {
41
+ if (isNaN(parseInt(cardToProcess[j]))) {
42
+ maskedCard += cardToProcess[j];
43
+ } else {
44
+ maskedCard += options.maskWith;
45
+ }
46
+ j++;
47
+ }
48
+
49
+ i = 0;
50
+ j = lastIndex + 1;
51
+ while (i < options.unmaskedEndDigits) {
52
+ if (!isNaN(cardToProcess[j])) {
53
+ i++;
54
+ }
55
+ maskedCard += cardToProcess[j++];
58
56
  }
57
+ return maskedCard;
58
+ }
59
59
  }
60
60
 
61
- module.exports = CardMask
61
+ module.exports = CardMask;
@@ -3,28 +3,34 @@ const MaskHelper = require('../helpers/MaskHelper');
3
3
  const Constants = require('../helpers/Constants');
4
4
 
5
5
  class EmailMask {
6
+ static maskEmail2(email, options) {
7
+ if (!email || typeof email !== 'string') return email;
8
+ let maskedEmail = '';
9
+ options = options
10
+ ? MaskHelper.mapWithDefaultValues(options, Constants.defaultEmailMask2Options)
11
+ : Constants.defaultEmailMask2Options;
12
+ MaskHelper.validateEmailOptions2(email, options);
13
+ const indexOfAt = email.indexOf('@');
14
+ // if(indexOfAt < 0) return email; // Not needed since we have the validation for mandatory '@'
15
+ const [before, after] = email.split('@');
16
+ const beforeLength = before.length;
17
+ const afterLength = after.length;
6
18
 
7
- static maskEmail2(email, options) {
8
- if(!email || typeof(email) !== 'string') return email;
9
- let maskedEmail = '';
10
- options = options ? MaskHelper.mapWithDefaultValues(options, Constants.defaultEmailMask2Options)
11
- : Constants.defaultEmailMask2Options;
12
- MaskHelper.validateEmailOptions2(email, options);
13
- const indexOfAt = email.indexOf('@');
14
- // if(indexOfAt < 0) return email; // Not needed since we have the validation for mandatory '@'
15
- const [before, after] = email.split('@');
16
- const beforeLength = before.length;
17
- const afterLength = after.length;
19
+ maskedEmail +=
20
+ options.unmaskedStartCharactersBeforeAt >= beforeLength
21
+ ? before
22
+ : before.substring(0, options.unmaskedStartCharactersBeforeAt) +
23
+ `${options.maskWith}`.repeat(beforeLength - options.unmaskedStartCharactersBeforeAt);
18
24
 
19
- maskedEmail += (options.unmaskedStartCharactersBeforeAt >= beforeLength) ? before :
20
- before.substring(0, options.unmaskedStartCharactersBeforeAt) + `${options.maskWith}`.repeat(beforeLength - options.unmaskedStartCharactersBeforeAt);
21
-
22
- maskedEmail += options.maskAtTheRate ? options.maskWith : '@';
25
+ maskedEmail += options.maskAtTheRate ? options.maskWith : '@';
23
26
 
24
- maskedEmail += (options.unmaskedEndCharactersAfterAt >= afterLength) ? after :
25
- (`${options.maskWith}`.repeat(afterLength-options.unmaskedEndCharactersAfterAt) + after.substring(afterLength - options.unmaskedEndCharactersAfterAt));
26
- return maskedEmail;
27
- }
27
+ maskedEmail +=
28
+ options.unmaskedEndCharactersAfterAt >= afterLength
29
+ ? after
30
+ : `${options.maskWith}`.repeat(afterLength - options.unmaskedEndCharactersAfterAt) +
31
+ after.substring(afterLength - options.unmaskedEndCharactersAfterAt);
32
+ return maskedEmail;
33
+ }
28
34
  }
29
35
 
30
- module.exports = EmailMask
36
+ module.exports = EmailMask;