@btmills/prettier

中文文档
3.3.3发布于 2024/07/29MITTypeScriptESM + CJS零依赖近 30 天下载 1.5万

Prettier is an opinionated code formatter

原始使用文档
文档目录8 节
  1. Usage
  2. Releases
  3. Opinionated Code Formatter
  4. Intro
  5. Input
  6. Output
  7. Badge
  8. Contributing

:fork_and_knife: This is a fork.

Compared to prettier, @btmills/prettier moves binary operators to the beginning of new lines in long expressions instead of the end of the previous line. That's it.

// prettier:
const before =
  bom.length >= 2 &&
  ((bom.charCodeAt(0) === 0xff && bom.charCodeAt(1) === 0xfe) ||
    (bom.charCodeAt(0) === 0xfe && bom.charCodeAt(1) === 0xff));

// @btmills/prettier:
const after =
  bom.length >= 2
  && ((bom.charCodeAt(0) === 0xff && bom.charCodeAt(1) === 0xfe)
    || (bom.charCodeAt(0) === 0xfe && bom.charCodeAt(1) === 0xff));

Usage

Install using an alias (npm, yarn) so that require('prettier') transparently resolves to this fork:

npm install --save-dev prettier@npm:@btmills/prettier
yarn add --dev prettier@npm:@btmills/prettier

This package will function just like prettier, and editor integrations should use it as if it were the real thing.

Releases

Releases of the forked package are done by rebasing the line-before-operator branch on top of the most recent version tag in main.

# Get the latest changes and update the main branch:
git checkout main
git pull
git push fork

# Rebase the release branch on the latest version:
git checkout line-before-operator
git rebase x.y.z

# Fix conflicts as necessary.
git rebase --continue
# There will be a merge conflict in `yarn.lock`. To resolve it:
yarn && yarn dedupe && yarn dedupe --check
# If any conflicts in snapshots, discard and update automatically:
yarn test -u

# With rebasing done, run tests, push tags, build, and publish:
yarn run lint
yarn test
git tag x.y.z-fork
git push --force-with-lease
git push --tags
yarn run build
yarn run test:dist
cd dist
npm publish

Prettier Banner

Opinionated Code Formatter

JavaScript · TypeScript · Flow · JSX · JSON
CSS · SCSS · Less
HTML · Vue · Angular
GraphQL · Markdown · YAML
Your favorite language?

Github Actions Build Status Github Actions Build Status Github Actions Build Status Codecov Coverage Status Blazing Fast
npm version weekly downloads from npm code style: prettier Follow Prettier on Twitter

Intro

Prettier is an opinionated code formatter. It enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary.

Input

foo(reallyLongArg(), omgSoManyParameters(), IShouldRefactorThis(), isThereSeriouslyAnotherOne());

Output

foo(
  reallyLongArg(),
  omgSoManyParameters(),
  IShouldRefactorThis(),
  isThereSeriouslyAnotherOne(),
);

Prettier can be run in your editor on-save, in a pre-commit hook, or in CI environments to ensure your codebase has a consistent style without devs ever having to post a nit-picky comment on a code review ever again!


Documentation

Install · Options · CLI · API

Playground


Badge

Show the world you're using Prettier → code style: prettier

[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)

Contributing

See CONTRIBUTING.md.

版本与发布记录

@btmills/prettier 共发布 65 个版本,首次发布于 2018/11/02;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.3.3latest2024/07/292 年前
3.3.22024/07/292 年前
3.3.12024/07/292 年前
3.3.02024/07/292 年前
3.2.52024/02/262 年前
3.2.42024/02/012 年前

关于 @btmills/prettier 的常见问题

@btmills/prettier 是什么?

Prettier is an opinionated code formatter

如何安装 @btmills/prettier?

在项目目录运行 npm install @btmills/prettier,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 prettier,可以用 npx prettier 直接运行。

@btmills/prettier 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@btmills/prettier 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@btmills/prettier 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=14。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@btmills/prettier 可以商用吗?

@btmills/prettier 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@btmills/prettier 的下载量有多少?

根据 npm 官方下载统计,@btmills/prettier 在 2026/10/09 – 2026/11/07 这 30 天内被下载 15,112 次,日均约 504 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@btmills/prettier 还在维护吗?

最新版本 3.3.3 发布于 2024/07/29(2 年前);至今共发布 65 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/11/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。