{"id":13749451,"url":"https://github.com/millermedeiros/esformatter","last_synced_at":"2025-05-15T00:06:57.848Z","repository":{"id":5829419,"uuid":"7045004","full_name":"millermedeiros/esformatter","owner":"millermedeiros","description":"ECMAScript code beautifier/formatter","archived":false,"fork":false,"pushed_at":"2022-12-30T18:44:12.000Z","size":1265,"stargazers_count":969,"open_issues_count":72,"forks_count":91,"subscribers_count":25,"default_branch":"master","last_synced_at":"2025-04-30T12:36:42.575Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/millermedeiros.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-12-06T23:49:41.000Z","updated_at":"2025-04-12T19:12:00.000Z","dependencies_parsed_at":"2023-01-13T13:43:03.953Z","dependency_job_id":null,"html_url":"https://github.com/millermedeiros/esformatter","commit_stats":null,"previous_names":[],"tags_count":49,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/millermedeiros%2Fesformatter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/millermedeiros%2Fesformatter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/millermedeiros%2Fesformatter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/millermedeiros%2Fesformatter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/millermedeiros","download_url":"https://codeload.github.com/millermedeiros/esformatter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253547229,"owners_count":21925546,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T07:01:02.240Z","updated_at":"2025-05-15T00:06:57.829Z","avatar_url":"https://github.com/millermedeiros.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Packages","包"],"sub_categories":["Command-line apps","命令行应用"],"readme":"# esformatter\n\n[![Build Status](https://secure.travis-ci.org/millermedeiros/esformatter.svg?branch=master)](https://travis-ci.org/millermedeiros/esformatter)\n\nECMAScript code beautifier/formatter.\n\n\n## Important\n\nThis tool is still missing support for many important features. Please report\nany bugs you find, the code is only as good as the test cases. Feature requests\nare very welcome.\n\n**We are looking for [contributors](https://github.com/millermedeiros/esformatter/blob/master/CONTRIBUTING.md)!!**\n\n\n\n## Why?\n\n[jsbeautifier.org](http://jsbeautifier.org/) doesn't have enough options and not\nall IDEs/Editors have a good JavaScript code formatter. I would like to have\na command line tool (and standalone lib) at least as powerful/flexible as the\n[WebStorm](http://www.jetbrains.com/webstorm/) and\n[FDT](http://fdt.powerflasher.com/) code formatters so that it can be plugged\ninto any editor and reused by other tools like\n[escodegen](https://github.com/Constellation/escodegen/).\n\nFor more reasoning behind it and history of the project see: [esformatter\n\u0026 rocambole](http://blog.millermedeiros.com/esformatter-rocambole/)\n\n\n\n## How?\n\nThis tool uses [rocambole](https://github.com/millermedeiros/rocambole) and\n[babylon](https://www.npmjs.com/package/babylon) to recursively parse the tokens\nand transform it *in place*.\n\n\n\n## Goals\n\n - *granular* control about white spaces, indent and line breaks.\n - command line interface (cli).\n - be non-destructive.\n - support for local/global config file so settings can be shared between team\n   members.\n - be extensive ([plugins](https://github.com/millermedeiros/esformatter/wiki/Plugins)\n   and other cli tools).\n - support most popular style guides through plugins (Google, jQuery,\n   Idiomatic.js).\n - be the best JavaScript code formatter!\n\n\n\n## API\n\n```js\nvar esformatter = require('esformatter');\nvar fs = require('fs');\nvar codeStr = fs.readFileSync('path/to/js/file.js').toString();\n\n// for a list of available options check \"lib/preset/default.js\"\nvar options = {\n  indent : {\n    value : '  '\n  },\n  lineBreak : {\n    before : {\n      // at least one line break before BlockStatement\n      BlockStatement : '\u003e=1',\n      // only one line break before DoWhileStatementOpeningBrace\n      DoWhileStatementOpeningBrace : 1,\n      // ...\n    }\n  },\n  whiteSpace : {\n    // ...\n  }\n};\n\n// return a string with the formatted code\nvar formattedCode = esformatter.format(codeStr, options);\n```\n\nSee the [doc/api.md](./doc/api.md) file for a list of all the public methods\nand detailed documentation about each one.\n\nSee [doc/config.md](./doc/config.md) for more info about the configuration\noptions.\n\n\n## CLI\n\nYou can also use the simple command line interface to process the `stdin` or\nread from a file.\n\n```sh\nnpm install [-g] esformatter\n```\n\n### Usage:\n\nPass the `--help` flag to see the available options or see\n[doc/cli.txt](./doc/cli.txt).\n\n```sh\nesformatter --help\n```\n\n### Examples:\n\n```sh\n# Format\n# ======\n\n# format \"test.js\" and output result to stdout\nesformatter test.js\n# you can also pipe other shell commands (read file from stdin)\ncat test.js | esformatter\n# format \"test.js\" using options in \"options.json\" and output result to stdout\nesformatter --config options.json test.js\n# process \"test.js\" and writes to \"test.out.js\"\nesformatter test.js \u003e test.out.js\n# you can override the default settings, see lib/preset/default.js for\n# a list of available options\nesformatter test.js --indent.value=\"\\t\" --lineBreak.before.IfStatementOpeningBrace=0\n# format \"test.js\" and output result to \"test.js\"\nesformatter -i test.js\n# format and overwrite all the \".js\" files inside the \"lib/\" folder\nesformatter -i 'lib/*.js'\n# format and overwrite all the \".js\" files inside \"lib/\" and it's subfolders\nesformatter -i 'lib/**/*.js'\n\n# **important:** surround the glob with single quotes to avoid expansion; [glob\n# syntax reference](https://github.com/isaacs/node-glob/#glob-primer)\n\n# Diff\n# ======\n\n# check if \"test.js\" matches style and output diff to stdout\nesformatter --diff test.js\n# check if \"test.js\" matches style and output unified diff to stdout\nesformatter --diff-unified test.js\n# check if \"test.js\" matches \"options.json\" style and output diff to stdout\nesformatter --diff --config options.json test.js\n# check all files inside \"lib/\" and it's subfolders\nesformatter --diff 'lib/**/*.js'\n```\n\n### Local version\n\nIf a locally installed `esformatter` is found, the CLI uses that instead of the\nglobal executable (this means you can have multiple projects depending on\ndifferent versions of esformatter).\n\n**protip:** add `esformatter` and all the plugins that you need on your project\nto the [package.json `devDependencies`](https://docs.npmjs.com/files/package.json#devdependencies)\nthat way you can use locally installed plugins and also make sure everyone on\nyour team is using the same version/settings.\n\n```json\n{\n  \"devDependencies\": {\n    \"esformatter\": \"~0.6.0\",\n    \"esformatter-quotes\": \"^1.0.1\"\n  },\n  \"esformatter\": {\n    \"plugins\": [\"esformatter-quotes\"],\n    \"quotes\": {\n      \"type\": \"single\"\n    }\n  }\n}\n```\n\n\n\n## IDE / Editor integration\n\nSince esformatter is available as a command-line tool, it can be used in any editor that supports external shell commands.\n\n- Vim - [vim-esformatter](https://github.com/millermedeiros/vim-esformatter)\n- Sublime Text - [sublime-esformatter](https://github.com/piuccio/sublime-esformatter)\n- Atom - [atom-esformatter](https://github.com/sindresorhus/atom-esformatter)\n- Visual Studio Code - [vscode-esformatter](https://github.com/leftstick/vscode-esformatter)\n\n\n\n\n## Configuration\n\nSee [doc/config.md](./doc/config.md).\n\n\n## Presets\n\nPresets are reusable config files that can `require` other presets/plugins and\noverride configs.\n\n```js\n{\n  // presets are used as \"base settings\"\n  \"extends\": [\n    \"preset:foobar\", // load \"esformatter-preset-foobar\" from \"./node_modules\"\n    \"./lorem_ipsum.json\" // load relative config file\n  ],\n\n  // you can still override any setting from the preset if needed\n  \"indent\": {\n    \"value\": \"  \"\n  }\n}\n```\n\nFor more info see [presets.md](./doc/presets.md)\n\n## Pipe other CLI tools\n\nSince we don't expect everyone to write plugins that only works with\nesformatter we decided to encourage the usage of standalone CLI tools.\n\n```js\n{\n  // pipe is a simple way to \"pipe\" multiple binaries input/output\n  \"pipe\": {\n    // scripts listed as \"before\" will be executed before esformatter\n    // and will forward output to next command in the queue\n    \"before\": [\n      \"strip-debug\",\n      \"./bin/my-custom-script.sh --foo true -zx\"\n    ],\n    // scripts listed as \"after\" will be executed after esformatter\n    \"after\": [\n      \"baz --keepLineBreaks\"\n    ]\n  }\n}\n```\n\n## Plugins\n\nPlugins are automatically loaded from `node_modules` if you pass the module id\nin the config file:\n\n```json\n{\n  \"plugins\": [ \"esformatter-sample-plugin\", \"foobar\" ]\n}\n```\n\nList of plugins and plugins wish list:\nhttps://github.com/millermedeiros/esformatter/wiki/Plugins\n\nList of plugins with easy filterable search:\nhttp://pgilad.github.io/esformatter-plugins/\n\nFor detailed information about plugins structure and API see\n[doc/plugins.md](./doc/plugins.md)\n\n\n## IRC\n\nWe have an IRC channel [#esformatter on\nirc.freenode.net](http://webchat.freenode.net/?channels=esformatter) for quick\ndiscussions about the project development/structure.\n\n\n## Wiki\n\nSee project Wiki for more info: https://github.com/millermedeiros/esformatter/wiki\n\n\n\n## Project structure / Contributing\n\nSee [CONTRIBUTING.md](https://github.com/millermedeiros/esformatter/blob/master/CONTRIBUTING.md)\n\n\n\n## Popular Alternatives\n\n - [prettier](https://github.com/prettier/prettier)\n - [jsbeautifier](http://jsbeautifier.org/)\n - [codepainter](https://npmjs.org/package/codepainter)\n - [jscs](http://jscs.info/)\n\n\n\n## License\n\nReleased under the MIT license\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmillermedeiros%2Fesformatter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmillermedeiros%2Fesformatter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmillermedeiros%2Fesformatter/lists"}