maskdata 1.1.10 → 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.10 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,97 +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
40
49
  ### Version: 1.1.10
41
- - Support of maxMaskedCharacters in masking json fields: https://github.com/Sumukha1496/maskdata/issues/21
42
- - This is applicable only if the type of value is string. Details: [Mask JSON fields](#mask-fields-in-a-json)
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)
43
52
  ### Version: 1.1.8
44
- - Mocha test cases for most of the usecases.
53
+ - Mocha test cases for most of the use cases.
45
54
  https://github.com/Sumukha1496/maskdata/pull/23
46
55
  - Handling null/Empty inputs --> Mask function will return the input itself.
47
56
  ### Version: 1.1.6
48
- - Feature to mask all the characters in the String along with mask/not mask spaces in the string.
49
- - [Mask all characters in the String](#mask-all-characters-in-the-string)
50
- ### Version: 1.1.4
51
- - Password masking bug fix: https://github.com/Sumukha1496/maskdata/issues/12
52
-
53
- ### Version: 1.1.3
54
- - 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.
55
- 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.
56
58
 
57
- #### Example: Mask password OR secretKey with some meta info at the end
59
+ # How to Use
60
+ ```javascript
61
+ const MaskData = require('./maskdata');
62
+ ```
58
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
59
66
  ```javascript
60
67
  const MaskData = require('./maskdata');
61
68
 
62
- const maskPasswordOptions = {
63
- maskWith: "X",
64
- maxMaskedCharacters: 20, // To limit the output String length to 20.
65
- unmaskedStartCharacters: 4,
66
- 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
67
82
  };
68
83
 
69
- const password = "TEST:U2VjcmV0S2V5MQ==:CLIENT-A";
84
+ const cardNumber = "1234-5678-1234-5678";
70
85
 
71
- const maskedPassword = MaskData.maskPassword(password, maskPasswordOptions);
72
- //Output: TESTXXXXXXX:CLIENT-A
86
+ const cardAfterMasking = MaskData.maskCard(cardNumber, maskCardOptions);
73
87
 
74
- maskPasswordOptions.unmaskedStartCharacters = 0;
88
+ //Output: 1234-****-****-***8
75
89
 
76
- const maskedPassword = MaskData.maskPassword(password, maskPasswordOptions);
77
- //Output: XXXXXXXXXXX:CLIENT-A
78
90
  ```
79
91
 
80
- # 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.
81
95
  ```javascript
82
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
+
83
111
  ```
112
+ ### Consider an email: abcd@email.com
113
+ Here,
114
+ - number of characters before @ -> 4
115
+ - number of characters after @ --> 9
84
116
 
85
- ## 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 '@'
86
123
  ```javascript
87
124
  const MaskData = require('./maskdata');
88
125
 
89
- const maskPhoneOptions = {
90
- // Character to mask the data
91
- // default value is '*'
92
- maskWith: "*",
93
-
94
- //Should be positive Integer
95
- // If the starting 'n' digits needs to be unmasked
96
- // Default value is 4
97
- unmaskedStartDigits: 5,
98
-
99
- // Should be positive Integer
100
- //If the ending 'n' digits needs to be unmasked
101
- // Default value is 1
102
- 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
103
131
  };
104
132
 
105
- const phoneNumber = "+911234567890";
133
+ const email = "abcd@email.com";
106
134
 
107
- const maskedPhoneNumber = MaskData.maskPhone(phoneNumber, maskPhoneOptions);
108
- //Output: +9112*******0
135
+ const maskedEmail = MaskData.maskEmail2(email, emailMask2Options);
136
+
137
+ //Output: ****@email.com
109
138
 
110
139
  ```
111
140
 
112
- ## Mask Phone Number with the default configuration
113
- 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.
114
143
  ```javascript
115
144
  const MaskData = require('./maskdata');
116
145
 
117
146
  /** Default Options
118
- maskWith: "*"
119
- unmaskedStartDigits: 4
120
- unmaskedEndDigits: 1
147
+ maskWith: "*",
148
+ unmaskedStartCharactersBeforeAt: 3,
149
+ unmaskedEndCharactersAfterAt: 2,
150
+ maskAtTheRate: false
121
151
  **/
122
- const phoneNumber = "+111234567890";
152
+ const email = "my.test.email@testEmail.com";
123
153
 
124
- const maskedPhoneNumber = MaskData.maskPhone(phoneNumber);
154
+ const maskedEmail = MaskData.maskEmail2(email);
125
155
 
126
- //Output: +911********0
156
+ //Output: my.********@**********om
127
157
 
128
158
  ```
129
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');
130
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
+ };
238
+
239
+ ```
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'],
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
+ ```
131
424
  ## Mask Password
