Emoji removal and text sanitization for AI output, user content, and your repository.
demojify-sanitize is a dependency-free Go library and CLI that detects emoji, removes them or swaps them
for readable text such as [PASS], and tidies the whitespace they leave behind. Use it to
clean up AI agent and LLM responses, sanitize submitted text, or fail a CI build when emoji creep into source and docs.
✅ tests passed, ❌ build failed 🚀🚀[PASS] tests passed, [FAIL] build failed [DEPLOY]Small, predictable, and safe to run on anything
Pure standard library, no go.sum, and defaults that never silently do nothing.
Detect, remove, or substitute
ContainsEmojiWith detects emoji, Sanitize strips them, and Replace maps 280 built-in emoji to text tokens and strips the rest. Custom maps are supported.
Script-aware
Keeps the Zero Width Joiner and variation selectors that shape Indic, CJK, and math text, while still removing every emoji.
Whitespace normalization
Collapses redundant spaces and blank lines while preserving indentation, gofmt alignment, and CRLF line endings.
Streams, JSON, and trees
SanitizeReader for LLM streams, SanitizeJSON for string values only, and ScanDir / FixDir for whole repositories.
Install the Go library and CLI
Add the library to a module. The v1 import path has no /v1 suffix.
go get github.com/nicholashoule/demojify-sanitize@v1.2.0
Install the CLI, or run it once without installing:
go install github.com/nicholashoule/demojify-sanitize/cmd/demojify@v1.2.0
go run github.com/nicholashoule/demojify-sanitize/cmd/demojify@v1.2.0 -root .
Zero dependencies, Go 1.24 or newer
Everything is built on the standard library, so there is nothing else to fetch or audit. CI tests Go 1.24, 1.25, and the latest release on Linux, macOS, and Windows.
Remove emoji from a string in Go
Start from the safe presets. SanitizeSafe always removes emoji, keeps script joiners, and leaves whitespace alone.
import demojify "github.com/nicholashoule/demojify-sanitize"
clean := demojify.SanitizeSafe(aiResponse)
// Also collapse redundant whitespace.
opts := demojify.SafeOptions()
opts.NormalizeWhitespace = true
clean = demojify.Sanitize(text, opts)
// Substitute instead of strip.
clean = demojify.Replace(text, demojify.DefaultReplacements())
// Gate user input.
if demojify.ContainsEmojiWith(input, demojify.SafeOptions()) {
return errEmojiNotAllowed
}
Scan and clean a whole repository
cfg := demojify.SafeScanConfig()
findings, err := demojify.ScanDir(cfg) // audit
fixed, _, err := demojify.FixDir(".", cfg) // audit and rewrite
| Function | Purpose |
|---|---|
SanitizeSafe | Recommended entry point: remove emoji, keep script joiners. |
Sanitize | Configurable pipeline: removal, then whitespace normalization. |
Replace | Map emoji to text tokens; strip anything unmapped. |
SanitizeReport | Cleaned text plus emoji removed and bytes saved. |
SanitizeReader | Line-by-line streaming, lines up to 1 MiB. |
SanitizeJSON | Clean string values; keys, numbers, and precision untouched. |
ScanDir, FixDir | Walk a tree, report per-file findings, and optionally write back. |
Every function and option is documented on pkg.go.dev.
Emoji linter CLI for CI and pre-commit hooks
demojify audits a directory tree and reports every occurrence with file, line, and column. It exits 1 when it finds emoji, so it works as a CI gate or pre-commit hook.
demojify -root . # audit only; nothing changes
demojify -root . -exts .go,.md # limit to these extensions
demojify -root . -fix # strip emoji in place
demojify -root . -sub # substitute text tokens in place
demojify -root . -sub -normalize # substitute and tidy whitespace
demojify -root . -skip dist,build -json # machine-readable findings
demojify -version
See the CLI reference for every flag and exit code, CI integration for GitHub Actions and GitLab CI, and git hooks for blocking emoji at commit time.
Safe defaults and safe file writes
A zero Options passes text through unchanged, as v1 promises, so a forgotten field can silently turn sanitizing off. SafeOptions, SanitizeSafe, and SafeScanConfig leave nothing to forget: they always remove emoji.
File writes go through a same-directory temp file and rename, preserving permissions. A file edited after it was read is left alone and reported with ErrFileChanged. Scans skip binary files and the safe preset caps file size; FixDir never writes through a path or symlink that resolves outside its root. SECURITY.md says how to report a vulnerability.
Documentation
- API reference every function, type, and option
- CLI flags, modes, exit codes, and output format
- CI integration GitHub Actions, GitLab CI, and test-based gates
- Git hooks pre-commit hooks on macOS, Linux, and Windows
- Replacements all 280 built-in emoji-to-text mappings
- Unicode coverage the ranges removed and what is intentionally kept
- Design zero dependencies, pipeline order, and write strategy
- Changelog what changed in each release