Gathering detailed insights and metrics for @xdanangelxoqenpm/ullam-voluptas-dolorum
Gathering detailed insights and metrics for @xdanangelxoqenpm/ullam-voluptas-dolorum
Gathering detailed insights and metrics for @xdanangelxoqenpm/ullam-voluptas-dolorum
Gathering detailed insights and metrics for @xdanangelxoqenpm/ullam-voluptas-dolorum
npm install @xdanangelxoqenpm/ullam-voluptas-dolorum
Typescript
Module System
Node Version
NPM Version
48.1
Supply Chain
48.1
Quality
75.7
Maintenance
100
Vulnerability
99.6
License
JavaScript (100%)
Total Downloads
760
Last Day
2
Last Week
7
Last Month
24
Last Year
760
1,941 Commits
2 Watching
1 Branches
1 Contributors
Latest Version
1.0.0
Package Id
@xdanangelxoqenpm/ullam-voluptas-dolorum@1.0.0
Unpacked Size
45.07 kB
Size
12.42 kB
File Count
10
NPM Version
10.5.0
Node Version
20.12.2
Publised On
25 Apr 2024
Cumulative downloads
Total Downloads
Last day
100%
2
Compared to previous day
Last week
16.7%
7
Compared to previous week
Last month
-11.1%
24
Compared to previous month
Last year
0%
760
Compared to previous year
16
@xdanangelxoqenpm/ullam-voluptas-dolorum is a Node.js module to mask various kinds of data. With the help of @xdanangelxoqenpm/ullam-voluptas-dolorum, you can mask email, phone number, card number, JSON fields, password, etc...
Also, it provides utility methods to get a field, or replace a field from any complex/nested JSON.
npm i @xdanangelxoqenpm/ullam-voluptas-dolorum
"TypeError: validatedConfig[typeToFunctionMap[key][1]] is not iterable"
1const MaskData = require('./@xdanangelxoqenpm/ullam-voluptas-dolorum');
Follow this document for more details: Maskdata for typescript
This will mask the digits in a card number.
This will mask only the numerical data and not any non-numeric delimiters, alphabets, or any other types of data
1const MaskData = require('./@xdanangelxoqenpm/ullam-voluptas-dolorum'); 2 3const maskCardOptions = { 4 // Character to mask the data. The default value is '*' 5 maskWith: "*", 6 7 // Should be positive Integer 8 // If the starting 'n' digits need to be visible/unmasked 9 // Default value is 4 10 unmaskedStartDigits: 4, 11 12 // Should be positive Integer 13 // If the ending 'n' digits need to be visible/unmasked 14 // Default value is 1. 15 unmaskedEndDigits: 1 16}; 17 18const cardNumber = "1234-5678-1234-5678"; 19 20const cardAfterMasking = MaskData.maskCard(cardNumber, maskCardOptions); 21 22//Output: 1234-****-****-***8 23
Use this method instead of maskEmail(). To mask with the default options, don't pass the configurations.
1const MaskData = require('./@xdanangelxoqenpm/ullam-voluptas-dolorum'); 2 3const emailMask2Options = { 4 maskWith: "*", 5 unmaskedStartCharactersBeforeAt: 3, 6 unmaskedEndCharactersAfterAt: 2, 7 maskAtTheRate: false 8}; 9 10const email = "my.test.email@testEmail.com"; 11 12const maskedEmail = MaskData.maskEmail2(email, emailMask2Options); 13 14//Output: my.********@**********om 15
Here,
1const MaskData = require('./@xdanangelxoqenpm/ullam-voluptas-dolorum'); 2 3const emailMask2Options = { 4 maskWith: "*", 5 unmaskedStartCharactersBeforeAt: 0, 6 unmaskedEndCharactersAfterAt: 257, // Give a number which is more than the characters after @ 7 maskAtTheRate: false 8}; 9 10const email = "abcd@email.com"; 11 12const maskedEmail = MaskData.maskEmail2(email, emailMask2Options); 13 14//Output: ****@email.com 15
To mask with the default options, don't pass the configurations.
1const MaskData = require('./@xdanangelxoqenpm/ullam-voluptas-dolorum'); 2 3/** Default Options 4 maskWith: "*", 5 unmaskedStartCharactersBeforeAt: 3, 6 unmaskedEndCharactersAfterAt: 2, 7 maskAtTheRate: false 8**/ 9const email = "my.test.email@testEmail.com"; 10 11const maskedEmail = MaskData.maskEmail2(email); 12 13//Output: my.********@**********om 14
This is the new functionality in version 1.2.0+ to handle masking of multiple types of data in the JSON object with a single mask function call.
1const MaskData = require('./@xdanangelxoqenpm/ullam-voluptas-dolorum'); 2 3// Default configs are as below. If specific masking changes are needed, use the corresponding configs for each type of field. 4const defaultjsonMask2Configs = { 5 cardMaskOptions: defaultCardMaskOptions, // Optional 6 cardFields: [], // List of card fields to be masked 7 8 emailMaskOptions: defaultEmailMask2Options, // Optional 9 emailFields: [], // List of email fields to be masked 10 11 // For passwords, tokens, etc... 12 passwordMaskOptions: defaultPasswordMaskOptions, // Optional 13 passwordFields: [], // List of password fields to be masked 14 15 phoneMaskOptions: defaultPhoneMaskOptions, // Optional 16 phoneFields: [], // List of phone fields to be masked 17 18 stringMaskOptions: defaultStringMaskOptions, // Mandatory if stringFields are given. Otherwise, stringFields won't be masked 19 stringFields: [], // List of String fields to be masked 20 21 uuidMaskOptions: defaultUuidMaskOptions, // Optional 22 uuidFields: [], // List of UUID fields to be masked 23 24 jwtMaskOptions: defaultJwtMaskOptions, // Optional 25 jwtFields: [], // List of JWT fields to be masked 26 27 genericStrings: [ 28 { 29 config: defaultStringMaskV2Options, 30 fields: [] 31 } 32 ] 33};
NOTE: For details on the configs mentioned above, refer:
defaultCardMaskOptions
defaultEmailMask2Options
defaultPasswordMaskOptions
defaultPhoneMaskOptions
defaultStringMaskOptions
defaultUuidMaskOptions
defaultJwtMaskOptions
defaultStringMaskV2Options / generic String Maksing
1const defaultjsonMask2Configs = { 2 cardMaskOptions: { 3 maskWith: "*", 4 unmaskedStartDigits: 4, 5 unmaskedEndDigits: 1 6 }, 7 cardFields: [], 8 9 emailMaskOptions: { 10 maskWith: "*", 11 unmaskedStartCharactersBeforeAt: 3, 12 unmaskedEndCharactersAfterAt: 2, 13 maskAtTheRate: false 14 }, 15 emailFields: [], 16 17 passwordMaskOptions: { 18 maskWith: "*", 19 maxMaskedCharacters: 16, 20 unmaskedStartCharacters: 0, 21 unmaskedEndCharacters: 0 22 }, 23 passwordFields: [], 24 25 phoneMaskOptions: { 26 maskWith: "*", 27 unmaskedStartDigits: 4, 28 unmaskedEndDigits: 1 29 }, 30 phoneFields: [], 31 32 stringMaskOptions: { 33 maskWith: "*", 34 maskOnlyFirstOccurance: false, 35 values: [], 36 maskAll: false, 37 maskSpace: true 38 }, 39 stringFields: [], 40 41 uuidMaskOptions: { 42 maskWith: "*", 43 unmaskedStartCharacters: 0, 44 unmaskedEndCharacters: 0 45 }, 46 uuidFields: [], 47 48 jwtMaskOptions: { 49 maskWith: '*', 50 maxMaskedCharacters: 512, 51 maskDot: true, 52 maskHeader: true, 53 maskPayload: true, 54 maskSignature: true 55 }, 56 jwtFields: [], 57 // To extend the mask function to other types of data. 58 genericStrings: [ 59 { 60 config: { 61 maskWith: "*", 62 maxMaskedCharacters: 256, 63 unmaskedStartDigits: 0, 64 unmaskedEndDigits: 0 65 }, 66 fields: [] 67 } 68 ] 69}; 70
Example1:
1const jsonInput = { 2 'credit': '1234-5678-8765-1234', 3 'debit': '0000-1111-2222-3333', 4 'primaryEmail': 'primary@Email.com', 5 'secondaryEmail': 'secondary@Email.com', 6 'password': 'dummyPassword', 7 'homePhone': "+1 1234567890", 8 'workPhone': "+1 9876543210", 9 'addressLine1': "This is my addressline 1. This is my home", 10 'addressLine2': "AddressLine 2", 11 'uuid1': '123e4567-e89b-12d3-a456-426614174000', 12 'randomStrings': { 13 'row1': 'This is row 1 random string', 14 'row2': ['Entry1', 'Entry2', 'Entry3'], 15 'row3': { 16 'key1': 'Row3 Object 1', 17 'key2': 'Row3 Object 2', 18 'key3': ['Entry1', 'Entry2', 'Entry3'] 19 } 20 } 21}; 22 23const jsonMaskConfig = { 24 cardFields: ['credit', 'debit'], 25 emailFields: ['primaryEmail', 'secondaryEmail'], 26 passwordFields: ['password'], 27 phoneFields: ['homePhone', 'workPhone'], 28 stringMaskOptions: { 29 maskWith: "*", 30 maskOnlyFirstOccurance: false, 31 values: ["This"] 32 }, 33 stringFields: ['addressLine1', 'addressLine2'], 34 uuidFields: ['uuid1'], 35 genericStrings: [ 36 { 37 fields: ['randomStrings.row1'], 38 config: { 39 maskWith: '*', 40 unmaskedStartCharacters: 2, 41 unmaskedEndCharacters: 3, 42 maxMaskedCharacters: 8 43 } 44 }, 45 { fields: ['randomStrings.row2.*'], config: { maskWith: 'X', unmaskedEndCharacters: 1 } }, 46 { fields: ['randomStrings.row3.key1'] }, 47 { 48 fields: ['randomStrings.row3.key3.*'], 49 config: { maskWith: '@', unmaskedEndCharacters: 1 } 50 } 51 ] 52}; 53 54const maskedJsonOutput = maskData.maskJSON2(jsonInput, jsonMaskConfig); 55 56Output: 57{ 58 credit: '1234-****-****-***4', 59 debit: '0000-****-****-***3', 60 primaryEmail: 'pri****@*******om', 61 secondaryEmail: 'sec******@*******om', 62 password: '*************', 63 homePhone: '+1 1********0', 64 workPhone: '+1 9********0', 65 addressLine1: '**** is my addressline 1. **** is my home', 66 addressLine2: 'AddressLine 2', 67 uuid1: '********-****-****-****-************', 68 randomStrings: { 69 row1: 'Th***ing', 70 row2: ['XXXXX1', 'XXXXX2', 'XXXXX3'], 71 row3: { 72 key1: '*************', 73 key2: 'Row3 Object 2', 74 key3: ['@@@@@1', '@@@@@2', '@@@@@3'] 75 } 76 } 77} 78 79 80Example2: Mask with custom configs for each/any type of fields 81 82const jsonInput2 = { 83 'credit': '1234-5678-8765-1234', 84 'debit': '0000-1111-2222-3333', 85 'primaryEmail': 'primary@Email.com', 86 'secondaryEmail': 'secondary@Email.com', 87 'password': 'dummyPasswordANDdummyPassword', 88 'homePhone': "+1 1234567890", 89 'workPhone': "+1 9876543210", 90 'addressLine1': "This is my addressline 1. This is my home", 91 'addressLine2': "AddressLine 2", 92 'uuid1': '123e4567-e89b-12d3-a456-426614174000' 93}; 94 95const jsonMaskConfig2 = { 96 // Card 97 cardMaskOptions: { maskWith: "X", unmaskedStartDigits: 2,unmaskedEndDigits: 4 }, 98 cardFields: ['credit', 'debit'], 99 100 // Email 101 emailMaskOptions: { maskWith: "*", unmaskedStartCharactersBeforeAt: 2, unmaskedEndCharactersAfterAt: 2, maskAtTheRate: false }, 102 emailFields: ['primaryEmail', 'secondaryEmail'], 103 104 // Password 105 passwordMaskOptions: { maskWith: "*", maxMaskedCharacters: 10, unmaskedStartCharacters: 0, unmaskedEndCharacters: 0 }, 106 passwordFields: ['password'], 107 108 // Phone 109 phoneMaskOptions: { maskWith: "*", unmaskedStartDigits: 2, unmaskedEndDigits: 1 }, 110 phoneFields: ['homePhone', 'workPhone'], 111 112 // String 113 stringMaskOptions: { maskWith: "*", maskOnlyFirstOccurance: false, values: [], maskAll: true, maskSpace: false }, 114 stringFields: ['addressLine1', 'addressLine2'], 115 116 // UUID 117 uuidMaskOptions: { maskWith: "*", unmaskedStartCharacters: 4, unmaskedEndCharacters: 2 }, 118 uuidFields: ['uuid1'] 119}; 120 121const maskedJsonOutput2 = maskData.maskJSON2(jsonInput2, jsonMaskConfig2); 122 123Output: 124 125{ 126 credit: '12XX-XXXX-XXXX-1234', 127 debit: '00XX-XXXX-XXXX-3333', 128 primaryEmail: 'pr*****@*******om', 129 secondaryEmail: 'se*******@*******om', 130 password: '**********', 131 homePhone: '+1**********0', 132 workPhone: '+1**********0', 133 addressLine1: '**** ** ** *********** ** **** ** ** ****', 134 addressLine2: '*********** *', 135 uuid1: '123e****-****-****-****-**********00' 136}
Example3: Mask nested json fields -> Use dot(.) and Array([]) notation to specify the inner fields.
1 2const jsonInput2 = { 3 cards: { 4 creditCards: ['1234-5678-8765-1234', '1111-2222-1111-2222'], 5 debitCards: ['0000-1111-2222-3333', '2222-1111-3333-4444'] 6 }, 7 emails: { 8 primaryEmail: 'primary@Email.com', 9 secondaryEmail: 'secondary@Email.com' 10 }, 11 passwords: [ 12 ['dummyPasswordANDdummyPassword', 'dummyPasswordANDdummyPassword'] 13 ], 14 phones: { 15 homePhone: "+1 1234567890", 16 workPhone: "+1 9876543210", 17 }, 18 address: { 19 addressLine1: "This is my addressline 1. This is my home", 20 addressLine2: "AddressLine 2" 21 }, 22 uuids: { 23 uuid1: '123e4567-e89b-12d3-a456-426614174000' 24 }, 25 jwt: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1MTYyMzkwMjJ9.tbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQ' 26}; 27 28const jsonMaskConfig2 = { 29 // Card 30 cardMaskOptions: { maskWith: "X", unmaskedStartDigits: 2,unmaskedEndDigits: 4 }, 31 cardFields: ['cards.creditCards[0]', 'cards.creditCards[1]', 'cards.debitCards[0]', 'cards.debitCards[1]'], 32 33 // Email 34 emailMaskOptions: { maskWith: "*", unmaskedStartCharactersBeforeAt: 2, unmaskedEndCharactersAfterAt: 2, maskAtTheRate: false }, 35 emailFields: ['emails.primaryEmail', 'emails.secondaryEmail'], 36 37 // Password 38 passwordMaskOptions: { maskWith: "*", maxMaskedCharacters: 10, unmaskedStartCharacters: 0, unmaskedEndCharacters: 0 }, 39 passwordFields: ['passwords[0][0]]', 'passwords[0][1]'], 40 41 // Phone 42 phoneMaskOptions: { maskWith: "*", unmaskedStartDigits: 2, unmaskedEndDigits: 1 }, 43 phoneFields: ['phones.homePhone', 'phones.workPhone'], 44 45 // String 46 stringMaskOptions: { maskWith: "*", maskOnlyFirstOccurance: false, values: [], maskAll: true, maskSpace: false }, 47 stringFields: ['address.addressLine1', 'address.addressLine2'], 48 49 // UUID 50 uuidMaskOptions: { maskWith: "*", unmaskedStartCharacters: 4, unmaskedEndCharacters: 2 }, 51 uuidFields: ['uuids.uuid1'] 52 53 // JWT 54 jwtMaskOptions: { maskWith: '*', maxMaskedCharacters: 512, maskDot: true, maskHeader: true, maskPayload: true, maskSignature: true}, 55 jwtFields: ['jwt'] 56}; 57 58const maskedJsonOutput2 = MaskData.maskJSON2(jsonInput2, jsonMaskConfig2); 59// OUTPUT: 60{ 61 cards: { 62 creditCards: [ '12XX-XXXX-XXXX-1234', '11XX-XXXX-XXXX-2222' ], 63 debitCards: [ '00XX-XXXX-XXXX-3333', '22XX-XXXX-XXXX-4444' ] 64 }, 65 emails: { 66 primaryEmail: 'pr*****@*******om', 67 secondaryEmail: 'se*******@*******om' 68 }, 69 passwords: [ [ '**********', '**********' ] ], 70 phones: { homePhone: '+1**********0', workPhone: '+1**********0' }, 71 address: { 72 addressLine1: '**** ** ** *********** ** **** ** ** ****', 73 addressLine2: '*********** *' 74 }, 75 uuids: { uuid1: '123e****-****-****-****-**********00' }, 76 jwt: '*********************************************************************************************************' 77} 78
1const MaskData = require('./@xdanangelxoqenpm/ullam-voluptas-dolorum'); 2 3const maskPasswordOptions = { 4 // Character to mask the data 5 // default value is '*' 6 maskWith: "*", 7 8 // To limit the *s in the response when the password length is more 9 // Default value is 16 10 maxMaskedCharacters: 16, 11 12 // To show(not mask) first 'n' characters in the password/secret key. 13 // Default value is 0. 14 unmaskedStartCharacters: 0, 15 16 // To show(not mask) last 'n' characters in the password/secret key. 17 // Default value is 0. 18 unmaskedEndCharacters: 0 19}; 20 21const password = "Password1$"; 22 23const maskedPassword = MaskData.maskPassword(password, maskPasswordOptions); 24 25//Output: ********** 26 27## Mask Password with the default configuration 28To mask with the default options, don't pass the configurations. 29```javascript 30const MaskData = require('./@xdanangelxoqenpm/ullam-voluptas-dolorum'); 31 32 /** Default Options 33 maskWith: "*" 34 maxMaskedCharacters: 16, 35 unmaskedStartCharacters: 0, 36 unmaskedEndCharacters: 0 37 **/ 38 39const password = "Password1$"; 40 41const maskedPassword = MaskData.maskPassword(password) 42
1const MaskData = require('./@xdanangelxoqenpm/ullam-voluptas-dolorum'); 2 3const maskPasswordOptions = { 4 maskWith: "X", 5 maxMaskedCharacters: 20, // To limit the output String length to 20. 6 unmaskedStartCharacters: 4, 7 unmaskedEndCharacters: 9 // As the last 9 characters of the secret key is meta info which can be printed for debugging or other purposes 8}; 9 10const password = "TEST:U2VjcmV0S2V5MQ==:CLIENT-A"; 11 12const maskedPassword = MaskData.maskPassword(password, maskPasswordOptions); 13//Output: TESTXXXXXXX:CLIENT-A 14 15maskPasswordOptions.unmaskedStartCharacters = 0; 16 17const maskedPassword = MaskData.maskPassword(password, maskPasswordOptions); 18//Output: XXXXXXXXXXX:CLIENT-A
1const MaskData = require('./@xdanangelxoqenpm/ullam-voluptas-dolorum'); 2 3const maskPhoneOptions = { 4 // Character to mask the data 5 // default value is '*' 6 maskWith: "*", 7 8 //Should be positive Integer 9 // If the starting 'n' digits need to be unmasked 10 // Default value is 4 11 unmaskedStartDigits: 5, 12 13 // Should be positive Integer 14 //If the ending 'n' digits need to be unmasked 15 // Default value is 1 16 unmaskedEndDigits: 1 17}; 18 19const phoneNumber = "+911234567890"; 20 21const maskedPhoneNumber = MaskData.maskPhone(phoneNumber, maskPhoneOptions); 22//Output: +9112*******0 23
To mask with the default options, don't pass the configurations.
1const MaskData = require('./@xdanangelxoqenpm/ullam-voluptas-dolorum'); 2 3/** Default Options 4 maskWith: "*" 5 unmaskedStartDigits: 4 6 unmaskedEndDigits: 1 7**/ 8const phoneNumber = "+111234567890"; 9 10const maskedPhoneNumber = MaskData.maskPhone(phoneNumber); 11 12//Output: +911********0 13
This functionality can be used to mask any string with the below configs.
1const MaskData = require('./@xdanangelxoqenpm/ullam-voluptas-dolorum'); 2 3const defaultStringMaskV2Options = { 4 // Character to mask the data 5 // default value is '*' 6 maskWith: "*", 7 8 // This is to limit the maximun characters in the output. 9 // Default value is 256 10 maxMaskedCharacters: 256, 11 12 // To show(not mask) first 'n' characters of the string. 13 // Default value is 0. 14 unmaskedStartCharacters: 0, 15 16 // To show(not mask) last 'n' characters of the string. 17 // Default value is 0. 18 unmaskedEndCharacters: 0 19}; 20 21const string1 = "Password1$"; 22 23const maskedString = MaskData.maskStringV2(string1, defaultStringMaskV2Options); 24 25//Output: **********
1const MaskData = require('./@xdanangelxoqenpm/ullam-voluptas-dolorum'); 2 3const stringMaskV2Options = { 4 maskWith: "X", 5 maxMaskedCharacters: 20, // To limit the output length to 20. 6 unmaskedStartCharacters: 4, 7 unmaskedEndCharacters: 9 8}; 9 10const secret = "TEST:U2VjcmV0S2V5MQ==:CLIENT-A"; 11 12const maskedSecret = MaskData.maskStringV2(password, stringMaskV2Options); 13//Output: TESTXXXXXXX:CLIENT-A 14 15stringMaskV2Options.unmaskedStartCharacters = 0; 16 17maskedSecret = MaskData.maskStringV2(password, stringMaskV2Options); 18//Output: XXXXXXXXXXX:CLIENT-A
This will mask the characters or words if present in the given string.
1const MaskData = require('./@xdanangelxoqenpm/ullam-voluptas-dolorum'); 2 3const maskStringOptions = { 4 // Character to mask the data. The default value is '*' 5 maskWith: "*", 6 7 /** 8 * It is the words/substrings to mask. 9 * Should be an array of strings. 10 * Can give multiple words/substrings. 11 * values[] can be used only when maskAll is false. If maskAll is true, then this is of no use. 12 */ 13 values: ['is', 'test'], 14 15 /** 16 * If to mask only the first occurrence of each word/substring in the given string 17 * Should be boolean 18 * Default value is false 19 */ 20 maskOnlyFirstOccurance: false, 21 22 /** 23 * If to mask all the characters in a string make maskAll: true 24 * If maskAll is true, the words/substrings inside values[] will not be considered. 25 * Default value is false 26 */ 27 maskAll: false, 28 29 /** 30 * This is to mask/not mask the spaces in a string when masking all the characters. 31 * Can be used ONLY when maskAll: true 32 * If maskSpace is false, the spaces in the string will not be masked. 33 * This feature is to know the words and each word's length but to hide the content 34 * Default value is true 35 */ 36 maskSpace: true 37}; 38 39const str = "This is a test String"; 40 41const strAfterMasking = MaskData.maskString(str, maskStringOptions); 42 43//Output: Th** ** a **** String 44
1const str = "This is a test String"; 2 3const strAfterMasking = MaskData.maskString(str, maskStringOptions); 4 5const stringMaskOptions = { 6 maskWith: "*", 7 values: [], 8 maskAll: true, 9 maskSpace: false // Maks all characters except spaces 10}; 11 12// Output: **** ** * **** ***** 13 14const str = "This is a test String"; 15 16const strAfterMasking = MaskData.maskString(str, maskStringOptions); 17 18const stringMaskOptions = { 19 maskWith: "*", 20 values: [], 21 maskAll: true, 22 maskSpace: true // Mask all characters including spaces 23}; 24 25// Output: ******************** 26
This will mask the alphanumeric characters in a UUID.
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 regex:
/[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;).
If the input is not a valid UUID, it will return the input itself without masking.
1const MaskData = require('./@xdanangelxoqenpm/ullam-voluptas-dolorum'); 2 3const maskUuidOptions = { 4 // Character to mask the data. The default value is '*' 5 maskWith: "*", 6 7 // Should be a positive Integer <= 32 8 // If the starting 'n' alphanumeric characters need to be visible/unmasked 9 // Default value is 0 10 unmaskedStartCharacters: 0, 11 12 //Should be a positive Integer <= 32 13 //If the ending 'n' alphanumeric characters need to be visible/unmasked 14 // Default value is 0 15 unmaskedEndCharacters: 0 16}; 17 18const uuidInput = "123e4567-e89b-12d3-a456-426614174000"; 19 20const uuidAfterMasking = MaskData.maskUuid(uuidInput, maskUuidOptions); 21 22// Output: ********-****-****-****-************ 23
This function returns the masked JWT tokens. A JWT token consists of 3 parts separated by 2 dots. i.e, {header}.{payload}.{signature}
. Based on the usecase, we will have to mask/keep a part/s of jwt token. With @xdanangelxoqenpm/ullam-voluptas-dolorum you can mask JWT tokens with all possible combinations.
If the input is null, undefined, non-string, string with length < 5, doesn't contain 2 dots(invalid JWT format), the function will return the input as it is without masking.
1 2const MaskData = require('./@xdanangelxoqenpm/ullam-voluptas-dolorum'); 3 4const jwtMaskOptions = { 5 // Character to mask the data. The default value is '*' 6 maskWith: '*', 7 8 // Max masked characters in the output(EXCLUDING the unmasked characters). Default value is 512 9 maxMaskedCharacters: 512, 10 11 // Config to mask OR keep the dots(.). Default value is true, i.e, mask dots 12 maskDot: true, 13 14 // Config to mask OR keep the first part of the JWT. i.e, the header part. Default value is true, i.e, mask the header part 15 maskHeader: true, 16 17 // Config to mask OR keep the second part of the JWT. i.e, the payload part. Default value is true, i.e, mask the payload part 18 maskPayload: true, 19 20 // Config to mask OR keep the third part of the JWT. i.e, the signature part. Default value is true, i.e, mask the signature part 21 maskSignature: true 22}; 23 24const jwt = 25 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1MTYyMzkwMjJ9.tbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQ'; 26 27/** In this example, 28 * Header = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 29 * Payload = eyJpYXQiOjE1MTYyMzkwMjJ9 30 * Signature = tbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQ 31 */ 32const maskedJwt = MaskData.maskJwt(jwt, jwtMaskOptions); 33 34// Output: 35********************************************************************************************************* 36
1 2const MaskData = require('./@xdanangelxoqenpm/ullam-voluptas-dolorum'); 3 4const jwtMaskOptions = { 5 maskWith: '*', 6 maxMaskedCharacters: 512, 7 maskDot: false, 8 maskHeader: false, 9 maskPayload: false, 10 maskSignature: true 11}; 12 13const jwt = 14 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1MTYyMzkwMjJ9.tbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQ'; 15 16/** In this example, 17 * Header = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 18 * Payload = eyJpYXQiOjE1MTYyMzkwMjJ9 19 * Signature = tbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQ 20 */ 21const maskedJwt = MaskData.maskJwt(jwt, jwtMaskOptions); 22 23// Output: 24eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1MTYyMzkwMjJ9.******************************************* 25
1 2const MaskData = require('./@xdanangelxoqenpm/ullam-voluptas-dolorum'); 3 4const jwtMaskOptions = { 5 maskWith: '*', 6 maxMaskedCharacters: 512, 7 maskDot: false, 8 maskHeader: true, 9 maskPayload: false, 10 maskSignature: true 11}; 12 13const jwt = 14 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1MTYyMzkwMjJ9.tbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQ'; 15 16/** In this example, 17 * Header = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 18 * Payload = eyJpYXQiOjE1MTYyMzkwMjJ9 19 * Signature = tbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQ 20 */ 21const maskedJwt = MaskData.maskJwt(jwt, jwtMaskOptions); 22 23// Output: 24************************************.eyJpYXQiOjE1MTYyMzkwMjJ9.******************************************* 25
1 2const MaskData = require('./@xdanangelxoqenpm/ullam-voluptas-dolorum'); 3 4const jwtMaskOptions = { 5 maskWith: '*', 6 maxMaskedCharacters: 16, 7 maskDot: false, 8 maskHeader: true, 9 maskPayload: true, 10 maskSignature: true 11}; 12 13const jwt = 14 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1MTYyMzkwMjJ9.tbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQ'; 15 16/** In this example, 17 * Header = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 18 * Payload = eyJpYXQiOjE1MTYyMzkwMjJ9 19 * Signature = tbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQ 20 */ 21const maskedJwt = MaskData.maskJwt(jwt, jwtMaskOptions); 22 23// Output: 24******.*****.***** 25
This method returns the value of the nested JSON property if it exists. Otherwise, it returns undefined
1const MaskData = require('./@xdanangelxoqenpm/ullam-voluptas-dolorum'); 2 3const innerPropety = Maskdata.getInnerProperty(object, field); 4 5Example: 6 7const nestedObject = { 8 level1: { 9 field1: "field1", 10 level2: { 11 field2: "field2", 12 level3: { 13 field3: "field3", 14 field4: [ { Hello: "world" }, { Hello: "Newworld" }, "Just a String" ] 15 } 16 } 17 }, 18 value1: "value" 19}; 20 21const innerPropety = Maskdata.getInnerProperty(nestedObject, 'level1.level2.level3.field4[0].Hello'); 22
To replace a value by keeping the type.
1 2const input = { 3 name: "John", 4 age: 33, 5 married: true 6} 7 8let afterReplacing = MaskData.replaceValue(input, 'age', 99); 9afterReplacing = MaskData.replaceValue(input, 'married', false); 10 11//Output: 12Before replacing: {"name":"John","age":33,"married":true} 13After replacing: {"name":"John","age":99,"married":false} 14 15Type of age: number 16Type of married: boolean 17
1const jsonInput = { 2 cards: [ 3 { 4 number: '1234-5678-8765-1234' 5 }, 6 { 7 number: '1111-2222-1111-2222' 8 }, 9 { 10 number: '0000-1111-2222-3333' 11 }, 12 { 13 name: "No card number here" 14 } 15 ], 16 emails: { 17 primaryEmail: 'primary@Email.com', 18 secondaryEmail: 'secondary@Email.com', 19 moreEmails: ["email1@email.com", "email2@email.com", "email3@email.com", {childEmail: "child@child.com", secondChild: {nestedkid: "hello@hello.com"}}] 20 }, 21 array: ["element1", "element22", "element333"], 22 jwt: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJsb2wiLCJuYW1lIjoiVGVzdCIsImlhdCI6ImxvbCJ9.XNDxZcBWWEKYkCiu6XFGmAeuPF7iFnI7Sdv91gVZJMU' 23}; 24 25const jsonMaskConfig = { 26 cardMaskOptions: { maskWith: "X", unmaskedStartDigits: 0, unmaskedEndDigits: 0}, 27 28 emailMaskOptions: { maskWith: "*", unmaskedStartCharactersBeforeAt: 0, 29 unmaskedEndCharactersAfterAt: 0, maskAtTheRate: false }, 30 31 stringMaskOptions: { maskWith: "?", maskOnlyFirstOccurance: false, values: [], maskAll: true, maskSpace: false }, 32 jwtMaskOptions: { maskWith: '*', maxMaskedCharacters: 32, maskDot: false, maskHeader: true, maskPayload: true, maskSignature: true}, 33 34 cardFields: ['cards[*].number'], 35 emailFields: ['emails.*'], 36 stringFields: ['array.*'], 37 jwtFields: ['jwt'] 38} 39 40const maskedOutput = maskData.maskJSON2(jsonInput, jsonMaskConfig); 41 42// Output: 43{ 44 "cards": [ 45 { 46 "number": "XXXX-XXXX-XXXX-XXXX" 47 }, 48 { 49 "number": "XXXX-XXXX-XXXX-XXXX" 50 }, 51 { 52 "number": "XXXX-XXXX-XXXX-XXXX" 53 }, 54 { 55 "name": "No card number here" 56 } 57 ], 58 "emails": { 59 "primaryEmail": "*******@*********", 60 "secondaryEmail": "*********@*********", 61 "moreEmails": [ 62 "******@*********", 63 "******@*********", 64 "******@*********", 65 { 66 "childEmail": "*****@*********", 67 "secondChild": { 68 "nestedkid": "*****@*********" 69 } 70 } 71 ] 72 }, 73 "array": ["????????", "?????????", "??????????"], 74 "jwt": "************.**********.**********" 75} 76
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/xdanangelxoqenpm/ullam-voluptas-dolorum/issues
You can give a star at: https://github.com/xdanangelxoqenpm/ullam-voluptas-dolorum/stargazers
Licensed under MIT Licence
Copyright (c) 2019 Sumukha H S
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
No vulnerabilities found.
No security vulnerabilities found.