zero-width-lib
What's zero-width-lib
Zero-width-lib is a library for manipulating zero width characters (ZWC), which are non-printing and invisible chars.
The common usage of ZWC includes fingerprinting confidential text, embedding hidden text and escaping from string matching (i.e. regex)...
The lib is inspired by this great medium article and got the following features:
- 💯stable & cover full test cases
- 😆support full width Unicode chars
- ⚡️dependencies & performance considered
- 📦support CJS, ESM and UMD
Install
npm install zero-width-lib
Usage
Besides ESM, CJS and UMD ways of importing are also supported
// import one method at a time;
// or import all methods from lib;
// note * represents the invisible ZWC// U+ represents the Unicode for the character // 0. six different zwcconst dict = zzeroWidthDict;console; // '*' U+200Bconsole; // '*' U+200Cconsole; // '*' U+200Dconsole; // '*' U+200Econsole; // '*' U+200Fconsole; // '*' U+FEFF // 1. convert textconst text = 'text';const zwc = z; // '********'const back = z; // 'text' // 2. embed hidden textconst visble = 'hello world';const hidden = 'inspired by @umpox';const encoded = z; // 'h*********ello world'const decoded = z; // 'inpired by @umpox' // 3. extract ZWC from textconst extracted = z;const vis = extractedvis; // 'hello world'const hid = extractedhid; // '*********' // 4. escape from string matchingconst forbidden = 'forbidden';const escaped = z; // 'f*o*r*b*i*d*d*e*n*'
License
MIT