API リファレンス
format(input, options, ext?, plugin?)
Section titled “format(input, options, ext?, plugin?)”ソース文字列をフォーマットして返します。
import { format } from 'indentier'
const output = format(source, resolvedOptions, '.ts')| パラメーター | 型 | 説明 |
|---|---|---|
input | string | フォーマットするソースコード |
options | ResolvedOptions | 解決済みの設定オプション |
ext | string | ファイル拡張子(例: '.ts')。省略時は '.js' |
plugin | IndentierPlugin | undefined | コア非対応言語用のプラグインインスタンス |
string を返します。
loadConfig(cwd?)
Section titled “loadConfig(cwd?)”cosmiconfig を使って最寄りの設定ファイルを読み込みます。
import { loadConfig } from 'indentier'
const { options, filepath } = await loadConfig()// options は ResolvedOptions(デフォルト値補完済み)Promise<{ options: ResolvedOptions, filepath: string | null }> を返します。
loadPlugins(names)
Section titled “loadPlugins(names)”プラグインパッケージを動的にインポートしてグローバルレジストリに登録します。
import { loadPlugins } from 'indentier'
await loadPlugins(['@indentier/plugin-rust', '@indentier/plugin-go'])| パラメーター | 型 | 説明 |
|---|---|---|
names | string[] | インポートするパッケージ名 |
Promise<void> を返します。
registerPlugin(plugin)
Section titled “registerPlugin(plugin)”プラグインインスタンスを手動で登録します。
import { registerPlugin } from 'indentier'
registerPlugin({ extensions: ['.mylang'], rubyCompatible: false,})getPlugin(ext)
Section titled “getPlugin(ext)”指定した拡張子のプラグインを返します。登録されていなければ undefined。
import { getPlugin } from 'indentier'
const plugin = getPlugin('.rs') // IndentierPlugin | undefinedisPluginExt(ext)
Section titled “isPluginExt(ext)”指定した拡張子のプラグインが登録されていれば true を返します。
clearPlugins()
Section titled “clearPlugins()”登録済みのすべてのプラグインをクリアします。テスト時に便利です。
interface IndentierOptions { mode?: 'default' | 'ruby' tabWidth?: number useTabs?: boolean offset?: number minColumn?: number brackets?: boolean semicolon?: boolean comma?: boolean ruby?: { variableName?: string injectDeclaration?: boolean smartEnd?: boolean } overrides?: Override[] plugins?: string[]}
interface IndentierPlugin { extensions: string[] rubyCompatible?: boolean declarationTemplate?: string | null getEndStatement?: (variableName: string) => string declarationInsertIndex?: (lines: readonly PluginLine[]) => number}
interface PluginLine { readonly body: string}