indent
Import from @varavel/vdl-plugin-sdk/utils/strings.
function indent(input, prefix?): string;
Adds an indentation prefix to every non-blank line in a multi-line string.
This is the inverse operation of dedent and is useful when injecting a
generated block inside a nested structure (for example, inside a class,
interface, or function body).
Empty and whitespace-only lines are preserved without extra indentation to avoid introducing trailing spaces.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
input | string | undefined | Multi-line string to indent. |
prefix? | string | " " | String to prepend to each non-blank line. Defaults to two spaces. |
Returns
string
The input text with indentation applied line by line.
Examples
indent("name: string;\nactive: boolean;");
// returns " name: string;\n active: boolean;"
indent("field string\nfield int", "\t");
// returns "\tfield string\n\tfield int"