132
425
  ```javascript
133
426
  const MaskData = require('./maskdata');
@@ -157,7 +450,7 @@ const maskedPassword = MaskData.maskPassword(password, maskPasswordOptions);
157
450
  //Output: **********
158
451
 
159
452
  ## Mask Password with the default configuration
160
- To mask with the default options, dont pass the configurations.
453
+ To mask with the default options, don't pass the configurations.
161
454
  ```javascript
162
455
  const MaskData = require('./maskdata');
163
456
 
@@ -174,77 +467,189 @@ const maskedPassword = MaskData.maskPassword(password)
174
467
 
175
468
  ```
176
469
 
470
+ #### Example: Mask password OR secretKey with some meta info at the end
177
471
 
178
- ## Mask Email id
179
- Use this method instead of maskEmail(). To mask with the default options, dont pass the configurations.
180
472
  ```javascript
181
473
  const MaskData = require('./maskdata');
182
474
 
183
- const emailMask2Options = {
184
- maskWith: "*",
185
- unmaskedStartCharactersBeforeAt: 3,
186
- unmaskedEndCharactersAfterAt: 2,
187
- 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
188
480
  };
189
481
 
190
- const email = "my.test.email@testEmail.com";
482
+ const password = "TEST:U2VjcmV0S2V5MQ==:CLIENT-A";
191
483
 
192
- const maskedEmail = MaskData.maskEmail2(email, emailMask2Options);
484
+ const maskedPassword = MaskData.maskPassword(password, maskPasswordOptions);
485
+ //Output: TESTXXXXXXX:CLIENT-A
193
486
 
194
- //Output: my.********@**********om
487
+ maskPasswordOptions.unmaskedStartCharacters = 0;
195
488
 
489
+ const maskedPassword = MaskData.maskPassword(password, maskPasswordOptions);
490
+ //Output: XXXXXXXXXXX:CLIENT-A
196
491
  ```
197
- ### Consider an email: abcd@email.com
198
- Here,
199
- - number of characters before @ -> 4
200
- - number of characters after @ --> 9
201
492
 
202
- 1. **unmaskedStartCharactersBeforeAt** --> number of starting characters (before @)not to be masked.
203
- * If unmaskedStartCharactersBeforeAt > number of characters before @, then it will not mask the characters before @
204
- 2. **unmaskedEndCharactersAfterAt** --> number of characters not to be masked starting from the end till @.
205
- * If unmaskedEndCharactersAfterAt > number of characters after @, then it will not mask the characters after @
206
493
 
207
- ### Mask only the characters before '@'
494
+ ## Mask Phone Number
208
495
  ```javascript
209
496
  const MaskData = require('./maskdata');
210
497
 
211
- const emailMask2Options = {
212
- maskWith: "*",
213
- unmaskedStartCharactersBeforeAt: 0,
214
- unmaskedEndCharactersAfterAt: 257, // Give a number which is more than the characters after @
215
- maskAtTheRate: false
216
- };
498
+ const maskPhoneOptions = {
499
+ // Character to mask the data
500
+ // default value is '*'
501
+ maskWith: "*",
217
502
 
218
- 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,
219
507
 
220
- 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
+ };
221
513
 
222
- //Output: ****@email.com
514
+ const phoneNumber = "+911234567890";
515
+
516
+ const maskedPhoneNumber = MaskData.maskPhone(phoneNumber, maskPhoneOptions);
517
+ //Output: +9112*******0
223
518
 
224
519
  ```
225
520
 
226
- ## Mask Email id with the default configuration
227
- 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.
228
523
  ```javascript
229
524
  const MaskData = require('./maskdata');
230
525
 
