Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

data-mask

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

data-mask

A small string masking library in javascript.

  • 0.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.9K
increased by2.22%
Maintainers
1
Weekly downloads
 
Created
Source

data-mask

A small string masking library in javascript.

npm version Bower version Build Status

INSTALLATION

With bower:

bower install --save data-mask

With npm:

npm install --save data-mask

USAGE

Use it by using DataMasker instance with plain text:

/**
 * options parameter is optional in the constructor.
 */
var dataMasker = new DataMasker('lorem ipsum', options); //options is optional
var output = '';

output = dataMasker.maskLeft(2);   //"**rem **sum"
output = dataMasker.maskRight(2);  //"lor** ips**"
output = dataMasker.maskRandom(2); //"lo*e* ip**m" etc (random chars)

//options can be override on function call
output = dataMasker.maskLeft(2, ' ', '#');   //"##rem ##sum"
output = dataMasker.maskRight(2, ' ', '@');  //"lor@@ ips@@"
output = dataMasker.maskRandom(2, ' ', '-'); //"lo-e- ip--m" etc (random chars)
output = dataMasker.maskLeft(2, 4, '?');     //"??re??ip??m"" (fixed chuks)

//before & after mask functions.
output = dataMasker.maskLeft(2, ' ', '?', beforeMaskFn, afterMaskFn);

//or just call mask function
output = dataMasker.mask(2, ' ', '#', 1);   //"##rem ##sum"

//also static calls available.
output = DataMasker.maskLeft('lorem ipsum', 2, ' ', '#');   //"##rem ##sum"
output = DataMasker.maskRight('lorem ipsum', 2, ' ', '@');  //"lor@@ ips@@"
output = DataMasker.maskRandom('lorem ipsum', 2, ' ', '-'); //"lo-e- ip--m" etc (random chars)
output = DataMasker.maskLeft('lorem ipsum', 2, 4, '?');     //"??re??ip??m"" (fixed chuks)

OPTIONS

Options for constructor or method params:

OptionDescription
maskCharAn one-length string used for mask (Default *)
deliminatorA deliminator string or integer for fixed chunks (Default ' ' or min 1)
direction Mask positions. Left, right or random chars "1, -1, 0" (Default 1)
rangeMask character count or percentage for token (0 < range < 1), range=0 is random character count.
beforeMaskCallback function on before mask for each token. fn(token, range, maskChar, deliminator), a string token expected. Return false for prevent masking.
aftermaskCallback function on after mask for each token. fn(token, range, maskChar, deliminator), a string token expected. Return false for exclude token.

beforeMask and afterMask examples:

function beforeMask(token, range, maskChar, deliminator) {
    if(token=='lorem'){
        return 'LOREM'; //Uppercase 'lorem'
    }
    else if(token == 'ipsum'){
        return false; //Not mask 'ipsum'
    }
    else{
        return token;
    }
}

function afterMask(token, range, maskChar, deliminator) {
    if(token === maskChar){
        return false; //Ignore one-length masked tokens like '*', '#' etc.
    }
    else{
        return token;
    }
}

LICENSE

Copyright (c) 2016 Soner Çökmen

Licensed under the MIT license.

Keywords

FAQs

Package last updated on 19 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc