Get unlimited public & private packages + package-based permissions with npm Pro.Get started »

dprint

0.9.0 • Public • Published

dprint

npm version Build Status

TypeScript and JSONC code formatter.

Install

Install dprint and the plugins you want to use as a dev dependency.

For example:

yarn add --dev dprint dprint-plugin-typescript dprint-plugin-jsonc
# or
npm install --save-dev dprint dprint-plugin-typescript dprint-plugin-jsonc

Usage

Create a dprint.config.js file in the repo. Here's an example (you don't need to copy this... use your own config):

// @ts-check
const { TypeScriptPlugin } = require("dprint-plugin-typescript");
const { JsoncPlugin } = require("dprint-plugin-jsonc");
 
/** @type { import("dprint").Configuration } */
module.exports.config = {
    projectType: "openSource",
    lineWidth: 160,
    plugins: [
        new TypeScriptPlugin({
            useBraces: "preferNone",
            "tryStatement.nextControlFlowPosition": "sameLine"
        }),
        new JsoncPlugin({
            indentWidth: 2
        })
    ]
};

Add a format script to your package.json's "scripts" section (see npx dprint --help for usage):

{
  "name": "your-package-name",
  "scripts": {
    "format": "dprint \"**/*.{ts,tsx,json,js,jsx}\""
  }
}

Format:

yarn format
# or
npm run format

Install

npm i dprint

DownloadsWeekly Downloads

17

Version

0.9.0

License

MIT

Unpacked Size

64 kB

Total Files

7

Last publish

Collaborators

  • avatar