magic-string is a small JavaScript utility for editing strings while preserving accurate source maps. It is designed for compilers, bundlers, preprocessors, and code transformation tools that need to rewrite source code safely. The library lets developers overwrite, append, prepend, remove, move, and slice sections of text without losing track of where transformed content came from. This makes it especially useful when generated output still needs to map back to the original source for debugging. Magic String works in both Node.js and browser environments. Its main value is making code manipulation precise, fast, and source-map-friendly for build tools and language tooling.

Features

  • String manipulation for code tools
  • Source map generation support
  • Append, prepend, overwrite, and remove operations
  • Node.js and browser compatibility
  • Useful for compilers and bundlers
  • Lightweight transformation utility

Project Samples

Project Activity

See All Activity >

Categories

Libraries

License

MIT License

Follow magic-string

magic-string Web Site

Other Useful Business Software
Your monitoring isn't a stack. It's a pile. Fix that. Icon
Your monitoring isn't a stack. It's a pile. Fix that.

Errors, performance, logs, uptime. One install, one invoice, one UI.

Replace Datadog, New Relic, and Sentry without adding three more dashboards.
Free 30 days.
Rate This Project
Login To Rate This Project

User Reviews

Be the first to post a review of magic-string!

Additional Project Details

Programming Language

JavaScript

Related Categories

JavaScript Libraries

Registered

2026-06-10