Utvikling · verktøy

JavaScript-formaterer og minifiserer

Lim inn JavaScript og velg formatering eller minifisering. Se gjennom parserfeil før du kopierer.

Kjøres i nettleseren. Ingen opplasting.

Values are processed locally in this browser.

Result

—

Om verktøyet

JavaScript-formaterer og minifiserer sem complicação.

Verktøyet evaluerer aldri kildekoden. Formatereren er syntaksbevisst; minifisert resultat kan være vanskeligere å redigere, så behold originalfilen.

Veiledning

Slik bruker du JavaScript-formaterer og minifiserer

The JavaScript Formatter and Minifier takes a piece of JavaScript and either tidies it into a readable layout or squeezes it into a short single line. Formatting uses the Prettier library and minifying uses Terser, both run inside your browser tab. The tool reads your code as text and never runs it. It does not fix bugs, check style rules, bundle files or understand TypeScript.

Slik gjør du

  1. Paste your JavaScript into the source box. It must not be empty and must be under 200,000 characters.
  2. Choose Format to get a clean layout, or Minify to get the shortest version.
  3. Press Calculate. If the code has a syntax error, the box shows the parser's message and a dash instead of a result.
  4. Press Copy result to copy the output. Clear empties the source and sets the action back to Format.

Eksempler

Formatting a one-line script

Du skriver inn
Handling
format
Kildekode
function add(a,b){return a+b}const x=add(1,2);console.log(x)
Du får
Resultat
/*! license */\nfunction greet(e){return"Hi "+e}greet("x");

Each statement goes on its own line, braces get spaces and two-space indents, and semicolons are added where they were missing. Lines are wrapped at 100 characters.

Kjørt med verktøyets egen kode.

Minifying the same script

Du skriver inn
Handling
minify
Kildekode
function add(a,b){return a+b}const x=add(1,2);console.log(x)
Du får
Resultat
function add(n,o){return n+o}const x=add(1,2);console.log(x);

Spaces and line breaks go, and the names of the function's own parameters are shortened to single letters. The names add and x stay, because top-level names are kept by default.

Kjørt med verktøyets egen kode.

Which comments survive minifying

Du skriver inn
Handling
minify
Kildekode
/*! license */\nfunction greet(name){ /* note */ return "Hi " + name }\ngreet("x")
Du får
Resultat
/*! license */\nfunction greet(e){return"Hi "+e}greet("x");

A comment that starts with an exclamation mark is kept, which is the usual place for a license line. The ordinary note comment is removed.

Kjørt med verktøyets egen kode.

Når det er nyttig

  • Make a minified or one-line snippet readable so you can follow what it does.
  • Tidy code you pasted from several places into one consistent layout before sharing it.
  • Shrink a small script before placing it inside a page, a bookmarklet or a note.
  • Find a missing bracket or stray character, because the parser points to the line and column.

Begrensninger

  • Source text must be non-empty and at most 200,000 characters. The tool works on a single piece of code, with no project files, imports, bundling or source maps.
  • It reads standard JavaScript, and the Format action also reads JSX. TypeScript, such as a type after a colon, is refused with a syntax error.
  • Format always uses the same settings: lines wrap at 100 characters, semicolons are added, and you cannot change quotes, indent size or other style options.
  • Minifying can break code that depends on the names of parameters, on eval, or on reading the source text of a function. Test the output and keep your original file.

Tips

  • Run Format on minified code first if you need to read it, then edit the original source rather than the result.
  • Put licenses and notices in a /*! ... */ comment if they must survive minifying.
  • When you get an error, look at the line and column in the message and check the characters just before that spot.

Kilder

Vanlige spørsmål

Sobre JavaScript-formaterer og minifiserer.

Does this tool run my JavaScript?

No. It parses the text to understand its structure and then prints or compresses it, and it never evaluates the code. A script that would delete files or call a server does nothing here. The result is only text for you to copy.

What is the difference between Format and Minify?

Format spreads the code out for people, with indents and line breaks. Minify removes everything a computer does not need and shortens local names to make the file smaller. Minified code is hard to read, so keep the formatted source.

Why do I see Unexpected token as an error?

The parser found a character where the grammar did not allow one, such as a missing bracket, an extra comma or a type annotation. The message gives the place. Format errors show a line and column. Minify messages can be shorter and less exact.

Can it format TypeScript, JSON, HTML or CSS?

No. This page is set up for JavaScript only. A type annotation such as const x: number = 1 gives an error. The site has separate pages for HTML and CSS, and JSON has its own formatter.

Which comments does the minifier keep?

It keeps some comments, mainly those that start with an exclamation mark, such as /*! license */. Ordinary line and block comments are removed. Check the output if you need a notice to stay in the file.

Is it safe to use the minified code in production?

Often yes, but you should test it. Shortening names or removing code that looks unused can change how a script behaves if it relies on eval or on function names. This tool gives no test and cannot know how your code is used.

Is my code sent to a server?

Your source is processed in the page and is not uploaded. The page does fetch its own formatting code from the site the first time you press Calculate, so it needs a connection then. After that, nothing about your text leaves the tab.

Hvordan bruker du JavaScript-formaterer?

Lim inn JavaScript og velg formatering eller minifisering. Se gjennom parserfeil før du kopierer.

Lastes dataene mine opp til en server?

Nei. Behandlingen skjer i nettleseren din, og opplysningene dine lastes ikke opp.