Skip to content

API Reference

Formats a source string and returns the formatted string.

import { format } from 'indentier'
const output = format(source, resolvedOptions, '.ts')
ParameterTypeDescription
inputstringSource code to format
optionsResolvedOptionsResolved config options
extstringFile extension (e.g. '.ts'). Defaults to '.js'
pluginIndentierPlugin | undefinedPlugin instance for non-core languages

Returns string.


Loads the nearest .indentierrc.* / indentier.config.* / package.json#indentier config using cosmiconfig.

import { loadConfig } from 'indentier'
const { options, filepath } = await loadConfig()
// options is ResolvedOptions (defaults filled in)

Returns Promise<{ options: ResolvedOptions, filepath: string | null }>.


Dynamically imports plugin packages and registers them in the global registry.

import { loadPlugins } from 'indentier'
await loadPlugins(['@indentier/plugin-rust', '@indentier/plugin-go'])
ParameterTypeDescription
namesstring[]Package names to import

Returns Promise<void>.


Manually registers a plugin instance.

import { registerPlugin } from 'indentier'
registerPlugin({
extensions: ['.mylang'],
rubyCompatible: false,
})

Returns the registered plugin for a file extension, or undefined.

import { getPlugin } from 'indentier'
const plugin = getPlugin('.rs') // IndentierPlugin | undefined

Returns true if a plugin is registered for the given extension.


Clears all registered plugins. Useful in tests.


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
}