Biomine (biomine v0.1.0)

Copy Markdown View Source

Documentation for Biomine.

Summary

Functions

Format JavaScript/TypeScript source.

Functions

format_js(source, opts \\ [])

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 :tab or :space. The default value is :space.

  • :indent_width (non_neg_integer/0) - Indentation width as an integer. The default value is 2.

  • :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 is 120.

  • :quote_style - JavaScript quote style, either :double or :single.

  • :jsx_quote_style - JSX quote style, either :double or :single.

  • :quote_properties - Object property quote handling, either :as_needed or :preserve.

  • :trailing_comma - Trailing comma style, one of :all, :es5, or :none.

  • :semicolons - Semicolon style, either :always or :as_needed.

  • :arrow_parentheses - Arrow function parentheses style, either :always or :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 :auto or :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}
    }
  ]}}