# @dotbox/format

> A library for formatting DotBox files.

Latest version **1.0.2** (published 2022-05-01) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @dotbox/format
pnpm add @dotbox/format
yarn add @dotbox/format
bun add @dotbox/format
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2022-05-01 |
| First published | 2022-04-30 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 21.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Jake Hamilton |
| Maintainers | jakehamilton |
| Keywords | box, config, language, json, compiler |

## Links

- npm: https://www.npmjs.com/package/@dotbox/format
- Repository: https://github.com/jakehamilton/dotbox
- Issues: https://github.com/jakehamilton/dotbox/issues
- npm.io page: https://npm.io/package/@dotbox/format

## Dependencies (2)

- [@dotbox/compiler](https://npm.io/package/@dotbox/compiler.md) 1.0.2
- [@littlethings/coder](https://npm.io/package/@littlethings/coder.md) ^1.1.2

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.2 (latest) — 2022-05-01
- 1.0.1 — 2022-04-30
- 1.0.0 — 2022-04-30

## README

# @dotbox/format

> A formatter for DotBox files.

## Installation

```bash
# 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.

```ts
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.

```ts
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;
```

---
_Source: https://npm.io/package/@dotbox/format · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
