# jformatter

> A JavaScript formatter

Latest version **1.0.13** (published 2015-11-04) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install jformatter
pnpm add jformatter
yarn add jformatter
bun add jformatter
```

Provides the command `jformatter`.

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.13 |
| Published | 2015-11-04 |
| First published | 2014-03-13 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | ishowshao |
| Maintainers | ishowshao, ecomfe |
| Keywords | javascript, formatter, ast, code style |

## Links

- npm: https://www.npmjs.com/package/jformatter
- Repository: https://github.com/ecomfe/jformatter
- Issues: https://github.com/ecomfe/jformatter/issues
- npm.io page: https://npm.io/package/jformatter

## Dependencies (3)

- [commander](https://npm.io/package/commander.md) ^2.5.0
- [rocambole](https://npm.io/package/rocambole.md) 0.3.6
- [differ-cli](https://npm.io/package/differ-cli.md) 0.2.2

## Alternatives

- [update-check](https://npm.io/package/update-check.md) — 4.0M weekly downloads
- [react-native-onesignal](https://npm.io/package/react-native-onesignal.md) — 134.5K weekly downloads
- [react-redux-toastr](https://npm.io/package/react-redux-toastr.md) — 33.7K weekly downloads
- [@nocobase/plugin-notification-manager](https://npm.io/package/@nocobase/plugin-notification-manager.md) — 2.0K weekly downloads
- [react-simple-toasts](https://npm.io/package/react-simple-toasts.md) — 1.9K weekly downloads

## Recent versions

- 1.0.13 (latest) — 2015-11-04
- 1.0.12 — 2015-11-04
- 1.0.11 — 2015-09-07
- 1.0.9 — 2015-05-18
- 1.0.8 — 2015-05-04
- 1.0.7 — 2015-04-14
- 1.0.6 — 2014-12-03
- 1.0.5 — 2014-12-03
- 1.0.4 — 2014-12-03
- 1.0.3 — 2014-12-03
- 1.0.2 — 2014-11-30
- 1.0.1 — 2014-11-28
- 1.0.0 — 2014-11-27
- 0.2.0 — 2014-11-05
- 0.1.9 — 2014-11-05
- … 30 more at https://npm.io/package/jformatter/versions

## README

# jformatter

A JavaScript formatter

![jformatter](http://img.shields.io/npm/dm/jformatter.svg)

## Basic usage

The easiest way to use JFormatter is to install it as a Node program.

    npm -g install jformatter

After you've done that you should be able to use the `jformatter` program.

    jformatter file.js

## Command in Terminal

```
  Usage: jformatter [options] <file>

  Options:

    -h, --help     output usage information
    -v, --version  output the version number
    -d, --diff     Show difference between source and formatted
```

## Configuration

When use jformatter in terminal, it will try to load `.jformatterrc`.

JFormatter will start looking for this file in the same directory as the file that's being formatted. If not found, it will move one level up the directory tree all the way up to the filesystem root.

Default config, developing, not stable.

    {
        lineSeparator: '\n', // done
        maxLength: 120, // TODO
        wrapIfLong: false, // TODO
        indent: 4, // done
        useTabIndent: false, // done
        spaces: {
            around: {
                unaryOperators: false, // TODO
                binaryOperators: true, // done
                ternaryOperators: true // done
            },
            before: {
                functionDeclarationParentheses: false, // done function foo() {
                functionExpressionParentheses: true, // done var foo = function () {
                parentheses: true, // done if (), for (), while (), ...
                leftBrace: true, // done function () {, if () {, do {, try { ...
                keywords: true // done if {} else {}, do {} while (), try {} catch () {} finally
            },
            within: {
                // function call, function declaration, if, for, while, switch, catch
                parentheses: false // done
            },
            other: {
                beforePropertyNameValueSeparator: false, // done {key: value} {key : value} {key:value}
                afterPropertyNameValueSeparator: true // done
            }
        },
        bracesPlacement: { // 1. same line 2. next line
            functionDeclaration: 1, // TODO
            other: 1 // TODO
        },
        blankLines: {
            keepMaxBlankLines: 1, // done
            atEndOfFile: true // done
        },
        other: {
            keepArraySingleLine: false // TODO default formatted array multi line
        },
        fix: {
            prefixSpaceToLineComment: false, // done
            alterCommonBlockCommentToLineComment: false, // done
            singleVariableDeclarator: false, // done
            fixInvalidTypeof: false, // done
            removeEmptyStatement: false, // done
            autoSemicolon: false, // done
            singleQuotes: false, // done
            eqeqeq: false, // done
            invalidConstructor: false, // done
            addCurly: false, // done
            removeDebugger: false // done
        }
    }

## API

    require('jformatter').format(code, [configObj]) : string
    require('jformatter').formatFile(filePath, [configObj]) : string
    require('jformatter').version() : string
    require('jformatter').getDefaultConfig() : configObj


## Important Note

please update to `>=v1.0.5`, see version change log

## Changelog

### next

* make all config work
* 调整注释缩进

### v1.0.9 (2015/05/18)

* auto fix: addCurly, add curly for if/while/for statement
* auto fix: removeDebugger, remove debugger statement

### v1.0.8 (2015/05/04)

* fix bug: fix error when format empty file
* catch error when esprima parse syntax error files

### v1.0.7 (2015/04/14)

* fix bug: for windows environment

### v1.0.6 (2014/12/03)

* fix bug: single quotes auto-fix bugs
* update test case

### v1.0.5 (2014/12/03)

* fix bug: lost space before `instanceof`

### v1.0.4 (2014/12/03)

* fix bug: autoSemicolon add semicolon in for statement

### v1.0.3 (2014/12/03)

* add 5 auto fix, please see `config.fix`
* improve command line tool, please see document
* test case update

### v1.0.2 (2014/11/30)

* new and safe logic of keeping blank line
* config for blank line at end of file
* keep 1 blank line default
* test case update

### v1.0.1 (2014/11/28)

* keep blank line after file doc
* keep blank line after `},`

### v1.0.0 (2014/11/27)

* all new architecture with rocambole
* more config work
* fix a bug in auto-fixer

### v0.2.0 (2014/11/05)

* npm test: config auto test
* npm test: style auto test
* add four auto-fixer config
* fix bug: Comment at first line cause redundant LineBreak
* version rule

### v0.1.8 (2014/10/28)

* add version api

### v0.1.6 (2014/08/27)

* fix bug: lost space after `void`

### v0.1.5 (2014/08/27)

* fix bug: lost space after `typeof`
* fix bug: lost space after comma expression

### v0.1.4 (2014/08/19)

* remove config not relate to code style
* change config editable with common config editor
* support npm test

### v0.1.2 (2014/08/08)

* Fix DoWhileStatement bug

### v0.1.0 (2014/08/07)

* Initial release

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