UNPKG

1.47 kBMarkdownView Raw
1# dprint
2
3[![npm version](https://badge.fury.io/js/dprint.svg)](https://badge.fury.io/js/dprint)
4[![Build Status](https://travis-ci.org/dsherret/dprint.svg?branch=master)](https://travis-ci.org/dsherret/dprint)
5
6TypeScript and JSONC code formatter.
7
8## Install
9
10Install `dprint` and the plugins you want to use as a dev dependency.
11
12For example:
13
14```
15yarn add --dev dprint dprint-plugin-typescript dprint-plugin-jsonc
16# or
17npm install --save-dev dprint dprint-plugin-typescript dprint-plugin-jsonc
18```
19
20## Usage
21
22Create a *dprint.config.js* file in the repo. Here's an example (you don't need to copy this... use your own config):
23
24```js
25// @ts-check
26const { TypeScriptPlugin } = require("dprint-plugin-typescript");
27const { JsoncPlugin } = require("dprint-plugin-jsonc");
28
29/** @type { import("dprint").Configuration } */
30module.exports.config = {
31 projectType: "openSource",
32 lineWidth: 160,
33 plugins: [
34 new TypeScriptPlugin({
35 useBraces: "preferNone",
36 "tryStatement.nextControlFlowPosition": "sameLine"
37 }),
38 new JsoncPlugin({
39 indentWidth: 2
40 })
41 ]
42};
43```
44
45Add a format script to your *package.json*'s "scripts" section (see `npx dprint --help` for usage):
46
47```json
48{
49 "name": "your-package-name",
50 "scripts": {
51 "format": "dprint \"**/*{.ts,.tsx,.json,.js}\""
52 }
53}
54```
55
56Format:
57
58```
59yarn format
60# or
61npm run format
62```