terser

  • Version 5.47.1
  • Published
  • 2.29 MB
  • 4 dependencies
  • BSD-2-Clause license

Install

npm i terser
yarn add terser
pnpm add terser

Overview

JavaScript parser, mangler/compressor and beautifier toolkit for ES6+

Index

Functions

Interfaces

Enums

Type Aliases

Functions

function minify

minify: (
files: string | string[] | { [file: string]: string },
options?: MinifyOptions
) => Promise<MinifyOutput>;

    function minify_sync

    minify_sync: (
    files: string | string[] | { [file: string]: string },
    options?: MinifyOptions
    ) => MinifyOutput;

      Interfaces

      interface CompressOptions

      interface CompressOptions {}

        property arguments

        arguments?: boolean;

          property arrows

          arrows?: boolean;

            property booleans

            booleans?: boolean;

              property booleans_as_integers

              booleans_as_integers?: boolean;

                property builtins_ecma

                builtins_ecma?: ECMA;

                  property builtins_pure

                  builtins_pure?: boolean;

                    property collapse_vars

                    collapse_vars?: boolean;

                      property comparisons

                      comparisons?: boolean;

                        property computed_props

                        computed_props?: boolean;

                          property conditionals

                          conditionals?: boolean;

                            property dead_code

                            dead_code?: boolean;

                              property defaults

                              defaults?: boolean;

                                property directives

                                directives?: boolean;

                                  property drop_console

                                  drop_console?: DropConsoleOption;

                                    property drop_debugger

                                    drop_debugger?: boolean;

                                      property ecma

                                      ecma?: ECMA;

                                        property evaluate

                                        evaluate?: boolean;

                                          property expression

                                          expression?: boolean;

                                            property global_defs

                                            global_defs?: object;

                                              property hoist_funs

                                              hoist_funs?: boolean;

                                                property hoist_props

                                                hoist_props?: boolean;

                                                  property hoist_vars

                                                  hoist_vars?: boolean;

                                                    property ie8

                                                    ie8?: boolean;

                                                      property if_return

                                                      if_return?: boolean;

                                                        property inline

                                                        inline?: boolean | InlineFunctions;

                                                          property join_vars

                                                          join_vars?: boolean;

                                                            property keep_classnames

                                                            keep_classnames?: boolean | RegExp;

                                                              property keep_fargs

                                                              keep_fargs?: boolean;

                                                                property keep_fnames

                                                                keep_fnames?: boolean | RegExp;

                                                                  property keep_infinity

                                                                  keep_infinity?: boolean;

                                                                    property lhs_constants

                                                                    lhs_constants?: boolean;

                                                                      property loops

                                                                      loops?: boolean;

                                                                        property module

                                                                        module?: boolean;

                                                                          property negate_iife

                                                                          negate_iife?: boolean;

                                                                            property passes

                                                                            passes?: number;

                                                                              property properties

                                                                              properties?: boolean;

                                                                                property pure_funcs

                                                                                pure_funcs?: string[];

                                                                                  property pure_getters

                                                                                  pure_getters?: boolean | 'strict';

                                                                                    property pure_new

                                                                                    pure_new?: boolean;

                                                                                      property reduce_funcs

                                                                                      reduce_funcs?: boolean;

                                                                                        property reduce_vars

                                                                                        reduce_vars?: boolean;

                                                                                          property sequences

                                                                                          sequences?: boolean | number;

                                                                                            property side_effects

                                                                                            side_effects?: boolean;

                                                                                              property switches

                                                                                              switches?: boolean;

                                                                                                property top_retain

                                                                                                top_retain?: null | string | string[] | RegExp;

                                                                                                  property toplevel

                                                                                                  toplevel?: boolean;

                                                                                                    property typeofs

                                                                                                    typeofs?: boolean;

                                                                                                      property unsafe

                                                                                                      unsafe?: boolean;

                                                                                                        property unsafe_arrows

                                                                                                        unsafe_arrows?: boolean;

                                                                                                          property unsafe_comps

                                                                                                          unsafe_comps?: boolean;

                                                                                                            property unsafe_Function

                                                                                                            unsafe_Function?: boolean;

                                                                                                              property unsafe_math

                                                                                                              unsafe_math?: boolean;

                                                                                                                property unsafe_methods

                                                                                                                unsafe_methods?: boolean;

                                                                                                                  property unsafe_proto

                                                                                                                  unsafe_proto?: boolean;

                                                                                                                    property unsafe_regexp

                                                                                                                    unsafe_regexp?: boolean;

                                                                                                                      property unsafe_symbols

                                                                                                                      unsafe_symbols?: boolean;

                                                                                                                        property unsafe_undefined

                                                                                                                        unsafe_undefined?: boolean;

                                                                                                                          property unused

                                                                                                                          unused?: boolean;

                                                                                                                            interface FormatOptions

                                                                                                                            interface FormatOptions {}

                                                                                                                              property ascii_only

                                                                                                                              ascii_only?: boolean;

                                                                                                                                property beautify

                                                                                                                                beautify?: boolean;
                                                                                                                                • Deprecated

                                                                                                                                  Not implemented anymore

                                                                                                                                property braces

                                                                                                                                braces?: boolean;

                                                                                                                                  property comments

                                                                                                                                  comments?:
                                                                                                                                  | boolean
                                                                                                                                  | 'all'
                                                                                                                                  | 'some'
                                                                                                                                  | RegExp
                                                                                                                                  | ((
                                                                                                                                  node: any,
                                                                                                                                  comment: {
                                                                                                                                  value: string;
                                                                                                                                  type: 'comment1' | 'comment2' | 'comment3' | 'comment4';
                                                                                                                                  pos: number;
                                                                                                                                  line: number;
                                                                                                                                  col: number;
                                                                                                                                  }
                                                                                                                                  ) => boolean);

                                                                                                                                    property ecma

                                                                                                                                    ecma?: ECMA;

                                                                                                                                      property ie8

                                                                                                                                      ie8?: boolean;

                                                                                                                                        property indent_level

                                                                                                                                        indent_level?: number;

                                                                                                                                          property indent_start

                                                                                                                                          indent_start?: number;

                                                                                                                                            property inline_script

                                                                                                                                            inline_script?: boolean;

                                                                                                                                              property keep_numbers

                                                                                                                                              keep_numbers?: boolean;

                                                                                                                                                property keep_quoted_props

                                                                                                                                                keep_quoted_props?: boolean;

                                                                                                                                                  property max_line_len

                                                                                                                                                  max_line_len?: number | false;

                                                                                                                                                    property preamble

                                                                                                                                                    preamble?: string;

                                                                                                                                                      property preserve_annotations

                                                                                                                                                      preserve_annotations?: boolean;

                                                                                                                                                        property quote_keys

                                                                                                                                                        quote_keys?: boolean;

                                                                                                                                                          property quote_style

                                                                                                                                                          quote_style?: OutputQuoteStyle;

                                                                                                                                                            property safari10

                                                                                                                                                            safari10?: boolean;

                                                                                                                                                              property semicolons

                                                                                                                                                              semicolons?: boolean;

                                                                                                                                                                property shebang

                                                                                                                                                                shebang?: boolean;

                                                                                                                                                                  property shorthand

                                                                                                                                                                  shorthand?: boolean;

                                                                                                                                                                    property source_map

                                                                                                                                                                    source_map?: SourceMapOptions;

                                                                                                                                                                      property webkit

                                                                                                                                                                      webkit?: boolean;

                                                                                                                                                                        property width

                                                                                                                                                                        width?: number;

                                                                                                                                                                          property wrap_func_args

                                                                                                                                                                          wrap_func_args?: boolean;

                                                                                                                                                                            property wrap_iife

                                                                                                                                                                            wrap_iife?: boolean;

                                                                                                                                                                              interface MangleOptions

                                                                                                                                                                              interface MangleOptions {}

                                                                                                                                                                                property eval

                                                                                                                                                                                eval?: boolean;

                                                                                                                                                                                  property keep_classnames

                                                                                                                                                                                  keep_classnames?: boolean | RegExp;

                                                                                                                                                                                    property keep_fnames

                                                                                                                                                                                    keep_fnames?: boolean | RegExp;

                                                                                                                                                                                      property module

                                                                                                                                                                                      module?: boolean;

                                                                                                                                                                                        property nth_identifier

                                                                                                                                                                                        nth_identifier?: SimpleIdentifierMangler | WeightedIdentifierMangler;

                                                                                                                                                                                          property properties

                                                                                                                                                                                          properties?: boolean | ManglePropertiesOptions;

                                                                                                                                                                                            property reserved

                                                                                                                                                                                            reserved?: string[];

                                                                                                                                                                                              property safari10

                                                                                                                                                                                              safari10?: boolean;

                                                                                                                                                                                                property toplevel

                                                                                                                                                                                                toplevel?: boolean;

                                                                                                                                                                                                  interface ManglePropertiesOptions

                                                                                                                                                                                                  interface ManglePropertiesOptions {}

                                                                                                                                                                                                    property builtins

                                                                                                                                                                                                    builtins?: boolean;

                                                                                                                                                                                                      property debug

                                                                                                                                                                                                      debug?: boolean;

                                                                                                                                                                                                        property keep_quoted

                                                                                                                                                                                                        keep_quoted?: boolean | 'strict';

                                                                                                                                                                                                          property nth_identifier

                                                                                                                                                                                                          nth_identifier?: SimpleIdentifierMangler | WeightedIdentifierMangler;

                                                                                                                                                                                                            property regex

                                                                                                                                                                                                            regex?: RegExp | string;

                                                                                                                                                                                                              property reserved

                                                                                                                                                                                                              reserved?: string[];

                                                                                                                                                                                                                interface MinifyOptions

                                                                                                                                                                                                                interface MinifyOptions {}

                                                                                                                                                                                                                  property compress

                                                                                                                                                                                                                  compress?: boolean | CompressOptions;

                                                                                                                                                                                                                    property ecma

                                                                                                                                                                                                                    ecma?: ECMA;

                                                                                                                                                                                                                      property enclose

                                                                                                                                                                                                                      enclose?: boolean | string;

                                                                                                                                                                                                                        property format

                                                                                                                                                                                                                        format?: FormatOptions;

                                                                                                                                                                                                                          property ie8

                                                                                                                                                                                                                          ie8?: boolean;

                                                                                                                                                                                                                            property keep_classnames

                                                                                                                                                                                                                            keep_classnames?: boolean | RegExp;

                                                                                                                                                                                                                              property keep_fnames

                                                                                                                                                                                                                              keep_fnames?: boolean | RegExp;

                                                                                                                                                                                                                                property mangle

                                                                                                                                                                                                                                mangle?: boolean | MangleOptions;

                                                                                                                                                                                                                                  property module

                                                                                                                                                                                                                                  module?: boolean;

                                                                                                                                                                                                                                    property nameCache

                                                                                                                                                                                                                                    nameCache?: object;

                                                                                                                                                                                                                                      property output

                                                                                                                                                                                                                                      output?: FormatOptions;
                                                                                                                                                                                                                                      • Deprecated

                                                                                                                                                                                                                                      property parse

                                                                                                                                                                                                                                      parse?: ParseOptions;

                                                                                                                                                                                                                                        property safari10

                                                                                                                                                                                                                                        safari10?: boolean;

                                                                                                                                                                                                                                          property sourceMap

                                                                                                                                                                                                                                          sourceMap?: boolean | SourceMapOptions;

                                                                                                                                                                                                                                            property toplevel

                                                                                                                                                                                                                                            toplevel?: boolean;

                                                                                                                                                                                                                                              interface MinifyOutput

                                                                                                                                                                                                                                              interface MinifyOutput {}

                                                                                                                                                                                                                                                property code

                                                                                                                                                                                                                                                code?: string;

                                                                                                                                                                                                                                                  property decoded_map

                                                                                                                                                                                                                                                  decoded_map?: DecodedSourceMap | null;

                                                                                                                                                                                                                                                    property map

                                                                                                                                                                                                                                                    map?: EncodedSourceMap | string;

                                                                                                                                                                                                                                                      interface ParseOptions

                                                                                                                                                                                                                                                      interface ParseOptions {}

                                                                                                                                                                                                                                                        property bare_returns

                                                                                                                                                                                                                                                        bare_returns?: boolean;

                                                                                                                                                                                                                                                          property ecma

                                                                                                                                                                                                                                                          ecma?: ECMA;
                                                                                                                                                                                                                                                          • Deprecated

                                                                                                                                                                                                                                                            legacy option. Currently, all supported EcmaScript is valid to parse.

                                                                                                                                                                                                                                                          property html5_comments

                                                                                                                                                                                                                                                          html5_comments?: boolean;

                                                                                                                                                                                                                                                            property shebang

                                                                                                                                                                                                                                                            shebang?: boolean;

                                                                                                                                                                                                                                                              interface SimpleIdentifierMangler

                                                                                                                                                                                                                                                              interface SimpleIdentifierMangler {}
                                                                                                                                                                                                                                                              • An identifier mangler for which the output is invariant with respect to the source code.

                                                                                                                                                                                                                                                              method get

                                                                                                                                                                                                                                                              get: (n: number) => string;
                                                                                                                                                                                                                                                              • Obtains the nth most favored (usually shortest) identifier to rename a variable to. The mangler will increment n and retry until the return value is not in use in scope, and is not a reserved word. This function is expected to be stable; Evaluating get(n) === get(n) should always return true.

                                                                                                                                                                                                                                                                Parameter n

                                                                                                                                                                                                                                                                The ordinal of the identifier.

                                                                                                                                                                                                                                                              interface SourceMapOptions

                                                                                                                                                                                                                                                              interface SourceMapOptions {}

                                                                                                                                                                                                                                                                property asObject

                                                                                                                                                                                                                                                                asObject?: boolean;

                                                                                                                                                                                                                                                                  property content

                                                                                                                                                                                                                                                                  content?: SectionedSourceMapInput | string;
                                                                                                                                                                                                                                                                  • Source map object, 'inline' or source map file content

                                                                                                                                                                                                                                                                  property filename

                                                                                                                                                                                                                                                                  filename?: string;

                                                                                                                                                                                                                                                                    property includeSources

                                                                                                                                                                                                                                                                    includeSources?: boolean;

                                                                                                                                                                                                                                                                      property root

                                                                                                                                                                                                                                                                      root?: string;

                                                                                                                                                                                                                                                                        property url

                                                                                                                                                                                                                                                                        url?: string | 'inline';

                                                                                                                                                                                                                                                                          interface WeightedIdentifierMangler

                                                                                                                                                                                                                                                                          interface WeightedIdentifierMangler extends SimpleIdentifierMangler {}
                                                                                                                                                                                                                                                                          • An identifier mangler that leverages character frequency analysis to determine identifier precedence.

                                                                                                                                                                                                                                                                          method consider

                                                                                                                                                                                                                                                                          consider: (chars: string, delta: number) => number;
                                                                                                                                                                                                                                                                          • Modifies the internal weighting of the input characters by the specified delta. Will be invoked on the entire printed AST, and then deduct mangleable identifiers.

                                                                                                                                                                                                                                                                            Parameter chars

                                                                                                                                                                                                                                                                            The characters to modify the weighting of.

                                                                                                                                                                                                                                                                            Parameter delta

                                                                                                                                                                                                                                                                            The numeric weight to add to the characters.

                                                                                                                                                                                                                                                                          method reset

                                                                                                                                                                                                                                                                          reset: () => void;
                                                                                                                                                                                                                                                                          • Resets character weights.

                                                                                                                                                                                                                                                                          method sort

                                                                                                                                                                                                                                                                          sort: () => void;
                                                                                                                                                                                                                                                                          • Sorts identifiers by character frequency, in preparation for calls to get(n).

                                                                                                                                                                                                                                                                          Enums

                                                                                                                                                                                                                                                                          enum InlineFunctions

                                                                                                                                                                                                                                                                          enum InlineFunctions {
                                                                                                                                                                                                                                                                          Disabled = 0,
                                                                                                                                                                                                                                                                          SimpleFunctions = 1,
                                                                                                                                                                                                                                                                          WithArguments = 2,
                                                                                                                                                                                                                                                                          WithArgumentsAndVariables = 3,
                                                                                                                                                                                                                                                                          }

                                                                                                                                                                                                                                                                            member Disabled

                                                                                                                                                                                                                                                                            Disabled = 0

                                                                                                                                                                                                                                                                              member SimpleFunctions

                                                                                                                                                                                                                                                                              SimpleFunctions = 1

                                                                                                                                                                                                                                                                                member WithArguments

                                                                                                                                                                                                                                                                                WithArguments = 2

                                                                                                                                                                                                                                                                                  member WithArgumentsAndVariables

                                                                                                                                                                                                                                                                                  WithArgumentsAndVariables = 3

                                                                                                                                                                                                                                                                                    enum OutputQuoteStyle

                                                                                                                                                                                                                                                                                    enum OutputQuoteStyle {
                                                                                                                                                                                                                                                                                    PreferDouble = 0,
                                                                                                                                                                                                                                                                                    AlwaysSingle = 1,
                                                                                                                                                                                                                                                                                    AlwaysDouble = 2,
                                                                                                                                                                                                                                                                                    AlwaysOriginal = 3,
                                                                                                                                                                                                                                                                                    }

                                                                                                                                                                                                                                                                                      member AlwaysDouble

                                                                                                                                                                                                                                                                                      AlwaysDouble = 2

                                                                                                                                                                                                                                                                                        member AlwaysOriginal

                                                                                                                                                                                                                                                                                        AlwaysOriginal = 3

                                                                                                                                                                                                                                                                                          member AlwaysSingle

                                                                                                                                                                                                                                                                                          AlwaysSingle = 1

                                                                                                                                                                                                                                                                                            member PreferDouble

                                                                                                                                                                                                                                                                                            PreferDouble = 0

                                                                                                                                                                                                                                                                                              Type Aliases

                                                                                                                                                                                                                                                                                              type ConsoleProperty

                                                                                                                                                                                                                                                                                              type ConsoleProperty = keyof typeof console;

                                                                                                                                                                                                                                                                                                type DropConsoleOption

                                                                                                                                                                                                                                                                                                type DropConsoleOption = boolean | ConsoleProperty[];

                                                                                                                                                                                                                                                                                                  type ECMA

                                                                                                                                                                                                                                                                                                  type ECMA =
                                                                                                                                                                                                                                                                                                  | 5
                                                                                                                                                                                                                                                                                                  | 2015
                                                                                                                                                                                                                                                                                                  | 2016
                                                                                                                                                                                                                                                                                                  | 2017
                                                                                                                                                                                                                                                                                                  | 2018
                                                                                                                                                                                                                                                                                                  | 2019
                                                                                                                                                                                                                                                                                                  | 2020
                                                                                                                                                                                                                                                                                                  | 2021
                                                                                                                                                                                                                                                                                                  | 2022
                                                                                                                                                                                                                                                                                                  | 2023
                                                                                                                                                                                                                                                                                                  | 2024
                                                                                                                                                                                                                                                                                                  | 2025;

                                                                                                                                                                                                                                                                                                    Package Files (1)

                                                                                                                                                                                                                                                                                                    Dependencies (4)

                                                                                                                                                                                                                                                                                                    Dev Dependencies (10)

                                                                                                                                                                                                                                                                                                    Peer Dependencies (0)

                                                                                                                                                                                                                                                                                                    No peer dependencies.

                                                                                                                                                                                                                                                                                                    Badge

                                                                                                                                                                                                                                                                                                    To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                                                                                                                                                                                                                    You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/terser.

                                                                                                                                                                                                                                                                                                    • Markdown
                                                                                                                                                                                                                                                                                                      [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/terser)
                                                                                                                                                                                                                                                                                                    • HTML
                                                                                                                                                                                                                                                                                                      <a href="https://www.jsdocs.io/package/terser"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>