Skip to content

blackmatch/cleanstr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 value Escape sequence Meaning Category
\u0008 \b Backspace
\u0009 \t Tab White space
\u000A \n Line feed (new line) Line terminator
\u000B \v Vertical tab White space
\u000C \f Form feed White space
\u000D \r Carriage return Line terminator
\u0020 Space White space
\u0022 " Double quotation mark (")
\u0027 ' Single quotation mark (')
\u005C |Backslash ()
\u00A0 Nonbreaking space White space
\u2028 Line separator Line terminator
\u2029 Paragraph separator Line terminator
\uFEFF Byte order mark White 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

About

Remove unwanted characters from string.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published