231
526
  /** Default Options
232
- maskWith: "*",
233
- unmaskedStartCharactersBeforeAt: 3,
234
- unmaskedEndCharactersAfterAt: 2,
235
- maskAtTheRate: false
527
+ maskWith: "*"
528
+ unmaskedStartDigits: 4
529
+ unmaskedEndDigits: 1
236
530
  **/
237
- const email = "my.test.email@testEmail.com";
531
+ const phoneNumber = "+111234567890";
238
532
 
239
- const maskedEmail = MaskData.maskEmail2(email);
533
+ const maskedPhoneNumber = MaskData.maskPhone(phoneNumber);
240
534
 
241
- //Output: my.********@**********om
535
+ //Output: +911********0
242
536
 
243
537
  ```
244
538
 
245
539
 
246
- ## Get Nested Json Property
247
- This method returns the value of nested Json property if exists. Otherwise it returns ```undefined```
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
586
+
587
+ ```
588
+
589
+ ### Mask all characters in the String
590
+ ```javascript
591
+ const str = "This is a test String";
592
+
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```
248
653
  ```javascript
249
654
  const MaskData = require('./maskdata');
250
655
 
@@ -271,7 +676,7 @@ const innerPropety = Maskdata.getInnerProperty(nestedObject, 'level1.level2.leve
271
676
  ```
272
677
 
273
678
 
274
- ## Replace the value of a json field
679
+ ## Replace the value of a JSON field
275
680
  To replace a value by keeping the type.
276
681
  ```javascript
277
682
 
@@ -285,7 +690,6 @@ let afterReplacing = MaskData.replaceValue(input, 'age', 99);
285
690
  afterReplacing = MaskData.replaceValue(input, 'married', false);
286
691
 
287
692
  //Output:
288
-
289
693
  Before replacing: {"name":"John","age":33,"married":true}
290
694
  After replacing: {"name":"John","age":99,"married":false}
291
695
 
@@ -294,21 +698,22 @@ Type of married: boolean
294
698
 
295
699
  ```
296
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>
297
703
 
298
- ## Mask fields in a JSON
299
- 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.
300
705
  ```javascript
301
706
  const MaskData = require('./maskdata');
302
707
 
303
708
  const maskJSONOptions = {
304
- // Character to mask the data. Default value is '*'
709
+ // Character to mask the data. The default value is '*'
305
710
  maskWith: "*",
306
711
 
307
712
  // It should be an array
308
713
  // Field names to mask. Can give multiple fields.
309
714
  fields: ['password', 'firstName'],
310
715
 
311
- // If the type of value is string and if we want to limit the number of characters in the output, then we can use this. Default value is -1 means, by default this feature is disabled. It is enabled if we provide 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.
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.
312
717
  maxMaskedCharactersStr: 4 // Default value is -1 (Disable feature)
313
718
  };
314
719
 
@@ -326,16 +731,17 @@ const maskedObj = MaskData.maskJSONFields(obj, maskJSONOptions);
326
731
 
327
732
 
328
733
  ## Mask fields of a nested Object
329
- 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>
330
735
 
331
- 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```.
332
738
 
333
- 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.
334
740
  ```javascript
335
741
  const MaskData = require('./maskdata');
336
742
 
337
743
  const maskJSONOptions = {
338
- // Character to mask the data. Default value is '*'
744
+ // Character to mask the data. The default value is '*'
339
745
  maskWith: "*",
340
746
 
341
747
  // It should be an array
@@ -391,9 +797,9 @@ const maskedObj = MaskData.maskJSONFields(nestedObject, defaultJSONMaskOptions2)
391
797
  ### Example2: To mask all the keys of an object or to mask a field from all the elements of an array.
392
798
 
393
799
  ```javascript
394
- Limititions:
800
+ Limitations:
395
801
  1. Only one * is allowed per field. Either ARRAY[*].FIELD or JSON.*
396
- 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
397
803
  3. It will not mask all array elements if given ARRAY[*] or ARRAY[*].
398
804
  4. Will not mask null values.
399
805
  5. If ARRAY[*].FIELD is an object, then it will mask that entire object including the key.
