### Install Maskdata Module Source: https://context7.com/sumukha1496/maskdata/llms.txt Install the maskdata module using npm. This command should be run in your project's root directory. ```bash npm i maskdata ``` -------------------------------- ### Mask Password Example Source: https://github.com/sumukha1496/maskdata/blob/master/MASKDATA_FOR_TYPESCRIPT.md Demonstrates how to mask a password using the maskPassword function with custom options. Ensure PasswordMaskOptions are correctly defined. ```javascript import { maskPassword, PasswordMaskOptions } from 'maskdata'; const password: string = 'myPassword123'; const options: PasswordMaskOptions = { maskWith: '*', maxMaskedCharacters: 10, fixedOutputLength: undefined, unmaskedStartCharacters: 2, unmaskedEndCharacters: 2 }; const maskedPassword = maskPassword(password, options); ``` -------------------------------- ### Mask strings using V2 options Source: https://github.com/sumukha1496/maskdata/blob/master/README.md Demonstrates masking a string with specific start and end character visibility using maskStringV2. ```javascript const MaskData = require('./maskdata'); const stringMaskV2Options = { maskWith: "X", maxMaskedCharacters: 20, // To limit the output length to 20. unmaskedStartCharacters: 4, unmaskedEndCharacters: 9, fixedOutputLength: undefined }; const secret = "TEST:U2VjcmV0S2V5MQ==:CLIENT-A"; const maskedSecret = MaskData.maskStringV2(password, stringMaskV2Options); //Output: TESTXXXXXXX:CLIENT-A stringMaskV2Options.unmaskedStartCharacters = 0; maskedSecret = MaskData.maskStringV2(password, stringMaskV2Options); //Output: XXXXXXXXXXX:CLIENT-A ``` -------------------------------- ### Mask all characters in a string Source: https://github.com/sumukha1496/maskdata/blob/master/README.md Examples of masking all characters in a string with or without preserving spaces. ```javascript const str = "This is a test String"; const strAfterMasking = MaskData.maskString(str, maskStringOptions); const stringMaskOptions = { maskWith: "*", values: [], maskAll: true, maskSpace: false // Maks all characters except spaces }; // Output: **** ** * **** ***** const str = "This is a test String"; const strAfterMasking = MaskData.maskString(str, maskStringOptions); const stringMaskOptions = { maskWith: "*", values: [], maskAll: true, maskSpace: true // Mask all characters including spaces }; // Output: ******************** ``` -------------------------------- ### Mask Password with Custom Configuration Source: https://github.com/sumukha1496/maskdata/blob/master/documentation/mask_password_with_the_default_configuration.md Applies custom masking options to preserve specific start and end characters while masking the middle portion. ```javascript const MaskData = require('./maskdata'); const maskPasswordOptions = { maskWith: "X", maxMaskedCharacters: 20, // To limit the output String length to 20. unmaskedStartCharacters: 4, unmaskedEndCharacters: 9, // As the last 9 characters of the secret key is meta info which can be printed for debugging or other purposes fixedOutputLength: undefined }; const password = "TEST:U2VjcmV0S2V5MQ==:CLIENT-A"; const maskedPassword = MaskData.maskPassword(password, maskPasswordOptions); //Output: TESTXXXXXXX:CLIENT-A maskPasswordOptions.unmaskedStartCharacters = 0; const maskedPassword = MaskData.maskPassword(password, maskPasswordOptions); //Output: XXXXXXXXXXX:CLIENT-A ``` -------------------------------- ### Mask Multiple Fields with Wildcards Source: https://github.com/sumukha1496/maskdata/blob/master/README.md This example shows how to mask fields within arrays and nested objects using wildcard characters in the field paths. It demonstrates masking all elements in an array and specific nested fields. ```javascript const jsonInput = { cards: [ { number: '1234-5678-8765-1234' }, { number: '1111-2222-1111-2222' }, { number: '0000-1111-2222-3333' }, { name: "No card number here" } ], emails: { primaryEmail: 'primary@Email.com', secondaryEmail: 'secondary@Email.com', moreEmails: ["email1@email.com", "email2@email.com", "email3@email.com", {childEmail: "child@child.com", secondChild: {nestedkid: "hello@hello.com"}}] }, array: ["element1", "element22", "element333"], jwt: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJsb2wiLCJuYW1lIjoiVGVzdCIsImlhdCI6ImxvbCJ9.XNDxZcBWWEKYkCiu6XFGmAeuPF7iFnI7Sdv91gVZJMU' }; const jsonMaskConfig = { cardMaskOptions: { maskWith: "X", unmaskedStartDigits: 0, unmaskedEndDigits: 0}, emailMaskOptions: { maskWith: "*", unmaskedStartCharactersBeforeAt: 0, unmaskedEndCharactersAfterAt: 0, maskAtTheRate: false }, stringMaskOptions: { maskWith: "?", maskOnlyFirstOccurance: false, values: [], maskAll: true, maskSpace: false }, jwtMaskOptions: { maskWith: '*', maxMaskedCharacters: 32, maskDot: false, maskHeader: true, maskPayload: true, maskSignature: true}, cardFields: ['cards[*].number'], emailFields: ['emails.*'], stringFields: ['array.*'], jwtFields: ['jwt'] } const maskedOutput = maskData.maskJSON2(jsonInput, jsonMaskConfig); ``` -------------------------------- ### maskStringV2 Source: https://context7.com/sumukha1496/maskdata/llms.txt A generic string masking function that allows for configurable output length and visibility of characters at the start and end positions. ```APIDOC ## maskStringV2 ### Description Generic string masking function with configurable output length and character visibility at start/end positions. ### Method N/A (This is a library function, not an API endpoint) ### Endpoint N/A ### Parameters #### Request Body (Implicit) - **secret** (string) - The string to be masked. - **options** (object) - Configuration options for masking: - **maskWith** (string) - Character to mask with (default: '*'). - **maxMaskedCharacters** (number) - Maximum output length (default: 256). - **fixedOutputLength** (number | undefined) - Fixed output length if set. - **unmaskedStartCharacters** (number) - Starting characters to keep visible (default: 0). - **unmaskedEndCharacters** (number) - Ending characters to keep visible (default: 0). ### Request Example ```javascript const MaskData = require('maskdata'); const stringMaskOptions = { maskWith: "*", maxMaskedCharacters: 256, fixedOutputLength: undefined, unmaskedStartCharacters: 0, unmaskedEndCharacters: 0 }; const secret = "SensitiveData123"; const maskedString = MaskData.maskStringV2(secret, stringMaskOptions); // Output: **************** const customOptions = { maskWith: "X", maxMaskedCharacters: 20, unmaskedStartCharacters: 4, unmaskedEndCharacters: 4 }; const maskedCustom = MaskData.maskStringV2("TEST:SecretData:INFO", customOptions); // Output: TESTXXXXXXXXXXINFO ``` ### Response #### Success Response (200) - **maskedString** (string) - The masked string. #### Response Example ```json { "maskedString": "****************" } ``` ``` -------------------------------- ### Mask Email with Custom Options Source: https://github.com/sumukha1496/maskdata/blob/master/documentation/mask_email_id.md Applies masking to an email address using specific character counts for the start and end segments. ```javascript const MaskData = require('./maskdata'); const emailMask2Options = { maskWith: "*", unmaskedStartCharactersBeforeAt: 3, unmaskedEndCharactersAfterAt: 2, maskAtTheRate: false }; const email = "my.test.email@testEmail.com"; const maskedEmail = MaskData.maskEmail2(email, emailMask2Options); //Output: my.********@**********om ``` -------------------------------- ### CardMaskOptions Interface Source: https://github.com/sumukha1496/maskdata/blob/master/MASKDATA_FOR_TYPESCRIPT.md Defines the configuration options for masking credit card numbers. Specify the masking character and the number of digits to keep unmasked at the start and end. ```typescript { maskWith?: string; unmaskedStartDigits?: number; unmaskedEndDigits?: number; } ``` -------------------------------- ### UuidMaskOptions Interface Source: https://github.com/sumukha1496/maskdata/blob/master/MASKDATA_FOR_TYPESCRIPT.md Defines configuration options for masking UUIDs. Customize the masking character and the number of characters to keep unmasked at the start and end. ```typescript { maskWith?: string; unmaskedStartCharacters?: number; unmaskedEndCharacters?: number; } ``` -------------------------------- ### maskEmail2 Method Source: https://github.com/sumukha1496/maskdata/blob/master/documentation/mask_email_id.md This method masks an email address based on provided configuration options. It supports defining unmasked start characters before the '@' and unmasked end characters after the '@'. ```APIDOC ## maskEmail2(email, options) ### Description Masks an email address using custom configuration options. If no options are provided, default masking is applied. ### Parameters - **email** (string) - Required - The email address to be masked. - **options** (object) - Optional - Configuration object: - **maskWith** (string) - Character used for masking (default: '*'). - **unmaskedStartCharactersBeforeAt** (number) - Number of characters before '@' to remain unmasked. - **unmaskedEndCharactersAfterAt** (number) - Number of characters after '@' to remain unmasked. - **maskAtTheRate** (boolean) - Whether to mask the '@' symbol itself. ### Request Example const emailMask2Options = { maskWith: "*", unmaskedStartCharactersBeforeAt: 3, unmaskedEndCharactersAfterAt: 2, maskAtTheRate: false }; const maskedEmail = MaskData.maskEmail2("my.test.email@testEmail.com", emailMask2Options); ### Response - **maskedEmail** (string) - The resulting masked email string. ``` -------------------------------- ### Get Nested JSON Property Source: https://github.com/sumukha1496/maskdata/blob/master/README.md Retrieves the value of a nested JSON property using a dot-notation string path. Returns undefined if the property does not exist. ```javascript const MaskData = require('./maskdata'); const innerPropety = Maskdata.getInnerProperty(object, field); Example: const nestedObject = { level1: { field1: "field1", level2: { field2: "field2", level3: { field3: "field3", field4: [ { Hello: "world" }, { Hello: "Newworld" }, "Just a String" ] } } }, value1: "value" }; const innerPropety = Maskdata.getInnerProperty(nestedObject, 'level1.level2.level3.field4[0].Hello'); ``` -------------------------------- ### Recursive Card Number Masking Source: https://github.com/sumukha1496/maskdata/blob/master/README.md Apply recursive masking to card numbers using specific card masking configurations. This allows for partial unmasking of digits at the start and end. ```javascript const inputJson = { cards: [ { number: "1234-5678-0123-0000" }, { number: "1111-2222-3333-4444" }, { number: "2222-4444-6666-8888" }, { number: "1111-3333-5555-7777" }, { number: "0000-0000-0000-0000" } ] }; const cardfieldsToMask = ["*number"]; // Specify the field with a '*' at the beginning and NO dot(.) anywhere else in that field. const jsonMaskConfig = { cardMaskOptions: { maskWith: "*", unmaskedStartDigits: 4, unmaskedEndDigits: 1 }, cardFields: cardfieldsToMask, }; const maskedOutput = maskData.maskJSON2(inputJson, jsonMaskConfig); // Output: { cards: [ { number: '1234-****-****-***0' }, { number: '1111-****-****-***4' }, { number: '2222-****-****-***8' }, { number: '1111-****-****-***7' }, { number: '0000-****-****-***0' } ] } ``` -------------------------------- ### Mask Phone Numbers Source: https://context7.com/sumukha1496/maskdata/llms.txt Masks phone numbers while preserving a configurable number of starting and ending digits. Only numerical digits are masked. Options include the masking character, number of starting digits to keep visible, and number of ending digits to keep visible. ```javascript const MaskData = require('maskdata'); const maskPhoneOptions = { maskWith: "*", // Character to mask with (default: '*') unmaskedStartDigits: 5, // Starting digits to keep visible (default: 4) unmaskedEndDigits: 1 // Ending digits to keep visible (default: 1) }; const phoneNumber = "+911234567890"; const maskedPhone = MaskData.maskPhone(phoneNumber, maskPhoneOptions); // Output: +9112*******0 // With default options const maskedDefault = MaskData.maskPhone("+111234567890"); // Output: +111********0 ``` -------------------------------- ### Basic JSON Masking with Default Configurations Source: https://github.com/sumukha1496/maskdata/blob/master/documentation/mask_email_id_with_the_default_configuration.md Demonstrates masking common sensitive fields like credit cards, emails, and phone numbers using default masking options. Ensure the 'maskData' library is imported. ```javascript const jsonInput = { 'credit': '1234-5678-8765-1234', 'debit': '0000-1111-2222-3333', 'primaryEmail': 'primary@Email.com', 'secondaryEmail': 'secondary@Email.com', 'password': 'dummyPassword', 'homePhone': "+1 1234567890", 'workPhone': "+1 9876543210", 'addressLine1': "This is my addressline 1. This is my home", 'addressLine2': "AddressLine 2", 'uuid1': '123e4567-e89b-12d3-a456-426614174000', 'randomStrings': { 'row1': 'This is row 1 random string', 'row2': ['Entry1', 'Entry2', 'Entry3'], 'row3': { 'key1': 'Row3 Object 1', 'key2': 'Row3 Object 2', 'key3': ['Entry1', 'Entry2', 'Entry3'] } } }; const jsonMaskConfig = { cardFields: ['credit', 'debit'], emailFields: ['primaryEmail', 'secondaryEmail'], passwordFields: ['password'], phoneFields: ['homePhone', 'workPhone'], stringMaskOptions: { maskWith: "*", maskOnlyFirstOccurance: false, values: ["This"] }, stringFields: ['addressLine1', 'addressLine2'], uuidFields: ['uuid1'], genericStrings: [ { fields: ['randomStrings.row1'], config: { maskWith: '*', unmaskedStartCharacters: 2, unmaskedEndCharacters: 3, maxMaskedCharacters: 8 } }, { fields: ['randomStrings.row2.*'], config: { maskWith: 'X', unmaskedEndCharacters: 1 } }, { fields: ['randomStrings.row3.key1'] }, { fields: ['randomStrings.row3.key3.*'], config: { maskWith: '@', unmaskedEndCharacters: 1 } } ] }; const maskedJsonOutput = maskData.maskJSON2(jsonInput, jsonMaskConfig); ``` -------------------------------- ### Initialize Maskdata Source: https://github.com/sumukha1496/maskdata/blob/master/documentation/main.md Basic import statement required to use the maskdata module. ```javascript const MaskData = require('./maskdata'); ``` -------------------------------- ### All Available Imports Source: https://github.com/sumukha1496/maskdata/blob/master/MASKDATA_FOR_TYPESCRIPT.md Lists all available functions and types that can be imported from the maskdata package for various masking operations. ```javascript import { maskPassword, PasswordMaskOptions, maskJSON2, JsonMask2Configs, maskPhone, PhoneMaskOptions, maskEmail2, EmailMask2Options, maskCard, CardMaskOptions, maskString, StringMaskOptions, maskUuid, UuidMaskOptions, maskJwt, JwtMaskOptions, maskStringV2, GenericStringMaskOptions, StringMaskV2Options, getInnerProperty, replaceValue } from 'maskdata'; ``` -------------------------------- ### Configure and Use maskStringV2 Source: https://context7.com/sumukha1496/maskdata/llms.txt Use maskStringV2 for generic string masking with options for mask character, maximum length, fixed output length, and visible start/end characters. Requires importing the MaskData module. ```javascript const MaskData = require('maskdata'); const stringMaskOptions = { maskWith: "*", // Character to mask with (default: '*') maxMaskedCharacters: 256, // Maximum output length (default: 256) fixedOutputLength: undefined, // Fixed output length if set unmaskedStartCharacters: 0, // Starting characters to keep visible (default: 0) unmaskedEndCharacters: 0 // Ending characters to keep visible (default: 0) }; const secret = "SensitiveData123"; const maskedString = MaskData.maskStringV2(secret, stringMaskOptions); // Output: **************** // With custom visibility const customOptions = { maskWith: "X", maxMaskedCharacters: 20, unmaskedStartCharacters: 4, unmaskedEndCharacters: 4 }; const maskedCustom = MaskData.maskStringV2("TEST:SecretData:INFO", customOptions); // Output: TESTXXXXXXXXXXINFO ``` -------------------------------- ### Mask Password with Default Configuration Source: https://github.com/sumukha1496/maskdata/blob/master/documentation/mask_password_with_the_default_configuration.md Uses the default library settings to mask a password string. ```javascript const MaskData = require('./maskdata'); /** Default Options maskWith: "*" maxMaskedCharacters: 16, unmaskedStartCharacters: 0, fixedOutputLength: undefined, unmaskedEndCharacters: 0 **/ const password = "Password1$"; const maskedPassword = MaskData.maskPassword(password) ``` -------------------------------- ### Mask JWT Token with Default Options Source: https://github.com/sumukha1496/maskdata/blob/master/documentation/mask_jwt_token.md Demonstrates masking all parts of a JWT token using default configuration settings. ```javascript const MaskData = require('./maskdata'); const jwtMaskOptions = { // Character to mask the data. The default value is '*' maskWith: '*', // Max masked characters in the output(EXCLUDING the unmasked characters). Default value is 512 maxMaskedCharacters: 512, // Config to mask OR keep the dots(.). Default value is true, i.e, mask dots maskDot: true, // 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 maskHeader: true, // 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 maskPayload: true, // 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 maskSignature: true }; const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1MTYyMzkwMjJ9.tbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQ'; /** In this example, * Header = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 * Payload = eyJpYXQiOjE1MTYyMzkwMjJ9 * Signature = tbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQ */ const maskedJwt = MaskData.maskJwt(jwt, jwtMaskOptions); // Output: ********************************************************************************************************* ``` -------------------------------- ### Mask JSON with Custom Field-Specific Configurations Source: https://github.com/sumukha1496/maskdata/blob/master/README.md Shows how to apply custom masking options for different field types like cards, emails, and passwords. ```javascript const jsonInput2 = { 'credit': '1234-5678-8765-1234', 'debit': '0000-1111-2222-3333', 'primaryEmail': 'primary@Email.com', 'secondaryEmail': 'secondary@Email.com', 'password': 'dummyPasswordANDdummyPassword', 'homePhone': "+1 1234567890", 'workPhone': "+1 9876543210", 'addressLine1': "This is my addressline 1. This is my home", 'addressLine2': "AddressLine 2", 'uuid1': '123e4567-e89b-12d3-a456-426614174000' }; const jsonMaskConfig2 = { // Card cardMaskOptions: { maskWith: "X", unmaskedStartDigits: 2,unmaskedEndDigits: 4 }, cardFields: ['credit', 'debit'], // Email emailMaskOptions: { maskWith: "*", unmaskedStartCharactersBeforeAt: 2, unmaskedEndCharactersAfterAt: 2, maskAtTheRate: false }, emailFields: ['primaryEmail', 'secondaryEmail'], // Password passwordMaskOptions: { maskWith: "*", maxMaskedCharacters: 10, unmaskedStartCharacters: 0, unmaskedEndCharacters: 0 }, passwordFields: ['password'], // Phone phoneMaskOptions: { maskWith: "*", unmaskedStartDigits: 2, unmaskedEndDigits: 1 }, phoneFields: ['homePhone', 'workPhone'], // String stringMaskOptions: { maskWith: "*", maskOnlyFirstOccurance: false, values: [], maskAll: true, maskSpace: false }, stringFields: ['addressLine1', 'addressLine2'], // UUID uuidMaskOptions: { maskWith: "*", unmaskedStartCharacters: 4, unmaskedEndCharacters: 2 }, uuidFields: ['uuid1'] }; const maskedJsonOutput2 = maskData.maskJSON2(jsonInput2, jsonMaskConfig2); ``` -------------------------------- ### Mask Phone Number with Custom Options Source: https://github.com/sumukha1496/maskdata/blob/master/documentation/mask_phone_number.md Use MaskData.maskPhone to mask phone numbers. Customize the masking character and the number of digits to keep unmasked from the start and end. ```javascript const MaskData = require('./maskdata'); const maskPhoneOptions = { // Character to mask the data // default value is '*' maskWith: "*", //Should be positive Integer // If the starting 'n' digits need to be unmasked // Default value is 4 unmaskedStartDigits: 5, // Should be positive Integer //If the ending 'n' digits need to be unmasked // Default value is 1 unmaskedEndDigits: 1 }; const phoneNumber = "+911234567890"; const maskedPhoneNumber = MaskData.maskPhone(phoneNumber, maskPhoneOptions); //Output: +9112*******0 ``` -------------------------------- ### Configure Masking for Multiple Data Types Source: https://github.com/sumukha1496/maskdata/blob/master/README.md Use this configuration to mask card numbers, emails, passwords, phone numbers, strings, and UUIDs. Specify options for each data type and the fields to apply them to. ```javascript const jsonInput2 = { cards: { creditCards: ['1234-5678-8765-1234', '1111-2222-1111-2222'], debitCards: ['0000-1111-2222-3333', '2222-3333-4444-4444'] }, emails: { primaryEmail: 'primary@Email.com', secondaryEmail: 'secondary@Email.com' }, passwords: [['password123', 'password456']], phones: { homePhone: '+1234567890', workPhone: '+1987654321' }, address: { addressLine1: '123 Main Street, Anytown, USA', addressLine2: 'Apt 4B' }, uuids: { uuid1: '123e4567-e89b-12d3-a456-426614174000' }, jwt: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1MTYyMzkwMjJ9.tbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQ' }; const jsonMaskConfig2 = { // Card cardMaskOptions: { maskWith: "X", unmaskedStartDigits: 2,unmaskedEndDigits: 4 }, cardFields: ['cards.creditCards[0]', 'cards.creditCards[1]', 'cards.debitCards[0]', 'cards.debitCards[1]'], // Email emailMaskOptions: { maskWith: "*", unmaskedStartCharactersBeforeAt: 2, unmaskedEndCharactersAfterAt: 2, maskAtTheRate: false }, emailFields: ['emails.primaryEmail', 'emails.secondaryEmail'], // Password passwordMaskOptions: { maskWith: "*", maxMaskedCharacters: 10, unmaskedStartCharacters: 0, unmaskedEndCharacters: 0 }, passwordFields: ['passwords[0][0]]', 'passwords[0][1]'], // Phone phoneMaskOptions: { maskWith: "*", unmaskedStartDigits: 2, unmaskedEndDigits: 1 }, phoneFields: ['phones.homePhone', 'phones.workPhone'], // String stringMaskOptions: { maskWith: "*", maskOnlyFirstOccurance: false, values: [], maskAll: true, maskSpace: false }, stringFields: ['address.addressLine1', 'address.addressLine2'], // UUID uuidMaskOptions: { maskWith: "*", unmaskedStartCharacters: 4, unmaskedEndCharacters: 2 }, uuidFields: ['uuids.uuid1'] // JWT jwtMaskOptions: { maskWith: '*', maxMaskedCharacters: 512, maskDot: true, maskHeader: true, maskPayload: true, maskSignature: true}, jwtFields: ['jwt'] }; const maskedJsonOutput2 = MaskData.maskJSON2(jsonInput2, jsonMaskConfig2); ``` -------------------------------- ### Mask JSON with Generic and Specific Field Configurations Source: https://github.com/sumukha1496/maskdata/blob/master/README.md Demonstrates masking various data types including nested objects and arrays using specific field configurations. ```javascript const jsonInput = { 'credit': '1234-5678-8765-1234', 'debit': '0000-1111-2222-3333', 'primaryEmail': 'primary@Email.com', 'secondaryEmail': 'secondary@Email.com', 'password': 'dummyPassword', 'homePhone': "+1 1234567890", 'workPhone': "+1 9876543210", 'addressLine1': "This is my addressline 1. This is my home", 'addressLine2': "AddressLine 2", 'uuid1': '123e4567-e89b-12d3-a456-426614174000', 'randomStrings': { 'row1': 'This is row 1 random string', 'row2': ['Entry1', 'Entry2', 'Entry3'], 'row3': { 'key1': 'Row3 Object 1', 'key2': 'Row3 Object 2', 'key3': ['Entry1', 'Entry2', 'Entry3'] } } }; const jsonMaskConfig = { cardFields: ['credit', 'debit'], emailFields: ['primaryEmail', 'secondaryEmail'], passwordFields: ['password'], phoneFields: ['homePhone', 'workPhone'], stringMaskOptions: { maskWith: "*", maskOnlyFirstOccurance: false, values: ["This"] }, stringFields: ['addressLine1', 'addressLine2'], uuidFields: ['uuid1'], genericStrings: [ { fields: ['randomStrings.row1'], config: { maskWith: '*', unmaskedStartCharacters: 2, unmaskedEndCharacters: 3, maxMaskedCharacters: 8 } }, { fields: ['randomStrings.row2.*'], config: { maskWith: 'X', unmaskedEndCharacters: 1 } }, { fields: ['randomStrings.row3.key1'] }, { fields: ['randomStrings.row3.key3.*'], config: { maskWith: '@', unmaskedEndCharacters: 1 } } ] }; const maskedJsonOutput = maskData.maskJSON2(jsonInput, jsonMaskConfig); ``` -------------------------------- ### Mask Email with Default Configuration Source: https://github.com/sumukha1496/maskdata/blob/master/documentation/mask_email_id_with_the_default_configuration.md Use this function to mask email addresses with default settings. No configuration is needed for basic email masking. ```javascript const MaskData = require('./maskdata'); /** Default Options maskWith: "*", unmaskedStartCharactersBeforeAt: 3, unmaskedEndCharactersAfterAt: 2, maskAtTheRate: false **/ const email = "my.test.email@testEmail.com"; const maskedEmail = MaskData.maskEmail2(email); //Output: my.********@**********om ``` -------------------------------- ### Mask Phone Number with Custom Options Source: https://github.com/sumukha1496/maskdata/blob/master/README.md Masks a phone number using custom options for unmasking the start and end digits. `unmaskedStartDigits` controls how many digits from the beginning are shown, and `unmaskedEndDigits` controls how many from the end are shown. ```javascript const MaskData = require('./maskdata'); const maskPhoneOptions = { // Character to mask the data // default value is '*' maskWith: "*", //Should be positive Integer // If the starting 'n' digits need to be unmasked // Default value is 4 unmaskedStartDigits: 5, // Should be positive Integer //If the ending 'n' digits need to be unmasked // Default value is 1 unmaskedEndDigits: 1 }; const phoneNumber = "+911234567890"; const maskedPhoneNumber = MaskData.maskPhone(phoneNumber, maskPhoneOptions); //Output: +9112*******0 ``` -------------------------------- ### Custom Masking Configurations for Field Types Source: https://github.com/sumukha1496/maskdata/blob/master/documentation/mask_email_id_with_the_default_configuration.md Applies specific masking rules for each data type (card, email, password, phone, string, UUID) by defining custom options. This allows for fine-grained control over how each type of sensitive data is masked. ```javascript const jsonInput2 = { 'credit': '1234-5678-8765-1234', 'debit': '0000-1111-2222-3333', 'primaryEmail': 'primary@Email.com', 'secondaryEmail': 'secondary@Email.com', 'password': 'dummyPasswordANDdummyPassword', 'homePhone': "+1 1234567890", 'workPhone': "+1 9876543210", 'addressLine1': "This is my addressline 1. This is my home", 'addressLine2': "AddressLine 2", 'uuid1': '123e4567-e89b-12d3-a456-426614174000' }; const jsonMaskConfig2 = { // Card cardMaskOptions: { maskWith: "X", unmaskedStartDigits: 2,unmaskedEndDigits: 4 }, cardFields: ['credit', 'debit'], // Email emailMaskOptions: { maskWith: "*", unmaskedStartCharactersBeforeAt: 2, unmaskedEndCharactersAfterAt: 2, maskAtTheRate: false }, emailFields: ['primaryEmail', 'secondaryEmail'], // Password passwordMaskOptions: { maskWith: "*", maxMaskedCharacters: 10, unmaskedStartCharacters: 0, unmaskedEndCharacters: 0 }, passwordFields: ['password'], // Phone phoneMaskOptions: { maskWith: "*", unmaskedStartDigits: 2, unmaskedEndDigits: 1 }, phoneFields: ['homePhone', 'workPhone'], // String stringMaskOptions: { maskWith: "*", maskOnlyFirstOccurance: false, values: [], maskAll: true, maskSpace: false }, stringFields: ['addressLine1', 'addressLine2'], // UUID uuidMaskOptions: { maskWith: "*", unmaskedStartCharacters: 4, unmaskedEndCharacters: 2 }, uuidFields: ['uuid1'] }; const maskedJsonOutput2 = maskData.maskJSON2(jsonInput2, jsonMaskConfig2); ``` -------------------------------- ### Mask Credit/Debit Card Numbers Source: https://context7.com/sumukha1496/maskdata/llms.txt Masks digits in a credit/debit card number while preserving non-numeric delimiters. Customizable options include the masking character, number of starting digits to keep visible, and number of ending digits to keep visible. ```javascript const MaskData = require('maskdata'); const maskCardOptions = { maskWith: "*", // Character to mask with (default: '*') unmaskedStartDigits: 4, // Number of starting digits to keep visible (default: 4) unmaskedEndDigits: 1 // Number of ending digits to keep visible (default: 1) }; const cardNumber = "1234-5678-8765-1234"; const maskedCard = MaskData.maskCard(cardNumber, maskCardOptions); // Output: 1234-****-****-***4 // With default options (no config passed) const maskedDefault = MaskData.maskCard("1234-5678-8765-1234"); // Output: 1234-****-****-***4 ``` -------------------------------- ### PasswordMaskOptions Interface Source: https://github.com/sumukha1496/maskdata/blob/master/MASKDATA_FOR_TYPESCRIPT.md Defines the configuration options for masking passwords. Customize masking character, length, and unmasked portions. ```typescript { maskWith?: string; maxMaskedCharacters?: number; fixedOutputLength?: undefined | number; unmaskedStartCharacters?: number; unmaskedEndCharacters?: number; } ``` -------------------------------- ### Mask Password with Custom Options Source: https://github.com/sumukha1496/maskdata/blob/master/documentation/mask_password.md Use this snippet to mask a password with custom options such as mask character, maximum masked characters, fixed output length, and unmasked start/end characters. Ensure the MaskData library is imported. ```javascript const MaskData = require('./maskdata'); const maskPasswordOptions = { // Character to mask the data // default value is '*' maskWith: "*", // To limit the *s in the response when the password length is more // Default value is 16 maxMaskedCharacters: 16, // To fix the length of output irrespective of the length of the input. This comes in handy when the input length < maxMaskedCharacters but we want a fixed output length. // Default value is undefined. If this value is set, then maxMaskedCharacters will not be considered and the output length will always be equal to fixedOutputLength characters. fixedOutputLength: undefined, // To show(not mask) first 'n' characters in the password/secret key. // Default value is 0. unmaskedStartCharacters: 0, // To show(not mask) last 'n' characters in the password/secret key. // Default value is 0. unmaskedEndCharacters: 0 }; const password = "Password1$"; const maskedPassword = MaskData.maskPassword(password, maskPasswordOptions); //Output: ********** ``` -------------------------------- ### Detailed JSON Masking Configurations Source: https://github.com/sumukha1496/maskdata/blob/master/documentation/mask_email_id_with_the_default_configuration.md Provides detailed configuration options for masking various data types within a JSON object, including specific settings for card numbers, emails, passwords, phone numbers, strings, UUIDs, and JWT tokens. ```javascript const defaultjsonMask2Configs = { cardMaskOptions: { maskWith: "*", unmaskedStartDigits: 4, unmaskedEndDigits: 1 }, cardFields: [], emailMaskOptions: { maskWith: "*", unmaskedStartCharactersBeforeAt: 3, unmaskedEndCharactersAfterAt: 2, maskAtTheRate: false }, emailFields: [], passwordMaskOptions: { maskWith: "*", maxMaskedCharacters: 16, unmaskedStartCharacters: 0, unmaskedEndCharacters: 0 }, passwordFields: [], phoneMaskOptions: { maskWith: "*", unmaskedStartDigits: 4, unmaskedEndDigits: 1 }, phoneFields: [], stringMaskOptions: { maskWith: "*", maskOnlyFirstOccurance: false, values: [], maskAll: false, maskSpace: true }, stringFields: [], uuidMaskOptions: { maskWith: "*", unmaskedStartCharacters: 0, unmaskedEndCharacters: 0 }, uuidFields: [], jwtMaskOptions: { maskWith: '*', maxMaskedCharacters: 512, maskDot: true, maskHeader: true, maskPayload: true, maskSignature: true }, jwtFields: [], // To extend the mask function to other types of data. genericStrings: [ { config: { maskWith: "*", maxMaskedCharacters: 256, unmaskedStartDigits: 0, unmaskedEndDigits: 0 }, fields: [] } ] }; ``` -------------------------------- ### Mask Phone Number with Default Configuration Source: https://github.com/sumukha1496/maskdata/blob/master/README.md Masks a phone number using the default configuration of the `maskPhone` function. No options object needs to be passed. ```javascript const MaskData = require('./maskdata'); /** Default Options maskWith: "*" unmaskedStartDigits: 4 unmaskedEndDigits: 1 **/ const phoneNumber = "+111234567890"; const maskedPhoneNumber = MaskData.maskPhone(phoneNumber); ``` -------------------------------- ### Configure and Apply JSON Masking Source: https://github.com/sumukha1496/maskdata/blob/master/documentation/mask_email_id_with_the_default_configuration.md Defines masking options for multiple data fields and applies them to a JSON object using MaskData.maskJSON2. ```javascript const jsonMaskConfig2 = { // Card cardMaskOptions: { maskWith: "X", unmaskedStartDigits: 2,unmaskedEndDigits: 4 }, cardFields: ['cards.creditCards[0]', 'cards.creditCards[1]', 'cards.debitCards[0]', 'cards.debitCards[1]'], // Email emailMaskOptions: { maskWith: "*", unmaskedStartCharactersBeforeAt: 2, unmaskedEndCharactersAfterAt: 2, maskAtTheRate: false }, emailFields: ['emails.primaryEmail', 'emails.secondaryEmail'], // Password passwordMaskOptions: { maskWith: "*", maxMaskedCharacters: 10, unmaskedStartCharacters: 0, unmaskedEndCharacters: 0 }, passwordFields: ['passwords[0][0]]', 'passwords[0][1]'], // Phone phoneMaskOptions: { maskWith: "*", unmaskedStartDigits: 2, unmaskedEndDigits: 1 }, phoneFields: ['phones.homePhone', 'phones.workPhone'], // String stringMaskOptions: { maskWith: "*", maskOnlyFirstOccurance: false, values: [], maskAll: true, maskSpace: false }, stringFields: ['address.addressLine1', 'address.addressLine2'], // UUID uuidMaskOptions: { maskWith: "*", unmaskedStartCharacters: 4, unmaskedEndCharacters: 2 }, uuidFields: ['uuids.uuid1'] // JWT jwtMaskOptions: { maskWith: '*', maxMaskedCharacters: 512, maskDot: true, maskHeader: true, maskPayload: true, maskSignature: true}, jwtFields: ['jwt'] }; const maskedJsonOutput2 = MaskData.maskJSON2(jsonInput2, jsonMaskConfig2); ``` -------------------------------- ### Mask Phone Number with Default Configuration Source: https://github.com/sumukha1496/maskdata/blob/master/documentation/mask_phone_number_with_the_default_configuration.md Masks a phone number using the default configuration. The default options are `maskWith: "*"`, `unmaskedStartDigits: 4`, and `unmaskedEndDigits: 1`. ```javascript const MaskData = require('./maskdata'); /** Default Options maskWith: "*" unmaskedStartDigits: 4 unmaskedEndDigits: 1 **/ const phoneNumber = "+111234567890"; const maskedPhoneNumber = MaskData.maskPhone(phoneNumber); //Output: +911********0 ``` -------------------------------- ### Mask Header and Signature Parts Source: https://github.com/sumukha1496/maskdata/blob/master/documentation/mask_jwt_token.md Configures the mask options to mask both the header and signature while keeping the payload and dots visible. ```javascript const MaskData = require('./maskdata'); const jwtMaskOptions = { maskWith: '*', maxMaskedCharacters: 512, maskDot: false, maskHeader: true, maskPayload: false, maskSignature: true }; const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1MTYyMzkwMjJ9.tbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQ'; /** In this example, * Header = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 * Payload = eyJpYXQiOjE1MTYyMzkwMjJ9 * Signature = tbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQ */ const maskedJwt = MaskData.maskJwt(jwt, jwtMaskOptions); // Output: ************************************.eyJpYXQiOjE1MTYyMzkwMjJ9.******************************************* ``` -------------------------------- ### Default JSON Masking Configurations Source: https://github.com/sumukha1496/maskdata/blob/master/documentation/mask_email_id_with_the_default_configuration.md Defines the default configuration object for masking various data types within a JSON object. Specify fields and options for each type to be masked. ```javascript const MaskData = require('./maskdata'); // Default configs are as below. If specific masking changes are needed, use the corresponding configs for each type of field. const defaultjsonMask2Configs = { cardMaskOptions: defaultCardMaskOptions, // Optional cardFields: [], // List of card fields to be masked emailMaskOptions: defaultEmailMask2Options, // Optional emailFields: [], // List of email fields to be masked // For passwords, tokens, etc... passwordMaskOptions: defaultPasswordMaskOptions, // Optional passwordFields: [], // List of password fields to be masked phoneMaskOptions: defaultPhoneMaskOptions, // Optional phoneFields: [], // List of phone fields to be masked stringMaskOptions: defaultStringMaskOptions, // Mandatory if stringFields are given. Otherwise, stringFields won't be masked stringFields: [], // List of String fields to be masked uuidMaskOptions: defaultUuidMaskOptions, // Optional uuidFields: [], // List of UUID fields to be masked jwtMaskOptions: defaultJwtMaskOptions, // Optional jwtFields: [], // List of JWT fields to be masked genericStrings: [ { config: defaultStringMaskV2Options, fields: [] } ] }; ``` -------------------------------- ### Generic String Masking with Custom Options Source: https://github.com/sumukha1496/maskdata/blob/master/README.md Masks a generic string using `maskStringV2` with customizable options. Options include `maskWith`, `maxMaskedCharacters`, `fixedOutputLength`, `unmaskedStartCharacters`, and `unmaskedEndCharacters`. `fixedOutputLength` takes precedence over `maxMaskedCharacters`. ```javascript const MaskData = require('./maskdata'); const defaultStringMaskV2Options = { // Character to mask the data // default value is '*' maskWith: "*", // This is to limit the maximun characters in the output. // Default value is 256 maxMaskedCharacters: 256, // To fix the length of output irrespective of the length of the input. This comes in handy when the input length < maxMaskedCharacters but we want a fixed output length. // Default value is undefined. If this value is set, then maxMaskedCharacters will not be considered and the output length will always be equal to fixedOutputLength characters. fixedOutputLength: undefined, // To show(not mask) first 'n' characters of the string. // Default value is 0. unmaskedStartCharacters: 0, // To show(not mask) last 'n' characters of the string. // Default value is 0. unmaskedEndCharacters: 0 }; const string1 = "Password1$"; const maskedString = MaskData.maskStringV2(string1, defaultStringMaskV2Options); //Output: ********** ```