DEV Community

pulkitgovrani
pulkitgovrani Subscriber

Posted on

emojis-cleaner — A npm package to remove Emojis from Any File or Codebase (CLI + JS API)

Introducing emojis-cleaner — Remove Emojis from Any File or Codebase (CLI + JS API)

Have you ever opened a file in your codebase and found random emojis inside comments, logs, commits, or strings?

Yes, they look aesthetic… until they break your CI, minifiers, builds, or linters. 😅

I ran into this too many times and decided to fix it once and for all.

So today, I'm excited to introduce:


emojis-cleaner — a simple tool to remove all emojis from any project

NPM: https://www.npmjs.com/package/emojis-cleaner

emojis-cleaner is a tiny Node.js package + CLI tool that:

✔ Removes all emojis from any text
✔ Works on any file type (JS, TS, HTML, JSON, Markdown, etc.)
✔ Can clean entire folders recursively
✔ Automatically ignores node_modules
✔ Can also be used directly in JS code

Whether you want to sanitize logs, clean content, or enforce “no emojis in code”, this tool does the job.


Installation

Global (use as CLI)

npm install -g emojis-cleaner
Enter fullscreen mode Exit fullscreen mode

Local

npm install emojis-cleaner
Enter fullscreen mode Exit fullscreen mode

Usage (CLI)

Clean all emojis from a folder

emojis-cleaner .
Enter fullscreen mode Exit fullscreen mode

Clean emojis from a specific file

emojis-cleaner src/index.js
Enter fullscreen mode Exit fullscreen mode

Example Output

 Cleaned: src/app.js
 Cleaned: src/utils/logs.js
 Cleaned: README.md
 Emoji removal complete!
Enter fullscreen mode Exit fullscreen mode

The CLI scans everything recursively, removes emojis, and updates files in place.


🧠 Use as a Function (Node.js API)

You can also use the same logic inside your Node scripts:

const removeEmojis = require("emojis-cleaner");

console.log(removeEmojis("Hello 😄 World 🚀"));
// Output: "Hello  World "
Enter fullscreen mode Exit fullscreen mode

This uses a reliable Unicode regex to detect all emojis, including:

  • basic emojis 😄
  • flags 🏳️‍🌈
  • symbols
  • multi-emoji clusters 👨‍👩‍👧‍👦
  • skin tones 👍🏽

Why I Built This

I was working on a project where random emojis were added in:

  • Git commit messages
  • Code comments
  • Debug logs
  • JSON configuration files
  • Markdown docs

They looked harmless, but:

  • Git diffs broke
  • Some emojis caused UTF-8 build issues
  • Minifiers crashed
  • CI complained about “invalid character 0xF0”

I searched for a tool that simply scans everything and removes emojis, but couldn’t find one that:

  • worked on any file
  • didn't force me to set configs
  • didn’t require regex tweaking
  • didn’t fail on multi-emoji clusters

So… I built it 😄


🛠️ How It Works (Internally)

The CLI:

  1. Resolves the input path
  2. Recursively scans all files
  3. Skips node_modules automatically
  4. Reads each file as UTF-8
  5. Uses a Unicode property regex:
const emojiRegex = /\p{Extended_Pictographic}/gu;
Enter fullscreen mode Exit fullscreen mode
  1. Rewrites the file without emojis

The API:

function removeEmojis(str) {
  return str.replace(emojiRegex, "");
}
Enter fullscreen mode Exit fullscreen mode

Simple, predictable, effective.


Roadmap / Future Features

Planned improvements:

  • --dry-run mode
  • --stats to show how many emojis were removed
  • Backup mode (--backup)
  • Exclusion patterns (--ignore *.md)
  • VS Code extension
  • Pre-commit hook examples

If you want any specific feature, drop a comment!


Final Thoughts

emojis-cleaner is intentionally small and focused — a “just remove emojis” utility that works out of the box.

If your project needs clean logs, consistent file formats, or emoji-free CI pipelines, this tool can help keep things tidy.

Try it here: https://www.npmjs.com/package/emojis-cleaner

If you’d like to contribute, suggest new features, or request enhancements, feel free to comment or open a PR.
Thanks for reading!


Top comments (0)