magic-string is a low-level JavaScript library designed for compilers and bundlers to perform source code transformations. It serves as a string transformation utility and source map manipulation library that allows for modifying text while automatically tracking character offsets.
The library enables the modification of source code strings through insertions, replacements, and removals without losing the relationship to original source positions. It specifically provides mechanisms to generate mapping files that link transformed output text back to original source file coordinates.
Capabilities include adjusting text indentation while excluding specific character ranges and concatenating multiple modified strings into a single bundle with a shared mapping file. The tool also supports replacing text patterns and analyzing string state.