Skip to content

Programmatic Usage

You can use lin as a library and run commands programmatically. This is useful for integrating lin into your own scripts or tools.

All commands and types are exported from the main package entry point.

The run function allows you to execute any command.

import { run } from '@rttnd/lin'
// Simple usage: run the 'translate' command with the --silent flag
await run('translate', ['-S'])

The run function accepts an optional third argument, options, to control execution behavior. It returns a RunResult object with details about the execution.

function run(
command: keyof Commands,
rawArgs?: string[],
options?: {
dry?: boolean // default: false
output?: 'live' | 'capture' | 'silent' // default: 'live'
}
): Promise<{
result: unknown
output?: string
writes?: Record<string, string>
deletes?: string[]
}>
  • dry: A boolean that, if true, prevents any file system modifications. Instead of writing or deleting files, run will return the planned changes in the writes and deletes objects.
  • output: can return the console output in output
    • 'live' (default) - print only.
    • 'capture' - print and return captured text.
    • 'silent' - capture text without printing.

Here’s how you can see what files check --fix would change, without actually modifying your disk:

import { run } from '@rttnd/lin'
const { output, writes } = await run(
'check',
['--fix'],
{ dry: true, output: 'silent' },
)
console.log('--- Captured Console Output ---')
console.log(output)
console.log('\n--- Files to be Written ---')
for (const [file, content] of Object.entries(writes || {})) {
console.log(`File: ${file}`)
console.log(content) // content is the full file content
}