data-mask
A small string masking library in javascript.
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 = 'lorem ipsum' options; //options is optionalvar output = ''; output = dataMasker; //"**rem **sum"output = dataMasker; //"lor** ips**"output = dataMasker; //"lo*e* ip**m" etc (random chars) //options can be override on function calloutput = dataMasker; //"##rem ##sum"output = dataMasker; //"lor@@ ips@@"output = dataMasker; //"lo-e- ip--m" etc (random chars)output = dataMasker; //"??re??ip??m"" (fixed chuks) //before & after mask functions.output = dataMasker; //or just call mask functionoutput = dataMasker; //"##rem ##sum" //also static calls available.output = DataMasker; //"##rem ##sum"output = DataMasker; //"lor@@ ips@@"output = DataMasker; //"lo-e- ip--m" etc (random chars)output = DataMasker; //"??re??ip??m"" (fixed chuks)
OPTIONS
Options for constructor or method params:
Option | Description |
---|---|
maskChar |
An one-length string used for mask (Default * ) |
deliminator |
A deliminator string or integer for fixed chunks (Default ' ' or min 1 ) |
direction |
Mask positions. Left, right or random chars "1, -1, 0" (Default 1 ) |
range |
Mask character count or percentage for token (0 < range < 1), range=0 is random character count. |
beforeMask |
Callback function on before mask for each token. fn(token , range , maskChar , deliminator ), a string token expected. Return false for prevent masking. |
aftermask |
Callback 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:
{ iftoken=='lorem' return 'LOREM'; //Uppercase 'lorem' else iftoken == 'ipsum' return false; //Not mask 'ipsum' else return token; } { iftoken === maskChar return false; //Ignore one-length masked tokens like '*', '#' etc. else return token; }
LICENSE
Copyright (c) 2016 Soner Çökmen
Licensed under the MIT license.