@dotbox/format
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

@dotbox/format

A formatter for DotBox files.

Installation

# Using npm.
npm install @dotbox/format

# Using yarn.
yarn add @dotbox/format

Usage

format(text: string)

To format DotBox code, call the format function with the contents of your .box file.

import { format } from "@dotbox/format";

const text = `
// This is my awesome DotBox file.
my_key = {
	my_number = 1_000
}
`;

const { value, error } = format(text);

if (error) {
	// Handle compilation errors
	for (const err of error) {
		// ...
	}
} else {
	// Use `value` (the formatted text) somehow
	console.log("Formatted Text:");
	console.log(value);
}

class Formatter

It is typically unnecessary to use the Formatter class directly, but in the event you need it this package exports the class.

import { Formatter } from "@dotbox/format";

const text = `
// This is my awesome DotBox file.
my_key = {
	my_number = 1_000
}
`;

const formatter = new Formatter();

const { value, error } = formatter.format(text);

if (error) {
	// Handle compilation errors
	for (const err of error) {
		// ...
	}
} else {
	// Use `value` (the formatted text) somehow
	console.log("Formatted Text:");
	console.log(value);
}

// The Parser and Lexer instances can be accessed on the
// Formatter instance.
const parser = formatter.parser;
const lexer = formatter.lexer;

Package Sidebar

Install

npm i @dotbox/format

Weekly Downloads

3

Version

1.0.2

License

Apache-2.0

Unpacked Size

21.6 kB

Total Files

7

Last publish

Collaborators

  • jakehamilton