Skip to content

Commit

Permalink
add indent dsl
Browse files Browse the repository at this point in the history
  • Loading branch information
flyerhzm committed Feb 12, 2025
1 parent cbcf1b1 commit 21bdd9f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ Actions:
* [delete](https://synvert-hq.github.io/synvert-core-javascript/Instance#delete) - delete code the code of specified child nodes
* [remove](https://synvert-hq.github.io/synvert-core-javascript/Instance.html#remove) - remove the whole code of current node
* [replaceWith](https://synvert-hq.github.io/synvert-core-javascript/Instance.html#replaceWith) - replace the whole code of current node
* [indent](https://synvert-hq.github.io/synvert-core-javascript/Instance.html#indent) - indent the code of current node
* [noop](https://synvert-hq.github.io/synvert-core-javascript/Instance.html#noop) - no operation
* [group](https://synvert-hq.github.io/synvert-core-javascript/Instance.html#group) - group actions

Expand Down
14 changes: 14 additions & 0 deletions src/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { evalHelperSync, evalHelper } from "./utils";
import { QueryOptions } from "@synvert-hq/node-query";
import NodeMutation, {
Strategy,
IndentOptions,
InsertOptions,
ReplaceOptions,
DeleteOptions,
Expand Down Expand Up @@ -885,6 +886,19 @@ class Instance<T> {
this.currentMutation.prepend(this.currentNode, code);
}

/**
* Indent the code.
* @example
* // const foo = bar
* // will be converted to
* // const foo = bar
* // after executing
* indent({ tabSize: 1 })
*/
indent(options: IndentOptions): void {
this.currentMutation.indent(this.currentNode, options);
}

/**
* Insert code to the beginning or end of the current node.
* @example
Expand Down

0 comments on commit 21bdd9f

Please sign in to comment.