Package Exports
- maskdata
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (maskdata) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
maskdata is a Node.js module to mask various kinds of data.
Table of Contents
Features
- Mask password data with the desired configuration
- Simple password mask(Mask using default configurations)
- Mask password data with the desired configuration
- Mask Phone numbers
- Simple phone number mask(Mask using default configurations)
- Mask phone number data with the desired configuration
- Mask Email
- Simple Email mask(Mask using default configurations)
- Mask Email data with the desired configuration
- Mask desired fields in a JSON
- Mask nested onject fields
- Mask the given substring from throughout a String
- Mask the card number
Install maskdata
npm i maskdata
How to Use
const MaskData = require('./maskdata');Mask Phone Number
const MaskData = require('./maskdata');
const maskPhoneOptions = {
// Character to mask the data
// default value is '*'
maskWith: "*",
//Should be positive Integer
// If the starting 'n' digits needs to be unmasked
// Default value is 4
unmaskedStartDigits: 5,
// Should be positive Integer
//If the ending 'n' digits needs to be unmasked
// Default value is 1
unmaskedEndDigits: 1
};
const phoneNumber = "+911234567890";
const maskedPhoneNumber = MaskData.maskPhone(phoneNumber, maskPhoneOptions);
//Output: +9112*******0
Mask Phone Number with the default configuration
const MaskData = require('./maskdata');
/** Default Options
maskWith: "*"
unmaskedStartDigits: 4
unmaskedEndDigits: 1
**/
const phoneNumber = "+111234567890";
const maskedPhoneNumber = MaskData.simplePhoneMask(phoneNumber);
//Output: +911********0
Mask Password
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
};
const password = "Password1$";
const maskedPassword = MaskData.maskPassword(password, maskPasswordOptions);
//Output: **********
Mask Password with the default configuration
const MaskData = require('./maskdata');
/** Default Options
maskWith: "*"
maxMaskedCharacters: 16
**/
const password = "Password1$";
const maskedPassword = MaskData.simplePasswordMask(password);
Mask Email Id
Mask the email id along with the required configurations
const MaskData = require('./maskdata');
const maskEmailOptions = {
// Character to mask the data. Default value is '*'
maskWith: "*",
//Should be positive Integer
// If the starting 'n' characters needs to be unmasked. Default value is 3
unmaskedStartCharacters: 1,
//Should be positive Integer
// If the ending 'n' characters needs to be unmasked. Default value is 2
unmaskedEndCharacters: 2,
// Should be boolean
//If '@' needs to be masked. Default value is false(Will not mask)
maskAtTheRate: false,
//Should be positive Integer
// To limit the *s in the response(Max *s before '@'). Default value is 10
maxMaskedCharactersBeforeAtTheRate: 10,
//Should be positive Integer
// To limit the *s in the response(Max *s after '@'). Default value is 10
maxMaskedCharactersAfterAtTheRate: 10
};
const email = "my.test.email@testEmail.com";
const maskedEmail = MaskData.maskEmail(email, maskEmailOptions);
//Output: m**********@**********om
Mask Email id with the default configuration
const MaskData = require('./maskdata');
/** Default Options
maskWith: "*"
unmaskedStartCharacters: 3
unmaskedEndCharacters: 2
maskAtTheRate: false
maxMaskedCharactersBeforeAtTheRate: 10
maxMaskedCharactersAfterAtTheRate: 10
**/
const email = "my.test.email@testEmail.com";
const maskedEmail = MaskData.simpleEmailMask(email);
//Output: my.********@**********om
Mask fields in a JSON
This will mask the field value if present in the given object
const MaskData = require('./maskdata');
const maskJSONOptions = {
// Character to mask the data. Default value is '*'
maskWith: "*",
// It should be an array
// Field names to mask. Can give multiple fields.
fields: ['password', 'firstName']
};
const obj = {
password: "IKnowNothing",
firstName: "Jon",
lastName: "Snoww"
};
const maskedObj = MaskData.maskJSONFields(obj, maskJSONOptions);
//Output: { password: '************', firstName: '***', lastName: 'Snoww' }
Mask fields of a nested Object
This will mask the field values if present in the given object.
The masked value type will always be string. Won't mask if the value is null
If the field doesn't exist or if there is any syntax error, then it will ignore without throwing any error.
const MaskData = require('./maskdata');
const maskJSONOptions = {
// Character to mask the data. Default value is '*'
maskWith: "*",
// It should be an array
// Field names to mask. Can give multiple fields.
fields : [ 'level1.level2.level3.field3',
'level1.level2.field2',
'level1.field1',
'value1',
'level1.level2.level3.field4[0].Hello',
'level1.level2.level3.field4[2]']
};
const nestedObject = {
level1: {
field1: "field1",
level2: {
field2: "field2",
level3: {
field3: "field3",
field4: [{ Hello: "world" }, { Hello: "Newworld" }, "Just a String"]
}
}
},
value1: "value"
};
const maskedObj = MaskData.maskJSONFields(nestedObject, defaultJSONMaskOptions2);
//Output: {"level1":{"field1":"******","level2":{"field2":"******","level3":{"field3":"******","field4":[{"Hello":"world"},{"Hello":"Newworld"},"Just a String"]}}},"value1":"*****"}
Mask the exact substring from throughout the string
This will mask the field value if present in the given object
const MaskData = require('./maskdata');
const maskStringOptions = {
// Character to mask the data. Default value is '*'
maskWith: "*",
// It should be an array of strings
// Field names to mask. Can give multiple fields.
values: ['is', 'test'],
// Should be boolean
// If to mask only the first occurance of each value in the given string
maskOnlyFirstOccurance: false
};
const str = "This is a test String";
const strAfterMasking = MaskData.maskString(str, maskStringOptions);
//Output: Th** ** a **** String
Mask card number
This will mask the card numbers
const MaskData = require('./maskdata');
const maskCardOptions = {
// Character to mask the data. Default value is 'X'
maskWith: "X",
// Should be positive Integer
// If the starting 'n' numbers needs to be unmasked
// Default value is 4
unmaskedStartDigits: 4,
//Should be positive Integer
//If the ending 'n' numbers needs to be unmasked
// Default value is 1.
// Max possible value is 4
unmaskedEndDigits: 1
};
const cardNumber = "1234-5678-1234-5678";
const cardAfterMasking = MaskData.maskCard(cardNumber, maskCardOptions);
//Output: 1234-XXXX-XXXX-XXX8
Report Bugs
Please raise an issue in github: https://github.com/Sumukha1496/maskdata/issues
Give a Star:
You can give a start at: https://github.com/Sumukha1496/maskdata/stargazers
LICENSE - "MIT"
Licenced 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 NONINFRINGEMENT. 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.