[][src]Function dprint_plugin_typescript::format_text

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

Formats a file.

Returns the file text Ok(formatted_text) or an error when it failed to parse.

Example

use std::path::PathBuf;
use dprint_plugin_typescript::*;
use dprint_plugin_typescript::configuration::*;

// build the configuration once
let config = ConfigurationBuilder::new()
    .line_width(80)
    .prefer_hanging(true)
    .prefer_single_line(false)
    .quote_style(QuoteStyle::PreferSingle)
    .next_control_flow_position(NextControlFlowPosition::SameLine)
    .build();

// now format many files (it is recommended to parallelize this)
let files_to_format = vec![(PathBuf::from("path/to/file.ts"), "const  t  =  5 ;")];
for (file_path, file_text) in files_to_format.iter() {
    let result = format_text(file_path, file_text, &config);
    // save result here...
}