maskdata 1.1.8 → 1.2.0

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/README.md CHANGED
@@ -1,35 +1,38 @@
1
- maskdata is a Node.js module to mask various kinds of data. With the help of maskdata, you can mask email, phone number, card number, JSON fields, password etc..
2
- <br/>Also, it provides utility methods to get a field, or replace a field from any complex/nested json.
1
+ maskdata is a Node.js module to mask various kinds of data. With the help of maskdata, you can mask email, phone number, card number, JSON fields, password, etc...
2
+ <br/>Also, it provides utility methods to get a field, or replace a field from any complex/nested JSON.
3
3
 
4
4
  # Table of Contents
5
5
  - [Features](#features)
6
6
  - [Install maskdata](#install-maskdata)
7
- - [Version 1.1.8 Features](#release-features)
7
+ - [Version 1.2.0 Features](#release-features)
8
8
  - [How to Use](#how-to-use)
9
- - [Mask Phone Number](#mask-phone-number)
10
- - [Mask Phone Number with the default configuration](#mask-phone-number-with-the-default-configuration)
11
- - [Mask Password](#mask-password)
12
- - [Mask Password with the default configuration](#mask-password-with-the-default-configuration)
9
+ - [Mask Card number](#mask-card-number)
13
10
  - [Mask Email](#mask-email-id)
14
- - [Mask Email id with the default configuration](#mask-email-id-with-the-default-configuration)
15
- - [Get Nested Json Property](#get-nested-json-property)
16
- - [Replace the value of a json field](#replace-the-value-of-a-json-field)
17
- - [Mask JSON fields](#mask-fields-in-a-json)
18
- - [Mask nested JSON fields](#mask-fields-of-a-nested-object)
11
+ - [Mask Email id with the default configuration](#mask-email-id-with-the-default-configuration)
12
+ - [Mask JSON fields](#mask-json)
13
+ - [JSON mask examples with nested fields](#json-mask-examples)
14
+ - [Mask Password](#mask-password)
15
+ - [Mask Password with the default configuration](#mask-password-with-the-default-configuration)
16
+ - [Mask Phone Number](#mask-phone-number)
17
+ - [Mask Phone Number with the default configuration](#mask-phone-number-with-the-default-configuration)
19
18
  - [Mask words/characters in a string](#mask-the-characters-or-words-in-the-string)
20
- - [Mask Card number](#mask-card-number)
19
+ - [Mask UUID](#mask-uuid)
20
+ - [Get Nested JSON Property](#get-nested-json-property)
21
+ - [Replace the value of a JSON field](#replace-the-value-of-a-json-field)
22
+ - [Mask JSON fields](#mask-fields-in-a-json)
23
+ - [Mask nested JSON fields](#mask-fields-of-a-nested-object)
21
24
  - [Report Bugs](#report-bugs)
22
- - [How to run test cases](#run-tests)
23
25
  - [Give a Star](#give-a-star)
24
26
  - [LICENSE - "MIT"](#license---mit)
25
27
 
26
28
  # Features
27
- * Mask password
29
+ * Mask Card numbers
30
+ * Mask Email ids
31
+ * Mask Password
28
32
  * Mask Phone numbers
29
- * Mask Email
30
- * Mask desired fields in a JSON
31
33
  * Mask the given words/substrings from throughout a String
32
- * Mask the card number
34
+ * Mask UUIDs
35
+ * Mask JSON - JSON can contain cards, emails, passwords, phones, strings, and UUIDs. Mask all of them with a single call using - [Mask JSON fields](#mask-json)
33
36
  * Get nested field from JSON
34
37
  * Set/Replace nested field values from JSON
35
38
 
@@ -37,94 +40,387 @@ maskdata is a Node.js module to mask various kinds of data. With the help of mas
37
40
  > npm i maskdata
38
41
 
39
42
  # Release Features
43
+ ### Version 1.2.0
44
+ - Support for masking cards, emails, passwords, phones, strings, and UUIDs. Mask all of them with a single call using - [Mask JSON fields](#mask-json)
45
+ - Support for masking UUID - [Mask UUID](#mask-uuid)
46
+ - Minor bug fix in card masking.
47
+ - Extensive testing with the help of mocha test cases for all features covering more than 110 test cases.
48
+ - Improved Documentation
49
+ ### Version: 1.1.10
50
+ - Support of maxMaskedCharacters in masking JSON fields: https://github.com/Sumukha1496/maskdata/issues/21
51
+ - This is applicable only if the type of value is a string. Details: [Mask JSON fields](#mask-fields-in-a-json)
40
52
  ### Version: 1.1.8
41
- - Mocha test cases for most of the usecases.
53
+ - Mocha test cases for most of the use cases.
42
54
  https://github.com/Sumukha1496/maskdata/pull/23
43
55
  - Handling null/Empty inputs --> Mask function will return the input itself.
44
56
  ### Version: 1.1.6
45
- - Feature to mask all the characters in the String along with mask/not mask spaces in the string.
46
- - [Mask all characters in the String](#mask-all-characters-in-the-string)
47
- ### Version: 1.1.4
48
- - Password masking bug fix: https://github.com/Sumukha1496/maskdata/issues/12
49
-
50
- ### Version: 1.1.3
51
- - Unmasked start and end characters feature in password masking. It can be used in cases where the password/Secret key has some metadata info which needs to be printed or shown to users.
52
- Ticket: https://github.com/Sumukha1496/maskdata/issues/11. Both the fields are opional and can find more info here: [Mask Password](#mask-password)
57
+ - Feature to mask all the characters in the String along with mask/visible spaces in the string.
53
58
 
54
- #### Example: Mask password OR secretKey with some meta info at the end
59
+ # How to Use
60
+ ```javascript
61
+ const MaskData = require('./maskdata');
62
+ ```
55
63
 
64
+ ## Mask card number
65
+ This will mask the digits in a card number.<br/>This will mask only the numerical data and not any non-numeric delimiters, alphabets, or any other types of data
56
66
  ```javascript
57
67
  const MaskData = require('./maskdata');
58
68
 
59
- const maskPasswordOptions = {
60
- maskWith: "X",
61
- maxMaskedCharacters: 20, // To limit the output String length to 20.
62
- unmaskedStartCharacters: 4,
63
- unmaskedEndCharacters: 9 // As last 9 characters of the secret key is a meta info which can be printed for debugging or other purpose
69
+ const maskCardOptions = {
70
+ // Character to mask the data. The default value is '*'
71
+ maskWith: "*",
72
+
73
+ // Should be positive Integer
74
+ // If the starting 'n' digits need to be visible/unmasked
75
+ // Default value is 4
76
+ unmaskedStartDigits: 4,
77
+
78
+ // Should be positive Integer
79
+ // If the ending 'n' digits need to be visible/unmasked
80
+ // Default value is 1.
81
+ unmaskedEndDigits: 1
64
82
  };
65
83
 
66
- const password = "TEST:U2VjcmV0S2V5MQ==:CLIENT-A";
84
+ const cardNumber = "1234-5678-1234-5678";
67
85
 
68
- const maskedPassword = MaskData.maskPassword(password, maskPasswordOptions);
69
- //Output: TESTXXXXXXX:CLIENT-A
86
+ const cardAfterMasking = MaskData.maskCard(cardNumber, maskCardOptions);
70
87
 
71
- maskPasswordOptions.unmaskedStartCharacters = 0;
88
+ //Output: 1234-****-****-***8
72
89
 
73
- const maskedPassword = MaskData.maskPassword(password, maskPasswordOptions);
74
- //Output: XXXXXXXXXXX:CLIENT-A
75
90
  ```
76
91
 
77
- # How to Use
92
+
93
+ ## Mask Email id
94
+ Use this method instead of maskEmail(). To mask with the default options, don't pass the configurations.
78
95
  ```javascript
79
96
  const MaskData = require('./maskdata');
97
+
98
+ const emailMask2Options = {
99
+ maskWith: "*",
100
+ unmaskedStartCharactersBeforeAt: 3,
101
+ unmaskedEndCharactersAfterAt: 2,
102
+ maskAtTheRate: false
103
+ };
104
+
105
+ const email = "my.test.email@testEmail.com";
106
+
107
+ const maskedEmail = MaskData.maskEmail2(email, emailMask2Options);
108
+
109
+ //Output: my.********@**********om
110
+
80
111
  ```
112
+ ### Consider an email: abcd@email.com
113
+ Here,
114
+ - number of characters before @ -> 4
115
+ - number of characters after @ --> 9
81
116
 
82
- ## Mask Phone Number
117
+ 1. **unmaskedStartCharactersBeforeAt** --> number of starting characters (before @)not to be masked.
118
+ * If unmaskedStartCharactersBeforeAt > number of characters before @, then it will not mask the characters before @
119
+ 2. **unmaskedEndCharactersAfterAt** --> number of characters not to be masked starting from the end till @.
120
+ * If unmaskedEndCharactersAfterAt > number of characters after @, then it will not mask the characters after @
121
+
122
+ ### Mask only the characters before '@'
83
123
  ```javascript
84
124
  const MaskData = require('./maskdata');
85
125
 
86
- const maskPhoneOptions = {
87
- // Character to mask the data
88
- // default value is '*'
89
- maskWith: "*",
90
-
91
- //Should be positive Integer
92
- // If the starting 'n' digits needs to be unmasked
93
- // Default value is 4
94
- unmaskedStartDigits: 5,
95
-
96
- // Should be positive Integer
97
- //If the ending 'n' digits needs to be unmasked
98
- // Default value is 1
99
- unmaskedEndDigits: 1
126
+ const emailMask2Options = {
127
+ maskWith: "*",
128
+ unmaskedStartCharactersBeforeAt: 0,
129
+ unmaskedEndCharactersAfterAt: 257, // Give a number which is more than the characters after @
130
+ maskAtTheRate: false
100
131
  };
101
132
 
102
- const phoneNumber = "+911234567890";
133
+ const email = "abcd@email.com";
103
134
 
104
- const maskedPhoneNumber = MaskData.maskPhone(phoneNumber, maskPhoneOptions);
105
- //Output: +9112*******0
135
+ const maskedEmail = MaskData.maskEmail2(email, emailMask2Options);
136
+
137
+ //Output: ****@email.com
106
138
 
107
139
  ```
108
140
 
109
- ## Mask Phone Number with the default configuration
110
- To mask with the default options, dont pass the configurations.
141
+ ## Mask Email id with the default configuration
142
+ To mask with the default options, don't pass the configurations.
111
143
  ```javascript
112
144
  const MaskData = require('./maskdata');
113
145
 
114
146
  /** Default Options
115
- maskWith: "*"
116
- unmaskedStartDigits: 4
117
- unmaskedEndDigits: 1
147
+ maskWith: "*",
148
+ unmaskedStartCharactersBeforeAt: 3,
149
+ unmaskedEndCharactersAfterAt: 2,
150
+ maskAtTheRate: false
118
151
  **/
119
- const phoneNumber = "+111234567890";
152
+ const email = "my.test.email@testEmail.com";
120
153
 
121
- const maskedPhoneNumber = MaskData.maskPhone(phoneNumber);
154
+ const maskedEmail = MaskData.maskEmail2(email);
122
155
 
123
- //Output: +911********0
156
+ //Output: my.********@**********om
157
+
158
+ ```
159
+
160
+ ## Mask JSON
161
+ This is the new functionality in version 1.2.0 to handle the masking of multiple types of data in the JSON object with a single mask function call. Use this function instead of the previous function maskJsonFields(). <br><br>To mask with the default options, just pass the required fields(cardFields[] and/or emailFields[] and/or passwordFields[] and/or phoneFields[] and/or stringFields[] and/or uuidFields[]) in the second argument to the function.
162
+
163
+ ```javascript
164
+ const MaskData = require('./maskdata');
165
+
166
+ // Default configs are as below. If specific masking changes are needed, use the corresponding configs for each type of field.
167
+ const defaultjsonMask2Configs = {
168
+ cardMaskOptions: defaultCardMaskOptions, // Optional
169
+ cardFields: [], // List of card fields to be masked
170
+
171
+ emailMaskOptions: defaultEmailMask2Options, // Optional
172
+ emailFields: [], // List of email fields to be masked
173
+
174
+ // For passwords, tokens, etc...
175
+ passwordMaskOptions: defaultPasswordMaskOptions, // Optional
176
+ passwordFields: [], // List of password fields to be masked
177
+
178
+ phoneMaskOptions: defaultPhoneMaskOptions, // Optional
179
+ phoneFields: [], // List of phone fields to be masked
180
+
181
+ stringMaskOptions: defaultStringMaskOptions, // Mandatory if stringFields are given. Otherwise, stringFields won't be masked
182
+ stringFields: [], // List of String fields to be masked
183
+
184
+ uuidMaskOptions: defaultUuidMaskOptions, // Optional
185
+ uuidFields: [] // List of UUID fields to be masked
186
+ };
187
+ ```
188
+ <b>NOTE: For defaultCardMaskOptions, defaultEmailMask2Options, defaultPasswordMaskOptions, defaultPhoneMaskOptions, defaultStringMaskOptions and defaultUuidMaskOptions refer the corresponding masking features. </b>
189
+
190
+ ```javascript
191
+ const defaultjsonMask2Configs = {
192
+ cardMaskOptions: {
193
+ maskWith: "*",
194
+ unmaskedStartDigits: 4,
195
+ unmaskedEndDigits: 1
196
+ },
197
+ cardFields: [],
198
+
199
+ emailMaskOptions: {
200
+ maskWith: "*",
201
+ unmaskedStartCharactersBeforeAt: 3,
202
+ unmaskedEndCharactersAfterAt: 2,
203
+ maskAtTheRate: false
204
+ },
205
+ emailFields: [],
206
+
207
+ passwordMaskOptions: {
208
+ maskWith: "*",
209
+ maxMaskedCharacters: 16,
210
+ unmaskedStartCharacters: 0,
211
+ unmaskedEndCharacters: 0
212
+ },
213
+ passwordFields: [],
214
+
215
+ phoneMaskOptions: {
216
+ maskWith: "*",
217
+ unmaskedStartDigits: 4,
218
+ unmaskedEndDigits: 1
219
+ },
220
+ phoneFields: [],
221
+
222
+ stringMaskOptions: {
223
+ maskWith: "*",
224
+ maskOnlyFirstOccurance: false,
225
+ values: [],
226
+ maskAll: false,
227
+ maskSpace: true
228
+ },
229
+ stringFields: [],
230
+
231
+ uuidMaskOptions: {
232
+ maskWith: "*",
233
+ unmaskedStartCharacters: 0,
234
+ unmaskedEndCharacters: 0
235
+ },
236
+ uuidFields: []
237
+ };
124
238
 
125
239
  ```
126
240
 
241
+ ### JSON mask examples
242
+ Example1:
243
+ ```javascript
244
+ const jsonInput = {
245
+ 'credit': '1234-5678-8765-1234',
246
+ 'debit': '0000-1111-2222-3333',
247
+ 'primaryEmail': 'primary@Email.com',
248
+ 'secondaryEmail': 'secondary@Email.com',
249
+ 'password': 'dummyPassword',
250
+ 'homePhone': "+1 1234567890",
251
+ 'workPhone': "+1 9876543210",
252
+ 'addressLine1': "This is my addressline 1. This is my home",
253
+ 'addressLine2': "AddressLine 2",
254
+ 'uuid1': '123e4567-e89b-12d3-a456-426614174000'
255
+ };
256
+
257
+ const jsonMaskConfig = {
258
+ cardFields: ['credit', 'debit'],
259
+ emailFields: ['primaryEmail', 'secondaryEmail'],
260
+ passwordFields: ['password'],
261
+ phoneFields: ['homePhone', 'workPhone'],
262
+ stringMaskOptions: {
263
+ maskWith: "*",
264
+ maskOnlyFirstOccurance: false,
265
+ values: ["This"]
266
+ },
267
+ stringFields: ['addressLine1', 'addressLine2'],
268
+ uuidFields: ['uuid1']
269
+ };
270
+
271
+ const maskedJsonOutput = maskData.maskJSON2(jsonInput, jsonMaskConfig);
272
+
273
+ Output:
274
+
275
+ {
276
+ credit: '1234-****-****-***4',
277
+ debit: '0000-****-****-***3',
278
+ primaryEmail: 'pri****@*******om',
279
+ secondaryEmail: 'sec******@*******om',
280
+ password: '*************',
281
+ homePhone: '+1 1********0',
282
+ workPhone: '+1 9********0',
283
+ addressLine1: '**** is my addressline 1. **** is my home',
284
+ addressLine2: 'AddressLine 2',
285
+ uuid1: '********-****-****-****-************'
286
+ }
287
+
288
+
289
+ Example2: Mask with custom configs for each/any type of fields
290
+
291
+ const jsonInput2 = {
292
+ 'credit': '1234-5678-8765-1234',
293
+ 'debit': '0000-1111-2222-3333',
294
+ 'primaryEmail': 'primary@Email.com',
295
+ 'secondaryEmail': 'secondary@Email.com',
296
+ 'password': 'dummyPasswordANDdummyPassword',
297
+ 'homePhone': "+1 1234567890",
298
+ 'workPhone': "+1 9876543210",
299
+ 'addressLine1': "This is my addressline 1. This is my home",
300
+ 'addressLine2': "AddressLine 2",
301
+ 'uuid1': '123e4567-e89b-12d3-a456-426614174000'
302
+ };
303
+
304
+ const jsonMaskConfig2 = {
305
+ // Card
306
+ cardMaskOptions: { maskWith: "X", unmaskedStartDigits: 2,unmaskedEndDigits: 4 },
307
+ cardFields: ['credit', 'debit'],
308
+
309
+ // Email
310
+ emailMaskOptions: { maskWith: "*", unmaskedStartCharactersBeforeAt: 2, unmaskedEndCharactersAfterAt: 2, maskAtTheRate: false },
311
+ emailFields: ['primaryEmail', 'secondaryEmail'],
312
+
313
+ // Password
314
+ passwordMaskOptions: { maskWith: "*", maxMaskedCharacters: 10, unmaskedStartCharacters: 0, unmaskedEndCharacters: 0 },
315
+ passwordFields: ['password'],
316
+
317
+ // Phone
318
+ phoneMaskOptions: { maskWith: "*", unmaskedStartDigits: 2, unmaskedEndDigits: 1 },
319
+ phoneFields: ['homePhone', 'workPhone'],
320
+
321
+ // String
322
+ stringMaskOptions: { maskWith: "*", maskOnlyFirstOccurance: false, values: [], maskAll: true, maskSpace: false },
323
+ stringFields: ['addressLine1', 'addressLine2'],
324
+
325
+ // UUID
326
+ uuidMaskOptions: { maskWith: "*", unmaskedStartCharacters: 4, unmaskedEndCharacters: 2 },
327
+ uuidFields: ['uuid1']
328
+ };
329
+
330
+ const maskedJsonOutput2 = maskData.maskJSON2(jsonInput2, jsonMaskConfig2);
331
+
332
+ Output:
333
+
334
+ {
335
+ credit: '12XX-XXXX-XXXX-1234',
336
+ debit: '00XX-XXXX-XXXX-3333',
337
+ primaryEmail: 'pr*****@*******om',
338
+ secondaryEmail: 'se*******@*******om',
339
+ password: '**********',
340
+ homePhone: '+1**********0',
341
+ workPhone: '+1**********0',
342
+ addressLine1: '**** ** ** *********** ** **** ** ** ****',
343
+ addressLine2: '*********** *',
344
+ uuid1: '123e****-****-****-****-**********00'
345
+ }
346
+ ```
347
+
348
+ Example3: Mask nested json fields -> Use dot(.) and Array([]) notation to specify the inner fields.
349
+
350
+ ```javascript
351
+
352
+ const jsonInput2 = {
353
+ cards: {
354
+ creditCards: ['1234-5678-8765-1234', '1111-2222-1111-2222'],
355
+ debitCards: ['0000-1111-2222-3333', '2222-1111-3333-4444']
356
+ },
357
+ emails: {
358
+ primaryEmail: 'primary@Email.com',
359
+ secondaryEmail: 'secondary@Email.com'
360
+ },
361
+ passwords: [
362
+ ['dummyPasswordANDdummyPassword', 'dummyPasswordANDdummyPassword']
363
+ ],
364
+ phones: {
365
+ homePhone: "+1 1234567890",
366
+ workPhone: "+1 9876543210",
367
+ },
368
+ address: {
369
+ addressLine1: "This is my addressline 1. This is my home",
370
+ addressLine2: "AddressLine 2"
371
+ },
372
+ uuids: {
373
+ uuid1: '123e4567-e89b-12d3-a456-426614174000'
374
+ }
375
+ };
376
+
377
+ const jsonMaskConfig2 = {
378
+ // Card
379
+ cardMaskOptions: { maskWith: "X", unmaskedStartDigits: 2,unmaskedEndDigits: 4 },
380
+ cardFields: ['cards.creditCards[0]', 'cards.creditCards[1]', 'cards.debitCards[0]', 'cards.debitCards[1]'],
381
+
382
+ // Email
383
+ emailMaskOptions: { maskWith: "*", unmaskedStartCharactersBeforeAt: 2, unmaskedEndCharactersAfterAt: 2, maskAtTheRate: false },
384
+ emailFields: ['emails.primaryEmail', 'emails.secondaryEmail'],
385
+
386
+ // Password
387
+ passwordMaskOptions: { maskWith: "*", maxMaskedCharacters: 10, unmaskedStartCharacters: 0, unmaskedEndCharacters: 0 },
388
+ passwordFields: ['passwords[0][0]]', 'passwords[0][1]'],
389
+
390
+ // Phone
391
+ phoneMaskOptions: { maskWith: "*", unmaskedStartDigits: 2, unmaskedEndDigits: 1 },
392
+ phoneFields: ['phones.homePhone', 'phones.workPhone'],
127
393
 
394
+ // String
395
+ stringMaskOptions: { maskWith: "*", maskOnlyFirstOccurance: false, values: [], maskAll: true, maskSpace: false },
396
+ stringFields: ['address.addressLine1', 'address.addressLine2'],
397
+
398
+ // UUID
399
+ uuidMaskOptions: { maskWith: "*", unmaskedStartCharacters: 4, unmaskedEndCharacters: 2 },
400
+ uuidFields: ['uuids.uuid1']
401
+ };
402
+
403
+ const maskedJsonOutput2 = MaskData.maskJSON2(jsonInput2, jsonMaskConfig2);
404
+ // OUTPUT:
405
+ {
406
+ cards: {
407
+ creditCards: [ '12XX-XXXX-XXXX-1234', '11XX-XXXX-XXXX-2222' ],
408
+ debitCards: [ '00XX-XXXX-XXXX-3333', '22XX-XXXX-XXXX-4444' ]
409
+ },
410
+ emails: {
411
+ primaryEmail: 'pr*****@*******om',
412
+ secondaryEmail: 'se*******@*******om'
413
+ },
414
+ passwords: [ [ '**********', '**********' ] ],
415
+ phones: { homePhone: '+1**********0', workPhone: '+1**********0' },
416
+ address: {
417
+ addressLine1: '**** ** ** *********** ** **** ** ** ****',
418
+ addressLine2: '*********** *'
419
+ },
420
+ uuids: { uuid1: '123e****-****-****-****-**********00' }
421
+ }
422
+
423
+ ```
128
424
  ## Mask Password
129
425
  ```javascript
130
426
  const MaskData = require('./maskdata');
@@ -154,7 +450,7 @@ const maskedPassword = MaskData.maskPassword(password, maskPasswordOptions);
154
450
  //Output: **********
155
451
 
156
452
  ## Mask Password with the default configuration
157
- To mask with the default options, dont pass the configurations.
453
+ To mask with the default options, don't pass the configurations.
158
454
  ```javascript
159
455
  const MaskData = require('./maskdata');
160
456
 
@@ -171,77 +467,189 @@ const maskedPassword = MaskData.maskPassword(password)
171
467
 
172
468
  ```
173
469
 
470
+ #### Example: Mask password OR secretKey with some meta info at the end
174
471
 
175
- ## Mask Email id
176
- Use this method instead of maskEmail(). To mask with the default options, dont pass the configurations.
177
472
  ```javascript
178
473
  const MaskData = require('./maskdata');
179
474
 
180
- const emailMask2Options = {
181
- maskWith: "*",
182
- unmaskedStartCharactersBeforeAt: 3,
183
- unmaskedEndCharactersAfterAt: 2,
184
- maskAtTheRate: false
475
+ const maskPasswordOptions = {
476
+ maskWith: "X",
477
+ maxMaskedCharacters: 20, // To limit the output String length to 20.
478
+ unmaskedStartCharacters: 4,
479
+ unmaskedEndCharacters: 9 // As the last 9 characters of the secret key is meta info which can be printed for debugging or other purposes
185
480
  };
186
481
 
187
- const email = "my.test.email@testEmail.com";
482
+ const password = "TEST:U2VjcmV0S2V5MQ==:CLIENT-A";
188
483
 
189
- const maskedEmail = MaskData.maskEmail2(email, emailMask2Options);
484
+ const maskedPassword = MaskData.maskPassword(password, maskPasswordOptions);
485
+ //Output: TESTXXXXXXX:CLIENT-A
190
486
 
191
- //Output: my.********@**********om
487
+ maskPasswordOptions.unmaskedStartCharacters = 0;
192
488
 
489
+ const maskedPassword = MaskData.maskPassword(password, maskPasswordOptions);
490
+ //Output: XXXXXXXXXXX:CLIENT-A
193
491
  ```
194
- ### Consider an email: abcd@email.com
195
- Here,
196
- - number of characters before @ -> 4
197
- - number of characters after @ --> 9
198
492
 
199
- 1. **unmaskedStartCharactersBeforeAt** --> number of starting characters (before @)not to be masked.
200
- * If unmaskedStartCharactersBeforeAt > number of characters before @, then it will not mask the characters before @
201
- 2. **unmaskedEndCharactersAfterAt** --> number of characters not to be masked starting from the end till @.
202
- * If unmaskedEndCharactersAfterAt > number of characters after @, then it will not mask the characters after @
203
493
 
204
- ### Mask only the characters before '@'
494
+ ## Mask Phone Number
205
495
  ```javascript
206
496
  const MaskData = require('./maskdata');
207
497
 
208
- const emailMask2Options = {
209
- maskWith: "*",
210
- unmaskedStartCharactersBeforeAt: 0,
211
- unmaskedEndCharactersAfterAt: 257, // Give a number which is more than the characters after @
212
- maskAtTheRate: false
213
- };
498
+ const maskPhoneOptions = {
499
+ // Character to mask the data
500
+ // default value is '*'
501
+ maskWith: "*",
214
502
 
215
- const email = "abcd@email.com";
503
+ //Should be positive Integer
504
+ // If the starting 'n' digits need to be unmasked
505
+ // Default value is 4
506
+ unmaskedStartDigits: 5,
216
507
 
217
- const maskedEmail = MaskData.maskEmail2(email, emailMask2Options);
508
+ // Should be positive Integer
509
+ //If the ending 'n' digits need to be unmasked
510
+ // Default value is 1
511
+ unmaskedEndDigits: 1
512
+ };
218
513
 
219
- //Output: ****@email.com
514
+ const phoneNumber = "+911234567890";
515
+
516
+ const maskedPhoneNumber = MaskData.maskPhone(phoneNumber, maskPhoneOptions);
517
+ //Output: +9112*******0
220
518
 
221
519
  ```
222
520
 
223
- ## Mask Email id with the default configuration
224
- To mask with the default options, dont pass the configurations.
521
+ ## Mask Phone Number with the default configuration
522
+ To mask with the default options, don't pass the configurations.
225
523
  ```javascript
226
524
  const MaskData = require('./maskdata');
227
525
 
228
526
  /** Default Options
229
- maskWith: "*",
230
- unmaskedStartCharactersBeforeAt: 3,
231
- unmaskedEndCharactersAfterAt: 2,
232
- maskAtTheRate: false
527
+ maskWith: "*"
528
+ unmaskedStartDigits: 4
529
+ unmaskedEndDigits: 1
233
530
  **/
234
- const email = "my.test.email@testEmail.com";
531
+ const phoneNumber = "+111234567890";
235
532
 
236
- const maskedEmail = MaskData.maskEmail2(email);
533
+ const maskedPhoneNumber = MaskData.maskPhone(phoneNumber);
237
534
 
238
- //Output: my.********@**********om
535
+ //Output: +911********0
536
+
537
+ ```
538
+
539
+
540
+ ## Mask the characters or words in the string
541
+ This will mask the characters or words if present in the given string.
542
+ ```javascript
543
+ const MaskData = require('./maskdata');
544
+
545
+ const maskStringOptions = {
546
+ // Character to mask the data. The default value is '*'
547
+ maskWith: "*",
548
+
549
+ /**
550
+ * It is the words/substrings to mask.
551
+ * Should be an array of strings.
552
+ * Can give multiple words/substrings.
553
+ * values[] can be used only when maskAll is false. If maskAll is true, then this is of no use.
554
+ */
555
+ values: ['is', 'test'],
556
+
557
+ /**
558
+ * If to mask only the first occurrence of each word/substring in the given string
559
+ * Should be boolean
560
+ * Default value is false
561
+ */
562
+ maskOnlyFirstOccurance: false,
563
+
564
+ /**
565
+ * If to mask all the characters in a string make maskAll: true
566
+ * If maskAll is true, the words/substrings inside values[] will not be considered.
567
+ * Default value is false
568
+ */
569
+ maskAll: false,
570
+
571
+ /**
572
+ * This is to mask/not mask the spaces in a string when masking all the characters.
573
+ * Can be used ONLY when maskAll: true
574
+ * If maskSpace is false, the spaces in the string will not be masked.
575
+ * This feature is to know the words and each word's length but to hide the content
576
+ * Default value is true
577
+ */
578
+ maskSpace: true
579
+ };
580
+
581
+ const str = "This is a test String";
582
+
583
+ const strAfterMasking = MaskData.maskString(str, maskStringOptions);
584
+
585
+ //Output: Th** ** a **** String
239
586
 
240
587
  ```
241
588
 
589
+ ### Mask all characters in the String
590
+ ```javascript
591
+ const str = "This is a test String";
242
592
 
243
- ## Get Nested Json Property
244
- This method returns the value of nested Json property if exists. Otherwise it returns ```undefined```
593
+ const strAfterMasking = MaskData.maskString(str, maskStringOptions);
594
+
595
+ const stringMaskOptions = {
596
+ maskWith: "*",
597
+ values: [],
598
+ maskAll: true,
599
+ maskSpace: false // Maks all characters except spaces
600
+ };
601
+
602
+ // Output: **** ** * **** *****
603
+
604
+ const str = "This is a test String";
605
+
606
+ const strAfterMasking = MaskData.maskString(str, maskStringOptions);
607
+
608
+ const stringMaskOptions = {
609
+ maskWith: "*",
610
+ values: [],
611
+ maskAll: true,
612
+ maskSpace: true // Mask all characters including spaces
613
+ };
614
+
615
+ // Output: ********************
616
+
617
+ ```
618
+
619
+
620
+ ## Mask UUID
621
+ This will mask the alphanumeric characters in a UUID.<br/>This will not mask the hyphen present in the UUID. Masking is done, only when the input is a valid UUID with only a-f, A-F, and 0-9 and has 36 characters (32 alphanumerics + 4 hyphens, and should work with the <b>regex:</b>
622
+ > /[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;).
623
+
624
+ If the input is not a valid UUID, it will return the input itself without masking.
625
+ ```javascript
626
+ const MaskData = require('./maskdata');
627
+
628
+ const maskUuidOptions = {
629
+ // Character to mask the data. The default value is '*'
630
+ maskWith: "*",
631
+
632
+ // Should be a positive Integer <= 32
633
+ // If the starting 'n' alphanumeric characters need to be visible/unmasked
634
+ // Default value is 0
635
+ unmaskedStartCharacters: 0,
636
+
637
+ //Should be a positive Integer <= 32
638
+ //If the ending 'n' alphanumeric characters need to be visible/unmasked
639
+ // Default value is 0
640
+ unmaskedEndCharacters: 0
641
+ };
642
+
643
+ const uuidInput = "123e4567-e89b-12d3-a456-426614174000";
644
+
645
+ const uuidAfterMasking = MaskData.maskUuid(uuidInput, maskUuidOptions);
646
+
647
+ // Output: ********-****-****-****-************
648
+
649
+ ```
650
+
651
+ ## Get Nested JSON Property
652
+ This method returns the value of the nested JSON property if it exists. Otherwise, it returns ```undefined```
245
653
  ```javascript
246
654
  const MaskData = require('./maskdata');
247
655
 
@@ -268,7 +676,7 @@ const innerPropety = Maskdata.getInnerProperty(nestedObject, 'level1.level2.leve
268
676
  ```
269
677
 
270
678
 
271
- ## Replace the value of a json field
679
+ ## Replace the value of a JSON field
272
680
  To replace a value by keeping the type.
273
681
  ```javascript
274
682
 
@@ -282,7 +690,6 @@ let afterReplacing = MaskData.replaceValue(input, 'age', 99);
282
690
  afterReplacing = MaskData.replaceValue(input, 'married', false);
283
691
 
284
692
  //Output:
285
-
286
693
  Before replacing: {"name":"John","age":33,"married":true}
287
694
  After replacing: {"name":"John","age":99,"married":false}
288
695
 
@@ -291,19 +698,23 @@ Type of married: boolean
291
698
 
292
699
  ```
293
700
 
701
+ ## Mask fields in a JSON
702
+ <b> NOTE: This is an old functionality. For more flexibility and single masking call to mask different types of data in the json object, start using the new maskJson2() function - [Mask JSON fields](#mask-json)</b>
294
703
 
295
- ## Mask fields in a JSON
296
- This method masks the field value if present in the given object
704
+ This method masks the field value if present in the given object.
297
705
  ```javascript
298
706
  const MaskData = require('./maskdata');
299
707
 
300
708
  const maskJSONOptions = {
301
- // Character to mask the data. Default value is '*'
709
+ // Character to mask the data. The default value is '*'
302
710
  maskWith: "*",
303
711
 
304
712
  // It should be an array
305
713
  // Field names to mask. Can give multiple fields.
306
- fields: ['password', 'firstName']
714
+ fields: ['password', 'firstName'],
715
+
716
+ // If the type of value is a string and if we want to limit the number of characters in the output, then we can use this. The default value is -1 means, by default this feature is disabled. It is enabled if we provide a positive integer value. This is not a mandatory field in the config and if not provided, it will take the default value -1 and disable the feature.
717
+ maxMaskedCharactersStr: 4 // Default value is -1 (Disable feature)
307
718
  };
308
719
 
309
720
  const obj = {
@@ -311,24 +722,26 @@ const obj = {
311
722
  firstName: "Jon",
312
723
  lastName: "Snoww"
313
724
  };
725
+
314
726
  const maskedObj = MaskData.maskJSONFields(obj, maskJSONOptions);
315
727
 
316
- //Output: { password: '************', firstName: '***', lastName: 'Snoww' }
728
+ //Output: { password: '****', firstName: '***', lastName: 'Snoww' }
317
729
 
318
730
  ```
319
731
 
320
732
 
321
733
  ## Mask fields of a nested Object
322
- This method masks the field value if present in the given object
734
+ <b>NOTE: USE [Mask JSON fields](#mask-json) for better functionalities.</b>
323
735
 
324
- The masked value type will always be string. Won't mask if the value is ```null```.
736
+ This method masks the field value if present in the given object.
737
+ The masked value type will always be a string. Won't mask if the value is ```null```.
325
738
 
326
- If the field doesn't exist or if there is any syntax error, then it will ignore without throwing any error.
739
+ If the field doesn't exist or if there is any syntax error, then it will ignore it without throwing any error.
327
740
  ```javascript
328
741
  const MaskData = require('./maskdata');
329
742
 
330
743
  const maskJSONOptions = {
331
- // Character to mask the data. Default value is '*'
744
+ // Character to mask the data. The default value is '*'
332
745
  maskWith: "*",
333
746
 
334
747
  // It should be an array
@@ -384,12 +797,12 @@ const maskedObj = MaskData.maskJSONFields(nestedObject, defaultJSONMaskOptions2)
384
797
  ### Example2: To mask all the keys of an object or to mask a field from all the elements of an array.
385
798
 
386
799
  ```javascript
387
- Limititions:
800
+ Limitations:
388
801
  1. Only one * is allowed per field. Either ARRAY[*].FIELD or JSON.*
389
- 2. It will not work for the nested fields like ARRAY[*].FIELD1.FIELD2
802
+ 2. It will not work for nested fields like ARRAY[*].FIELD1.FIELD2
390
803
  3. It will not mask all array elements if given ARRAY[*] or ARRAY[*].
391
804
  4. Will not mask null values.
392
- 5. If ARRAY[*].FIELD is an object, then it will mask that entire object include key.
805
+ 5. If ARRAY[*].FIELD is an object, then it will mask that entire object including the key.
393
806
 
394
807
  const nestedObject = {
395
808
  level1: {
@@ -435,127 +848,16 @@ const maskedObject = MaskData.maskJSONFields(nestedObject, maskAllFields);
435
848
  },
436
849
  "value1": "value"
437
850
  }
438
- ```
439
- ## Mask the characters or words in the string
440
- This will mask the characters or words value if present in the given string.
441
- ```javascript
442
- const MaskData = require('./maskdata');
443
-
444
- const maskStringOptions = {
445
- // Character to mask the data. Default value is '*'
446
- maskWith: "*",
447
-
448
- /**
449
- * It is the words/substrings to mask.
450
- * Should be an array of strings.
451
- * Can give multiple words/substrings.
452
- * values[] can be used only when maskAll is false. If maskAll is true, then this is of no use.
453
- */
454
- values: ['is', 'test'],
455
-
456
- /**
457
- * If to mask only the first occurance of each word/substring in the given string
458
- * Should be boolean
459
- * Default value is false
460
- */
461
- maskOnlyFirstOccurance: false,
462
-
463
- /**
464
- * If to mask all the characters in a string make maskAll: true
465
- * If maskAll is true, the words/substrings inside values[] will not be considered.
466
- * Default value is false
467
- */
468
- maskAll: false,
469
-
470
- /**
471
- * This is to mask/not mask the spaces in a string when masking all the characters.
472
- * Can be used ONLY when maskAll: true
473
- * If maskSpace is true, the spaces in the string will be masked.
474
- * This feature is to know the words and each word length but to hide the content
475
- * Default value is true
476
- */
477
- maskSpace: true
478
- };
479
-
480
- const str = "This is a test String";
481
-
482
- const strAfterMasking = MaskData.maskString(str, maskStringOptions);
483
-
484
- //Output: Th** ** a **** String
485
-
486
- ```
487
-
488
- ### Mask all characters in the String
489
- ```
490
- const str = "This is a test String";
491
-
492
- const strAfterMasking = MaskData.maskString(str, maskStringOptions);
493
-
494
- const stringMaskOptions = {
495
- maskWith: "*",
496
- values: [],
497
- maskAll: true,
498
- maskSpace: false // Do not mask space
499
- };
500
-
501
- // Output: **** ** * **** *****
502
- -------------------------------------------------------------------
503
-
504
- const str = "This is a test String";
505
-
506
- const strAfterMasking = MaskData.maskString(str, maskStringOptions);
507
-
508
- const stringMaskOptions = {
509
- maskWith: "*",
510
- values: [],
511
- maskAll: true,
512
- maskSpace: false // Mask spaces also
513
- };
514
-
515
- // Output: ********************
516
-
517
- ```
518
-
519
- ## Mask card number
520
- This will mask the digits in a card numbers.<br/>This will mask only the numerical data and not any non numeric delimeters, alphabets or any other types of data
521
- ```javascript
522
- const MaskData = require('./maskdata');
523
-
524
- const maskCardOptions = {
525
- // Character to mask the data. Default value is 'X'
526
- maskWith: "X",
527
-
528
- // Should be positive Integer
529
- // If the starting 'n' digits needs to be unmasked
530
- // Default value is 4
531
- unmaskedStartDigits: 4,
532
-
533
- //Should be positive Integer
534
- //If the ending 'n' digits needs to be unmasked
535
- // Default value is 1.
536
- unmaskedEndDigits: 1
537
- };
538
-
539
- const cardNumber = "1234-5678-1234-5678";
540
-
541
- const cardAfterMasking = MaskData.maskCard(cardNumber, maskCardOptions);
542
-
543
- //Output: 1234-XXXX-XXXX-XXX8
544
-
545
851
  ```
546
852
 
547
853
  # Report Bugs
548
- Please raise an issue in github: https://github.com/Sumukha1496/maskdata/issues
549
-
550
- # Run Tests
551
- Below command will run mocha tests and also the test cases present in test.js file. Install all the dependencies using npm i before runnning the below command.
552
- > npm run test
854
+ If there is any help needed with the library functionalities or if there is any bug/issue, please raise an issue in GitHub: https://github.com/Sumukha1496/maskdata/issues
553
855
 
554
856
  # Give a Star
555
- You can give a start at: https://github.com/Sumukha1496/maskdata/stargazers
857
+ You can give a star at: https://github.com/Sumukha1496/maskdata/stargazers
556
858
 
557
859
  # LICENSE - "MIT"
558
- Licenced under MIT Licence
860
+ Licensed under MIT Licence
559
861
 
560
862
  Copyright (c) 2019 Sumukha H S
561
863
 
@@ -571,8 +873,8 @@ copies or substantial portions of the Software.
571
873
 
572
874
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
573
875
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
574
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
575
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
876
+ FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
877
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER
576
878
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
577
879
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
578
880
  SOFTWARE.