> [!NOTE]
> `@sveltejs/sv-utils` is currently **experimental**. The API may change. Full documentation is not yet available.
`@sveltejs/sv-utils` provides utilities for parsing, transforming, and generating code in add-ons.
```sh
npm install -D @sveltejs/sv-utils
```
## Architecture
The Svelte CLI is split into two packages with a clear boundary:
- **`sv`** = **where and when** to do it. It owns paths, workspace detection, dependency tracking, and file I/O. The engine orchestrates add-on execution.
- **`@sveltejs/sv-utils`** = **what** to do to content. It provides parsers, language tooling, and typed transforms. Everything here is pure - no file system, no workspace awareness.
This separation means transforms are testable without a workspace and composable across add-ons.
## Transforms
Transforms are curried, parser-aware functions that turn `string -> string`. Call a transform with your callback to get a function that plugs directly into `sv.file()`. The parser choice is baked into the transform type - you can't accidentally parse a vite config as Svelte because you never call a parser yourself.
Each transform injects relevant utilities into the callback, so you only need one import:
```js
import { transforms } from '@sveltejs/sv-utils';
```
### `transforms.script`
Transform a JavaScript/TypeScript file. The callback receives `{ ast, comments, content, js }`.
```js
// @noErrors
import { transforms } from '@sveltejs/sv-utils';
sv.file(
files.viteConfig,
transforms.script(({ ast, js }) => {
js.imports.addDefault(ast, { as: 'foo', from: 'foo' });
js.vite.addPlugin(ast, { code: 'foo()' });
})
);
```
### `transforms.svelte`
Transform a Svelte component. The callback receives `{ ast, content, svelte, js }`.
```js
// @noErrors
import { transforms } from '@sveltejs/sv-utils';
sv.file(
layoutPath,
transforms.svelte(({ ast, svelte }) => {
svelte.addFragment(ast, '');
})
);
```
### `transforms.svelteScript`
Transform a Svelte component with a `