[][src]Function dprint_plugin_typescript::format_text

pub fn format_text(
    file_path: &str,
    file_text: &str,
    config: &ResolvedTypeScriptConfiguration
) -> Result<Option<String>, String>

Formats a file.

Example

// resolve the configuration once...
let config = TypeScriptConfiguration::new()
    .line_width(80)
    .force_multi_line_parameters(true)
    .force_multi_line_arguments(true)
    .single_quotes(true)
    .next_control_flow_position(NextControlFlowPosition::SameLine)
    .resolve();

// now format many files (consider parallelizing this)
for (file_path, file_text) in your_files_to_format {
    let formatted_text = format_text(file_path, file_text, &config);
    // ...save formatted_text here...
}