# rolldown-string

> A compatibility layer for magic-string to work with Rolldown and other bundlers.

Latest version **0.3.1** (published 2026-07-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install rolldown-string
pnpm add rolldown-string
yarn add rolldown-string
bun add rolldown-string
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2026-07-16 |
| First published | 2025-12-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=20.19.0 |
| Dependencies | 1 |
| Unpacked size | 7.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 10 |
| Author | Kevin Deng <sxzz@sxzz.moe> |
| Maintainers | sxzz |
| Keywords | rolldown, unplugin, magic-string, rollup |

## Links

- npm: https://www.npmjs.com/package/rolldown-string
- Repository: https://github.com/sxzz/rolldown-string
- Homepage: https://github.com/sxzz/rolldown-string#readme
- Issues: https://github.com/sxzz/rolldown-string/issues
- Funding: https://github.com/sponsors/sxzz
- npm.io page: https://npm.io/package/rolldown-string

## Dependencies (1)

- [magic-string](https://npm.io/package/magic-string.md) ^1.0.0

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 0.3.1 (latest) — 2026-07-16
- 0.3.0 — 2026-03-11
- 0.2.1 — 2025-12-15
- 0.2.0 — 2025-12-15
- 0.1.0 — 2025-12-15
- 0.0.0 — 2025-12-15

## README

# rolldown-string

[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![Unit Test][unit-test-src]][unit-test-href]

A compatibility layer for [magic-string](https://github.com/Rich-Harris/magic-string) to work with Rolldown and other bundlers.

- In Rolldown, [native `magic-string`](https://rolldown.rs/in-depth/native-magic-string) is used to optimize performance.
- If native support is unavailable, it gracefully falls back to the JavaScript implementation of `magic-string`.

Recommended for use with [unplugin](https://github.com/unjs/unplugin).

## Install

```bash
npm i rolldown-string
```

## Usage

### `withMagicString`

Higher-order function to create a `transform` hook with `magic-string` support.

```ts
import { withMagicString } from 'rolldown-string'

const plugin = {
  transform: withMagicString((s, id) => {
    // your transformations...
    s.replace('42', '43')
  }),
}
```

### `rolldownString` / `generateTransform`

More flexible way to use `rolldown-string`.

```ts
import { generateTransform, rolldownString } from 'rolldown-string'

const yourPlugin = {
  transform(code, id, meta) {
    const s = rolldownString(code, id, meta)

    // your transformations...
    s.replace('42', '43')

    return generateTransform(s, id)
  },
}
```

## Sponsors

<p align="center">
  <a href="https://cdn.jsdelivr.net/gh/sxzz/sponsors/sponsors.svg">
    <img src='https://cdn.jsdelivr.net/gh/sxzz/sponsors/sponsors.svg'/>
  </a>
</p>

## License

[MIT](./LICENSE) License © 2025-PRESENT [Kevin Deng](https://github.com/sxzz)

<!-- Badges -->

[npm-version-src]: https://img.shields.io/npm/v/rolldown-string.svg
[npm-version-href]: https://npmjs.com/package/rolldown-string
[npm-downloads-src]: https://img.shields.io/npm/dm/rolldown-string
[npm-downloads-href]: https://www.npmcharts.com/compare/rolldown-string?interval=30
[unit-test-src]: https://github.com/sxzz/rolldown-string/actions/workflows/unit-test.yml/badge.svg
[unit-test-href]: https://github.com/sxzz/rolldown-string/actions/workflows/unit-test.yml

---
_Source: https://npm.io/package/rolldown-string · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