@@ -442,127 +848,16 @@ const maskedObject = MaskData.maskJSONFields(nestedObject, maskAllFields);
442
848
  },
443
849
  "value1": "value"
444
850
  }
445
- ```
446
- ## Mask the characters or words in the string
447
- This will mask the characters or words value if present in the given string.
448
- ```javascript
449
- const MaskData = require('./maskdata');
450
-
451
- const maskStringOptions = {
452
- // Character to mask the data. Default value is '*'
453
- maskWith: "*",
454
-
455
- /**
456
- * It is the words/substrings to mask.
457
- * Should be an array of strings.
458
- * Can give multiple words/substrings.
459
- * values[] can be used only when maskAll is false. If maskAll is true, then this is of no use.
460
- */
461
- values: ['is', 'test'],
462
-
463
- /**
464
- * If to mask only the first occurance of each word/substring in the given string
465
- * Should be boolean
466
- * Default value is false
467
- */
468
- maskOnlyFirstOccurance: false,
469
-
470
- /**
471
- * If to mask all the characters in a string make maskAll: true
472
- * If maskAll is true, the words/substrings inside values[] will not be considered.
473
- * Default value is false
474
- */
475
- maskAll: false,
476
-
477
- /**
478
- * This is to mask/not mask the spaces in a string when masking all the characters.
479
- * Can be used ONLY when maskAll: true
480
- * If maskSpace is true, the spaces in the string will be masked.
481
- * This feature is to know the words and each word length but to hide the content
482
- * Default value is true
483
- */
484
- maskSpace: true
485
- };
486
-
487
- const str = "This is a test String";
488
-
489
- const strAfterMasking = MaskData.maskString(str, maskStringOptions);
490
-
491
- //Output: Th** ** a **** String
492
-
493
- ```
494
-
495
- ### Mask all characters in the String
496
- ```
497
- const str = "This is a test String";
498
-
499
- const strAfterMasking = MaskData.maskString(str, maskStringOptions);
500
-
501
- const stringMaskOptions = {
502
- maskWith: "*",
503
- values: [],
504
- maskAll: true,
505
- maskSpace: false // Do not mask space
506
- };
507
-
508
- // Output: **** ** * **** *****
509
- -------------------------------------------------------------------
510
-
511
- const str = "This is a test String";
512
-
513
- const strAfterMasking = MaskData.maskString(str, maskStringOptions);
514
-
515
- const stringMaskOptions = {
516
- maskWith: "*",
517
- values: [],
518
- maskAll: true,
519
- maskSpace: false // Mask spaces also
520
- };
521
-
522
- // Output: ********************
523
-
524
- ```
525
-
526
- ## Mask card number
527
- 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
528
- ```javascript
529
- const MaskData = require('./maskdata');
530
-
531
- const maskCardOptions = {
532
- // Character to mask the data. Default value is 'X'
533
- maskWith: "X",
534
-
535
- // Should be positive Integer
536
- // If the starting 'n' digits needs to be unmasked
537
- // Default value is 4
538
- unmaskedStartDigits: 4,
539
-
540
- //Should be positive Integer
541
- //If the ending 'n' digits needs to be unmasked
542
- // Default value is 1.
543
- unmaskedEndDigits: 1
544
- };
545
-
546
- const cardNumber = "1234-5678-1234-5678";
547
-
548
- const cardAfterMasking = MaskData.maskCard(cardNumber, maskCardOptions);
549
-
550
- //Output: 1234-XXXX-XXXX-XXX8
551
-
552
851
  ```
553
852
 
554
853
  # Report Bugs
555
- Please raise an issue in github: https://github.com/Sumukha1496/maskdata/issues
556
-
557
- # Run Tests
558
- 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.
559
- > 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
560
855
 
561
856
  # Give a Star
562
- 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
563
858
 
564
859
  # LICENSE - "MIT"
565
- Licenced under MIT Licence
860
+ Licensed under MIT Licence
566
861
 
567
862
  Copyright (c) 2019 Sumukha H S
568
863
 
@@ -578,8 +873,8 @@ copies or substantial portions of the Software.
578
873
 
579
874
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
580
875
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
581
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
582
- 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
583
878
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
584
879
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
585
880
  SOFTWARE.