A lightweight, zero-dependency utility to clean Zalgo/glitched text from strings. Works seamlessly across React, Next.js, Vue, Angular, and Svelte.
Clean your inputs, console logs, UI, or social media posts safely and efficiently.
/**
* Universal Zalgo Text Cleaner
* @param {string} mode - 'strict' (default) removes all non-ASCII, 'light' removes only combining marks
* @returns {function} - Function that accepts input string and returns cleaned string
*/
export function createZalgoCleaner(mode = "strict") {
return function(input = "") {
if (typeof input !== "string") return "";
// Step 1: Normalize Unicode characters
let normalized = input.normalize("NFD");
// Step 2: Remove combining marks
normalized = normalized.replace(/[\u0300-\u036f]/g, "");
// Step 3: Strict mode removes remaining non-ASCII characters
if (mode === "strict") {
normalized = normalized.replace(/[^\x00-\x7F]/g, "");
}
return normalized.trim();
};
}
import { createZalgoCleaner } from './utils/zalgoCleaner';
const clean = createZalgoCleaner();
const text = "w̵̛̽́̿̎o̶̽́̿w̵";
function App() {
return (
<div>
<p>Original: {text}</p>
<p>Cleaned: {clean(text)}</p>
</div>
);
}
export default App;
<script setup>
import { createZalgoCleaner } from './utils/zalgoCleaner';
const clean = createZalgoCleaner();
const text = "w̵̛̽́̿̎o̶̽́̿w̵";
</script>
<template>
<p>Original: {{ text }}</p>
<p>Cleaned: {{ clean(text) }}</p>
</template>
// zalgo-cleaner.service.ts
import { Injectable } from '@angular/core';
@Injectable({ providedIn: 'root' })
export class ZalgoCleanerService {
private cleanFn = (input: string) => {
if (!input) return '';
let normalized = input.normalize('NFD');
normalized = normalized.replace(/[\u0300-\u036f]/g, '');
normalized = normalized.replace(/[^\x00-\x7F]/g, '');
return normalized.trim();
};
clean(input: string) {
return this.cleanFn(input);
}
}
<p>Original: {{ text }}</p>
<p>Cleaned: {{ zalgoCleaner.clean(text) }}</p>
<script>
import { createZalgoCleaner } from './utils/zalgoCleaner.js';
const clean = createZalgoCleaner();
let text = "w̵̛̽́̿̎o̶̽́̿w̵";
</script>
<p>Original: {text}</p>
<p>Cleaned: {clean(text)}</p>
| Mode | Description |
|---|---|
strict |
Remove combining marks + any remaining non-ASCII characters (default). |
light |
Remove only combining marks, keep other Unicode letters intact. |
const clean = createZalgoCleaner("strict");
console.log(clean("@Microsoft, @amzn, w̵̽́̿o̶̽́̿w̵"));
// Output: "@Microsoft, @amzn, wow"
Kiranravi – Frontend Developer & Open Source Enthusiast
Built with ❤️ by Kiranravi. Feel free to contribute, report issues, or suggest features!