Soenneker.JavaScript.Formatter
4.0.85
Prefix Reserved
dotnet add package Soenneker.JavaScript.Formatter --version 4.0.85
NuGet\Install-Package Soenneker.JavaScript.Formatter -Version 4.0.85
<PackageReference Include="Soenneker.JavaScript.Formatter" Version="4.0.85" />
<PackageVersion Include="Soenneker.JavaScript.Formatter" Version="4.0.85" />
<PackageReference Include="Soenneker.JavaScript.Formatter" />
paket add Soenneker.JavaScript.Formatter --version 4.0.85
#r "nuget: Soenneker.JavaScript.Formatter, 4.0.85"
#:package Soenneker.JavaScript.Formatter@4.0.85
#addin nuget:?package=Soenneker.JavaScript.Formatter&version=4.0.85
#tool nuget:?package=Soenneker.JavaScript.Formatter&version=4.0.85
Soenneker.JavaScript.Formatter
Parses and serializes JavaScript as readable or compact source, with helpers for files and directories.
Install
dotnet add package Soenneker.JavaScript.Formatter
Register
using Soenneker.JavaScript.Formatter.Registrars;
services.AddJavaScriptFormatterAsSingleton();
A scoped registration is available through AddJavaScriptFormatterAsScoped().
Format source
using Soenneker.JavaScript.Formatter.Abstract;
string readable = await formatter.PrettyPrint(
"function total(a,b){return a+b}",
cancellationToken);
string compact = await formatter.Normalize(readable, cancellationToken);
PrettyPrint() uses four-space indentation and K&R-style braces. Normalize() emits compact source; it is a canonical serializer, not an optimizing minifier.
Both methods parse into an AST and generate new source. They are not lossless: comments, original whitespace, quote choices, and semicolon choices may not be preserved. Do not use these APIs when license comments, source-map comments, or exact source text must survive.
The parser accepts JavaScript scripts and modules and retries the alternate source type when needed. Invalid JavaScript and unsupported syntax such as TypeScript annotations cause an Acornima.ParseErrorException. Null, empty, or whitespace-only input produces an empty string.
Format files
string preview = await formatter.PrettyPrintFile(
"src/app.js",
cancellationToken: cancellationToken);
await formatter.SavePrettyPrintedFile(
sourcePath: "src/app.js",
destinationPath: "output/app.js",
cancellationToken: cancellationToken);
await formatter.SaveNormalizedFile(
sourcePath: "src/app.js",
cancellationToken: cancellationToken); // overwrites src/app.js
The read methods return transformed source without modifying the file. The Save methods write to the destination, or overwrite the source when no destination is supplied.
Format a directory
await formatter.PrettyPrintDirectory(
"src",
recursive: true,
cancellationToken: cancellationToken);
This overwrites .js, .mjs, and .cjs files in place. Cancellation does not restore files already written. The token is observed before parsing and throughout file operations, but the synchronous parser itself cannot be interrupted after it starts processing one source string.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Acornima.Extras (>= 1.8.0)
- Soenneker.Utils.Directory (>= 4.0.909)
- Soenneker.Utils.File (>= 4.0.2226)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.85 | 0 | 8/30/2026 |
| 4.0.84 | 0 | 8/30/2026 |
| 4.0.83 | 37 | 8/29/2026 |
| 4.0.82 | 39 | 8/29/2026 |
| 4.0.81 | 45 | 8/29/2026 |
| 4.0.80 | 72 | 8/26/2026 |
| 4.0.79 | 59 | 8/26/2026 |
| 4.0.78 | 68 | 8/26/2026 |
| 4.0.77 | 88 | 8/22/2026 |
| 4.0.76 | 83 | 8/22/2026 |
| 4.0.75 | 87 | 8/22/2026 |
| 4.0.74 | 81 | 8/22/2026 |
| 4.0.73 | 90 | 8/21/2026 |
| 4.0.72 | 89 | 8/18/2026 |
| 4.0.71 | 87 | 8/18/2026 |
| 4.0.70 | 96 | 8/12/2026 |
| 4.0.69 | 90 | 8/12/2026 |
| 4.0.68 | 93 | 8/12/2026 |
| 4.0.67 | 94 | 8/9/2026 |
| 4.0.66 | 99 | 8/8/2026 |