Skip to content

Instantly share code, notes, and snippets.

@johnmurch
Created March 26, 2024 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnmurch/4b9ac992e7dde41a9fe1b128b6a3df4b to your computer and use it in GitHub Desktop.
Save johnmurch/4b9ac992e7dde41a9fe1b128b6a3df4b to your computer and use it in GitHub Desktop.
Make It Blank
function convertStringToSpaces(inputString) {
// List of space-like Unicode characters, excluding zero-width spaces for visual effect
const unicodeSpaces = [
'\u0020', // Space
'\u00A0', // No-Break Space
'\u2002', // En Space
'\u2003', // Em Space
'\u2009', // Thin Space
'\u202F', // Narrow No-Break Space
'\u205F', // Medium Mathematical Space
'\u3000', // Ideographic Space
];
// Function to convert a single character to a Unicode space
const convertCharToSpace = () => {
// Select a random Unicode space character
const randomSpace = unicodeSpaces[Math.floor(Math.random() * unicodeSpaces.length)];
return randomSpace;
};
let result = '';
for (let i = 0; i < inputString.length; i++) {
// Replace each character in the input string with a random Unicode space
result += convertCharToSpace();
}
return result;
}
// Example usage
const input = 'when you want to replace a string with just look like empty spaces, but is not';
const output = convertStringToSpaces(input);
console.log('"' + output + '"');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment