0.0.1 • Published 7 years ago

cleanstr v0.0.1

Weekly downloads
5
License
MIT
Repository
github
Last release
7 years ago

cleanstr

NPM version Build status Test coverage Downloads

Some characters we can't see them on the text editor, but they really exist. They may be indifferent for your programs, but sometimes not. For example, you try to set default values for the talbe fields on database, but the default values are read from some files that may contain special chracters or zero-width chracters. And then you may get the error: invalid character for default value!. So let's remove these unwanted charaters.

Special characters

Unicode character valueEscape sequenceMeaningCategory
\u0008\bBackspace
\u0009\tTabWhite space
\u000A\nLine feed (new line)Line terminator
\u000B\vVertical tabWhite space
\u000C\fForm feedWhite space
\u000D\rCarriage returnLine terminator
\u0020SpaceWhite space
\u0022\"Double quotation mark (")
\u0027\'Single quotation mark (')
\u005C|Backslash ()
\u00A0Nonbreaking spaceWhite space
\u2028Line separatorLine terminator
\u2029Paragraph separatorLine terminator
\uFEFFByte order markWhite space

For more detail, you can check here.

Zero-width space

  • \u200B
  • \u200C
  • \u200D
  • \uFEFF

You can find the introduction here.

Installation

npm install cleanstr --save

Examples

const cleaner = require('cleanstr');

const sampleStr = '\u0008123\u200B';
const str1 = cleaner.clean(sampleStr);  // remove special characters
const str2 = cleaner.cleanZero(sampleStr);  // remove zero-with characters
const str3 = cleaner.cleanAll(sampleStr); // remove both
const str4 = cleaner.cleanCustom(sampleStr, '\u0008\u200B');  // remove custom characters

LICENSE

MIT