# Rich-Harris/magic-string

Manipulate strings like a wizard

Repository: https://github.com/Rich-Harris/magic-string
Canonical: https://ross.abutalabs.com/products/magic-string
Language: TypeScript
License: MIT
License Family: permissive
Last push: 2026-08-26T10:38:24+00:00

## Health v2 (maintenance only)
Score: 99/100 (v2, computed 2026-09-03T02:20:16.233290+00:00)
- activity 99, release rhythm 99, longevity 100
- inputs: {"age_days": 4321, "days_push": 7, "days_rel": 7, "gap_med": 6.0, "n_releases_24m": 9}
- flags: none
- formula: round(0.45*activity + 0.35*rhythm + 0.20*longevity); archived -> min(score, 10)

## Adoption (not part of the score)
Stars 2770, forks 125 (observed 2026-08-28T04:07:18.872904+00:00)

## What it is
A small, fast TypeScript library for editing strings in place (update, prepend, append, move, overwrite) while generating accurate v3 source maps. It is widely used by bundlers and transpilers for lightweight source-code transformations without a full AST.

## Use cases
- generate source maps while patching source code strings
- make small edits to code without a full AST parser
- wrap code with a header and footer preserving sourcemap accuracy
- build a custom bundler or transpiler step
- transform non-JavaScript text files with sourcemap support
- indent or move code sections while keeping mappings valid

## When to choose
- you need string-level code edits with sourcemap generation
- recast or a full AST toolchain is overkill for your transformation
- your source language is not JavaScript but you still need sourcemaps
- you are writing a bundler, plugin, or code-mod that patches files lightly

## When to avoid
- you need structural AST-based refactoring with formatting preservation
- you only need plain string manipulation with no sourcemaps
- your project requires CommonJS require() since it is ESM-only

## Facets
- artifact type: library
- maturity: stable
- function: parser, serialization, developer-tools
- domain: developer-tools, web-development, parsers
- platform: browser
- tags: sourcemap-generation, string-manipulation, code-transformation, esm-only, build-tools-utility, nodejs, javascript

## Member repositories
- Rich-Harris/magic-string (main) score 99

## Provenance
- Observed fields: from GitHub, fetched 2026-08-28T04:07:18.872904+00:00.
- Health v2: computed from the inputs above; adoption is never an input.
- Inferred fields (summary, facets, guidance): AI-extracted, prompt v1, taxonomy v1, on 2026-08-30T08:16:40.271656+00:00, confidence not recorded.
  - readme: https://github.com/Rich-Harris/magic-string (fetched 2026-08-28T04:07:18.872904+00:00, sha 8e8a70eeeac9)
  - registry_npm: https://registry.npmjs.org/magic-string (fetched 2026-08-29T09:56:17.161026+00:00, sha 87d0207f5625)
- Data as of 2026-08-30T08:39:29.467469+00:00.
