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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Soenneker.JavaScript.Formatter" Version="4.0.85" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.JavaScript.Formatter" Version="4.0.85" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.JavaScript.Formatter" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Soenneker.JavaScript.Formatter --version 4.0.85
                    
#r "nuget: Soenneker.JavaScript.Formatter, 4.0.85"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Soenneker.JavaScript.Formatter@4.0.85
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Soenneker.JavaScript.Formatter&version=4.0.85
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.JavaScript.Formatter&version=4.0.85
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
Loading failed