
Security News
GPT-6 Astra Attempts Supply Chain Attacks Against Open Source Maintainers in Testing
GPT-6 Astra hits 100% on ExploitBench and finds zero-days autonomously, while independent tests reveal scope violations and monitoring gaps.
Formats your code with whatever formatter your project is already using. ๐งผ
Formats your code with whatever formatter your project is already using. ๐งผ
formatly can automatically detect and format with:
See Formatter Detection for details on how they are detected.
npx formatly <files>
formatly takes in any number of glob patterns.
It will then:
For example, to match all directories and folders in the current directory:
npx formatly *
To match only .ts files in src/:
npx formatly "src/**/*.ts"
npm i formatly
The formatly package exports the functions used by the formatly CLI.
formatlyRuns formatting on any number of glob pattern strings.
import { formatly } from "formatly";
await formatly(["*"]);
Parameters:
patterns: string[] (required): any number of glob patternsoptions: FormatlyOptions (optional):
cwd: string (optional): working directory, if not "."formatter: FormatterName (optional): explicit formatter to use instead of detecting one, supports "biome", "deno", "dprint", and "prettier"order: FormatterName[] (optional): formatters to detect first, in order, as used by resolveFormatterstopDirectory: StopDirectory (optional): directory to stop searching parent directories for a config file at, as used by resolveFormatterResolves with a FormatlyReport, which is either:
FormatlyReportError if a formatter could not be determined, which an object containing:
ran: falseFormatlyReportResult if a formatter could be determined, which is an object containing:
formatter: Formatter: as resolved by resolveFormatterran: trueresult: FormatlyReportChildProcessResult:
code: number | null: exit code of the child processsignal: NodeJS.Signal | null: signal that terminated the child processFor example, to run formatting on TypeScript source files in a child directory and check the result:
import { formatly } from "formatly";
const report = await formatly(["src/**/*.ts"], { cwd: "path/to/project" });
if (!report.ran) {
console.error("Could not determine formatter.");
return;
}
const { formatter, result } = report;
if (result.code) {
console.error(`Error running ${formatter.runner}:`, result.stderr);
} else {
console.log(`Formatted with ${formatter.name}! ๐งผ`);
}
resolveFormatterDetects which of the supported formatters to use for a directory.
import { resolveFormatter } from "formatly";
const formatter = await resolveFormatter();
// {
// name: "Prettier",
// runner: "npx prettier --write",
// testers: { ... }
// }
console.log(formatter);
Parameters:
cwd: string (optional): working directory, if not "."options: ResolveFormatterOptions (optional):
order: FormatterName[] (optional): formatters to detect first, in orderstopDirectory: StopDirectory (optional): directory to stop searching parent directories for a config file at, either a string path or a (currentDirectory: string) => boolean functionBy default, only the working directory is searched for a config file.
Passing stopDirectory also searches each parent directory in turn, stopping once the directory matching stopDirectory has been searched.
A string is matched as a directory path, while a function is called with each directory and may return true to indicate the last directory to search.
Reaching the file system root without a match throws an error, as that indicates a stopDirectory that isn't a parent of the working directory.
For example, to search up to whichever parent directory contains a .git directory:
import { resolveFormatter } from "formatly";
import { existsSync } from "node:fs";
import * as path from "node:path";
const formatter = await resolveFormatter("path/to/project", {
stopDirectory: (currentDirectory) =>
existsSync(path.join(currentDirectory, ".git")),
});
console.log(formatter);
By default, formatters are detected in their documented order.
Passing order tries the named formatters first, in the order given; any formatter not named is tried afterwards in the default order.
Duplicate names, and names that aren't supported formatters, throw an error.
For example, to detect Biome before Prettier:
import { resolveFormatter } from "formatly";
const formatter = await resolveFormatter("path/to/project", {
order: ["biome", "prettier"],
});
console.log(formatter);
Resolves with either:
undefined if a formatter could not be detectedFormatter if one can be found, which is an object containing:
name: string: English name of the formatterrunner: string: the shell command used to run the formattertesters: object: strings and regular expressions used to test for the formatterFormatters are detected based on the first match from, in order:
package.json fmt or format scriptpackage.json keyConfig files are only searched for in the working directory unless a stopDirectory is provided.
package.json is always searched for in the working directory and its parent directories.
| Formatter | Config File | Package Key | Script |
|---|---|---|---|
| Biome | Configure Biome | biome | |
| deno fmt | Deno Configuration > Formatting | deno | |
| dprint | dprint setup | dprint | |
| Oxfmt | Oxfmt Configuration | oxfmt | |
| Prettier | Prettier Configuration File | "prettier" | prettier |
Want support for a formatter not mentioned here? Great! Please file a feature request GitHub issue. ๐
Formatly is a tool for any developer tool that creates files for users.
If your tool creates, say, a config file that users are meant to check into their repository, you probably want that file to be formatted per the user's preference.
But there are several popular formatters in use today: it's not enough to just call to prettier.format.
Formatly takes away the burden of
No. Formatly is a detection + wrapping layer around formatters such as Prettier. Userland projects still need to configure a formatter themselves.
See .github/CONTRIBUTING.md, then .github/DEVELOPMENT.md.
Thanks! ๐งผ
Alec Larson ๐ค ๐ป | Bjorn Lu ๐ค ๐ป ๐ | Eli ๐ | Josh Goldberg โจ ๐ป ๐ ๐ค ๐ ๐ง ๐ ๐ง ๐ ๐ | Lars Kappert ๐ ๐ป | rubiesonthesky ๐ |
๐ This package was templated with
create-typescript-appusing the Bingo framework.
FAQs
Formats your code with whatever formatter your project is already using. ๐งผ
The npm package formatly receives a total of 7,290,598 weekly downloads. As such, formatly popularity was classified as popular.
We found that formatly demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.ย It has 1 open source maintainer collaborating on the project.

Security News
GPT-6 Astra hits 100% on ExploitBench and finds zero-days autonomously, while independent tests reveal scope violations and monitoring gaps.

Product
Socket can now send alerts and supply chain attack notifications to Microsoft Teams, with filters that route the right updates to each channel.

Security News
pnpm 12 rewrites the package manager in Rust, cutting install times by up to 90% while preserving pnpm 11 workflows and lockfiles.