[−][src]Function dprint_plugin_typescript::format_text
pub fn format_text(
file_path: &str,
file_text: &str,
config: &Configuration
) -> Result<Option<String>, String>
Formats a file.
Returns the file text when the file was formatted, None
when the file had an ignore comment, and
an error when it failed to parse.
Example
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 (consider parallelizing this) let files_to_format = vec![("path/to/file.ts", "const t = 5 ;")]; for (file_path, file_text) in files_to_format { let formatted_text = format_text(file_path, file_text, &config); // ...save formatted_text here... }