Created
March 26, 2024 02:09
-
-
Save johnmurch/4b9ac992e7dde41a9fe1b128b6a3df4b to your computer and use it in GitHub Desktop.
Make It Blank
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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