> [!NOTE] > `@sveltejs/sv-utils` is currently **experimental**. The API may change. Full documentation is not yet available. `@sveltejs/sv-utils` is an add-on utilty for parsing, transforming, and generating code.. ```sh npm install -D @sveltejs/sv-utils ``` ## transforms `transforms` is a collection of parser-aware functions that lets you modify the files via abstract syntax tree (AST). It accepts a callback function. The return value is designed to be be passed 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(/* ... */); transforms.svelte(/* ... */); // ... ``` ### `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 `