[][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.


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

// build the configuration once
let config = ConfigurationBuilder::new()

// 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...