
Security News
minimatch Patches 3 High-Severity ReDoS Vulnerabilities
minimatch patched three high-severity ReDoS vulnerabilities that can stall the Node.js event loop, and Socket has released free certified patches.
format-file
Advanced tools
Code and config generation is hard enough already. Some of this code should be checked into version control, and should therefore abide by the repositories code formatting rules.
format-file is a package which will return a formatted version of generated JSON, typescript, and javascript files by inferring the formatting rules at runtime.
Under the hood, it uses either the user's configured biome or prettier setup to format files on their behalf.
npm i format-file
Format-file is an ESM package. It must be imported.
Due to peer dependencies on biome + prettier, it is recommended to install at least one of them as well (or set up a similar peer dependency).
// generated.ts
export const foo={
abc : 123,
efg:456 ,
} ;
// index.ts
import { formatFile, formatText } from 'format-file';
await formatFile('./generated.ts');
readFileSync('/generated.ts', 'utf8');
/**
* export const foo = {
* abc: 123,
* efg: 456
* };
*/
await formatText(`
{ "abc":123 ,
"efg":
456}
`, { ext: '.json' });
/**
* {
* "abc": 123,
* "efg": 456
* }
*/
File formatting is best effort and is not necessarily guaranteed to succeed. Primarily if the repo does not have biome or prettier installed.
It is recommended to create reasonable files before formatting, such as generating JSON files using JSON.stringify(content, null, 2) as a reasonable default.
Both biome and prettier have been declared as optional peerDependencies in this package. If using this library as an internal functionality, it is recommended to keep biome and prettier as optional peer dependencies to maintain your package's dependency.
formatFile(filePath, options?)Formats a file in-place.
The first parameter is the file path. If the path is relative, will be resolved from working directory just like regular fs methods.
The second parameter is an optional object with a formatter property.
While the default behavior is 'inherit' which will iterate over viable formatters based on support. It may be overridden with 'biome' or 'parser'.
Returns a promise which when resolved, means the file is formatted according user settings.
formatFiles(filePath[], options?)Formats a set of files in-place.
First parameter is a list of file paths. Any paths that are relative will be resolved from working directory just like regular fs methods.
Second parameter is an optional object the same as formatFile
Returns a promise which when resolved, means the files are formatted according user settings.
formatText(content, options?)Formats an inline text body as if it were a file.
Parameter is the raw text body.
Second parameter is options which include a ext, which defaults to .js. It also support sthe formatter option that formatFile has.
Returns a promise which resolves to a formatted version of the text.
FAQs
Utility API to format files via biome
The npm package format-file receives a total of 8 weekly downloads. As such, format-file popularity was classified as not popular.
We found that format-file demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
minimatch patched three high-severity ReDoS vulnerabilities that can stall the Node.js event loop, and Socket has released free certified patches.

Research
/Security News
Socket uncovered 26 malicious npm packages tied to North Korea's Contagious Interview campaign, retrieving a live 9-module infostealer and RAT from the adversary's C2.

Research
An impersonated golang.org/x/crypto clone exfiltrates passwords, executes a remote shell stager, and delivers a Rekoobe backdoor on Linux.