Documentation for Biomine.
Summary
Functions
Format JavaScript/TypeScript source.
Functions
Format JavaScript/TypeScript source.
Returns {:ok, formatted_source} when formatting succeeds.
Returns {:error, {:parse_error, diagnostics}} when the source cannot be
parsed and {:error, :invalid_option} when an unsupported option or option
value is provided.
Options
:indent_style- Indentation style, either:tabor:space. The default value is:space.:indent_width(non_neg_integer/0) - Indentation width as an integer. The default value is2.:line_ending- Line ending style, one of:lf,:crlf, or:cr. The default value is:lf.:line_width- Maximum line width as an integer from 1 to 320. The default value is120.:quote_style- JavaScript quote style, either:doubleor:single.:jsx_quote_style- JSX quote style, either:doubleor:single.:quote_properties- Object property quote handling, either:as_neededor:preserve.:trailing_comma- Trailing comma style, one of:all,:es5, or:none.:semicolons- Semicolon style, either:alwaysor:as_needed.:arrow_parentheses- Arrow function parentheses style, either:alwaysor:as_needed.:bracket_spacing(boolean/0) - Whether to print spaces inside object literal brackets.:bracket_same_line(boolean/0) - Whether to keep closing JSX brackets on the same line.:attribute_position- JSX attribute position style, either:autoor:multiline.
Examples
iex> Biomine.format_js("let x=1")
{:ok, "let x = 1;\n"}
iex> Biomine.format_js("let x='hello'", quote_style: :single)
{:ok, "let x = 'hello';\n"}
iex> Biomine.format_js("funtion f(")
{:error,
{:parse_error,
[
%{
message: "Expected a semicolon or an implicit semicolon after a statement, but found none",
span: %{start: 8, end: 9}
},
%{
message: "expected `)` but instead the file ends",
span: %{start: 10, end: 10}
}
]}}