π§Ό A lightweight utility to clean up strings by removing a wide range of invisible and non-printable characters in JavaScript.
- Removes characters such as
NULL,Backspace,Line Feed,No-Break Space, and many more (ASCII 0β31,\xA0). - Helps clean up corrupted input, malformed text from external sources, or unintentional invisible characters.
- Pure function β no dependencies, easy to test and integrate.
You can use this utility in two ways:
Download removeInvisibleCharacters.js and import it into your project.
npm install remove-invisible-charactersconst { removeInvisibleCharacters } = require('remove-invisible-characters');
const original = "Hello\x00World\xA0!";
const cleaned = removeInvisibleCharacters(original);
console.log(cleaned); // "Hello World !"It targets and replaces the following ASCII characters with a single space:
- Control characters:
\x00to\x1F - Non-breaking space:
\xA0
This ensures the resulting text is clean, visible, and safe for further processing or display.
Parameters:
textβ A string that may contain invisible characters.
Returns:
- A new string with all targeted invisible characters replaced with spaces.
MIT β Free to use, modify, and distribute.