svgo

  • Version 4.1.0
  • Published
  • 1.49 MB
  • 7 dependencies
  • MIT license

Install

npm i svgo
yarn add svgo
pnpm add svgo

Overview

SVGO is a Node.js library and command-line application for optimizing vector images.

Index

Variables

variable builtinPlugins

const builtinPlugins: readonly (
| (BuiltinPlugin<'cleanupAttrs', CleanupAttrsParams> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<'cleanupEnableBackground', null> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<'cleanupIds', CleanupIdsParams> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<'cleanupNumericValues', CleanupNumericValuesParams> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<'collapseGroups', null> & Partial<PresetProperties<false>>)
| (BuiltinPlugin<'convertColors', ConvertColorsParams> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<'convertEllipseToCircle', null> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<'convertPathData', ConvertPathDataParams> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<'convertShapeToPath', ConvertShapeToPathParams> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<'convertTransform', ConvertTransformParams> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<'mergeStyles', null> & Partial<PresetProperties<false>>)
| (BuiltinPlugin<'inlineStyles', InlineStylesParams> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<'mergePaths', MergePathsParams> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<'minifyStyles', MinifyStylesParams> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<'moveElemsAttrsToGroup', null> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<'moveGroupAttrsToElems', null> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<'removeComments', RemoveCommentsParams> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<'removeDeprecatedAttrs', RemoveDeprecatedAttrsParams> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<'removeDesc', RemoveDescParams> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<'removeDoctype', null> & Partial<PresetProperties<false>>)
| (BuiltinPlugin<'removeEditorsNSData', RemoveEditorsNSDataParams> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<'removeEmptyAttrs', null> & Partial<PresetProperties<false>>)
| (BuiltinPlugin<'removeEmptyContainers', null> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<'removeEmptyText', RemoveEmptyTextParams> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<'removeHiddenElems', RemoveHiddenElemsParams> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<'removeMetadata', null> & Partial<PresetProperties<false>>)
| (BuiltinPlugin<'removeNonInheritableGroupAttrs', null> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<'removeUnknownsAndDefaults', RemoveUnknownsAndDefaultsParams> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<'removeUnusedNS', null> & Partial<PresetProperties<false>>)
| (BuiltinPlugin<'removeUselessDefs', null> & Partial<PresetProperties<false>>)
| (BuiltinPlugin<
'removeUselessStrokeAndFill',
RemoveUselessStrokeAndFillParams
> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<'removeXMLProcInst', null> & Partial<PresetProperties<false>>)
| (BuiltinPlugin<'sortAttrs', SortAttrsParams> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<'sortDefsChildren', null> & Partial<PresetProperties<false>>)
| (BuiltinPlugin<
'preset-default',
{ floatPrecision?: number; overrides?: PresetDefaultOverrides }
> &
PresetProperties<true>)
| (BuiltinPlugin<
'preset-default',
{ floatPrecision?: number; overrides?: PresetDefaultOverrides }
> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<'cleanupListOfValues', CleanupListOfValuesParams> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<'convertOneStopGradients', null> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<'convertStyleToAttrs', ConvertStyleToAttrsParams> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<'prefixIds', PrefixIdsParams> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<'removeDimensions', null> & Partial<PresetProperties<false>>)
| (BuiltinPlugin<'removeOffCanvasPaths', null> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<'removeRasterImages', null> & Partial<PresetProperties<false>>)
| (BuiltinPlugin<'removeScripts', null> & Partial<PresetProperties<false>>)
| (BuiltinPlugin<'removeStyleElement', null> & Partial<PresetProperties<false>>)
| (BuiltinPlugin<'removeTitle', null> & Partial<PresetProperties<false>>)
| (BuiltinPlugin<'removeViewBox', null> & Partial<PresetProperties<false>>)
| (BuiltinPlugin<'removeXlink', RemoveXlinkParams> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<'removeXMLNS', null> & Partial<PresetProperties<false>>)
| (BuiltinPlugin<'reusePaths', null> & Partial<PresetProperties<false>>)
| (BuiltinPlugin<'addAttributesToSVGElement', AddAttributesToSVGElementParams> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<'addClassesToSVGElement', AddClassesToSVGElementParams> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<
'removeAttributesBySelector',
RemoveAttributesBySelectorParams
> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<'removeAttrs', RemoveAttrsParams> &
Partial<PresetProperties<false>>)
| (BuiltinPlugin<'removeElementsByAttr', RemoveElementsByAttrParams> &
Partial<PresetProperties<false>>)
)[];
  • Plugins that are bundled with SVGO. This includes plugin presets, and plugins that are not enabled by default.

    {ReadonlyArray<{[Name in keyof import('./types.js').PluginsParams]: import('./types.js').BuiltinPluginOrPreset<Name, import('./types.js').PluginsParams[Name]>;}[keyof import('./types.js').PluginsParams]>}

variable VERSION

const VERSION: string;
  • Version of SVGO.

    {string} 4.0.0

Functions

function loadConfig

loadConfig: <T extends string>(
configFile?: T,
cwd?: string
) => Promise<T extends string ? Config : Config>;
  • If you write a tool on top of svgo you might need a way to load svgo config. You can also specify relative or absolute path and customize current working directory.

    {<T extends string | null>(configFile?: T, cwd?: string) => Promise<T extends string ? import('./svgo.js').Config : import('./svgo.js').Config | null>}

function mapNodesToParents

mapNodesToParents: (
node: import('../types.js').XastParent
) => Map<import('../types.js').XastNode, import('../types.js').XastParent>;
  • Maps all nodes to their parent node recursively.

    Parameter node

    Returns

    {Map<import('../types.js').XastNode, import('../types.js').XastParent>}

function optimize

optimize: (
input: string,
config?: import('./svgo.js').Config | undefined
) => import('./svgo.js').Output;
  • The core of SVGO.

    Parameter input

    Parameter config

    Returns

    {import('./svgo.js').Output}

function querySelector

querySelector: (
node: import('./types.js').XastParent,
selector: string,
parents?:
| Map<import('./types.js').XastNode, import('./types.js').XastParent>
| undefined
) => import('./types.js').XastChild | null;
  • Parameter node

    Element to query the children of.

    Parameter selector

    CSS selector string.

    Parameter parents

    Returns

    {?import('./types.js').XastChild} First match, or null if there was no match.

function querySelectorAll

querySelectorAll: (
node: import('./types.js').XastParent,
selector: string,
parents?:
| Map<import('./types.js').XastNode, import('./types.js').XastParent>
| undefined
) => import('./types.js').XastChild[];
  • Parameter node

    Element to query the children of.

    Parameter selector

    CSS selector string.

    Parameter parents

    Returns

    {import('./types.js').XastChild[]} All matching elements.

Type Aliases

type BuiltinPlugin

type BuiltinPlugin<Name extends string, Params> = {
/** Name of the plugin, also known as the plugin ID. */
name: Name;
description?: string;
fn: Plugin<Params>;
};

    type BuiltinPluginOrPreset

    type BuiltinPluginOrPreset<Name extends string, Params> = BuiltinPlugin<
    Name,
    Params
    > &
    (PresetProperties<true> | Partial<PresetProperties<false>>);

      type BuiltinsWithOptionalParams

      type BuiltinsWithOptionalParams = DefaultPlugins & {
      'preset-default': {
      floatPrecision?: number;
      /**
      * All default plugins can be customized or disabled here
      * for example
      * {
      * sortAttrs: { xmlnsOrder: "alphabetical" },
      * cleanupAttrs: false,
      * }
      */
      overrides?: PresetDefaultOverrides;
      };
      cleanupListOfValues: CleanupListOfValuesParams;
      convertOneStopGradients: null;
      convertStyleToAttrs: ConvertStyleToAttrsParams;
      prefixIds: PrefixIdsParams;
      removeDimensions: null;
      removeOffCanvasPaths: null;
      removeRasterImages: null;
      removeScripts: null;
      removeStyleElement: null;
      removeTitle: null;
      removeViewBox: null;
      removeXlink: RemoveXlinkParams;
      removeXMLNS: null;
      reusePaths: null;
      };

        type BuiltinsWithRequiredParams

        type BuiltinsWithRequiredParams = {
        addAttributesToSVGElement: AddAttributesToSVGElementParams;
        addClassesToSVGElement: AddClassesToSVGElementParams;
        removeAttributesBySelector: RemoveAttributesBySelectorParams;
        removeAttrs: RemoveAttrsParams;
        removeElementsByAttr: RemoveElementsByAttrParams;
        };

          type ComputedStyles

          type ComputedStyles = Record<string, StaticStyle | DynamicStyle>;

            type Config

            type Config = {
            /** Can be used by plugins, for example prefixIds. */
            path?: string;
            /** Pass over SVGs multiple times to ensure all optimizations are applied. */
            multipass?: boolean;
            /**
            * Precision of floating point numbers. Will be passed to each plugin that
            * supports this param.
            */
            floatPrecision?: number;
            /**
            * Plugins configuration. By default SVGO uses `preset-default`, but may
            * contain builtin or custom plugins.
            */
            plugins?: PluginConfig[];
            /** Options for rendering optimized SVG from AST. */
            js2svg?: StringifyOptions;
            /** Output as Data URI string. */
            datauri?: DataUri;
            };

              type CustomPlugin

              type CustomPlugin<T = any> = {
              name: string;
              fn: Plugin<T>;
              params?: T;
              };

                type DataUri

                type DataUri = 'base64' | 'enc' | 'unenc';

                  type DefaultPlugins

                  type DefaultPlugins = {
                  cleanupAttrs: CleanupAttrsParams;
                  cleanupEnableBackground: null;
                  cleanupIds: CleanupIdsParams;
                  cleanupNumericValues: CleanupNumericValuesParams;
                  collapseGroups: null;
                  convertColors: ConvertColorsParams;
                  convertEllipseToCircle: null;
                  convertPathData: ConvertPathDataParams;
                  convertShapeToPath: ConvertShapeToPathParams;
                  convertTransform: ConvertTransformParams;
                  mergeStyles: null;
                  inlineStyles: InlineStylesParams;
                  mergePaths: MergePathsParams;
                  minifyStyles: MinifyStylesParams;
                  moveElemsAttrsToGroup: null;
                  moveGroupAttrsToElems: null;
                  removeComments: RemoveCommentsParams;
                  removeDeprecatedAttrs: RemoveDeprecatedAttrsParams;
                  removeDesc: RemoveDescParams;
                  removeDoctype: null;
                  removeEditorsNSData: RemoveEditorsNSDataParams;
                  removeEmptyAttrs: null;
                  removeEmptyContainers: null;
                  removeEmptyText: RemoveEmptyTextParams;
                  removeHiddenElems: RemoveHiddenElemsParams;
                  removeMetadata: null;
                  removeNonInheritableGroupAttrs: null;
                  removeUnknownsAndDefaults: RemoveUnknownsAndDefaultsParams;
                  removeUnusedNS: null;
                  removeUselessDefs: null;
                  removeUselessStrokeAndFill: RemoveUselessStrokeAndFillParams;
                  removeXMLProcInst: null;
                  sortAttrs: SortAttrsParams;
                  sortDefsChildren: null;
                  };

                    type DynamicStyle

                    type DynamicStyle = {
                    type: 'dynamic';
                    inherited: boolean;
                    };

                      type Output

                      type Output = {
                      data: string;
                      };

                        type PathDataCommand

                        type PathDataCommand =
                        | 'M'
                        | 'm'
                        | 'Z'
                        | 'z'
                        | 'L'
                        | 'l'
                        | 'H'
                        | 'h'
                        | 'V'
                        | 'v'
                        | 'C'
                        | 'c'
                        | 'S'
                        | 's'
                        | 'Q'
                        | 'q'
                        | 'T'
                        | 't'
                        | 'A'
                        | 'a';

                          type PathDataItem

                          type PathDataItem = {
                          command: PathDataCommand;
                          args: number[];
                          };

                            type Plugin

                            type Plugin<P = null> = (
                            root: XastRoot,
                            params: P,
                            info: PluginInfo
                            ) => Visitor | null | void;

                              type PluginConfig

                              type PluginConfig =
                              | keyof BuiltinsWithOptionalParams
                              | {
                              [Name in keyof BuiltinsWithOptionalParams]: {
                              name: Name;
                              params?: BuiltinsWithOptionalParams[Name];
                              };
                              }[keyof BuiltinsWithOptionalParams]
                              | {
                              [Name in keyof BuiltinsWithRequiredParams]: {
                              name: Name;
                              params: BuiltinsWithRequiredParams[Name];
                              };
                              }[keyof BuiltinsWithRequiredParams]
                              | CustomPlugin;

                                type PluginInfo

                                type PluginInfo = {
                                path?: string;
                                multipassCount: number;
                                };

                                  type PluginsParams

                                  type PluginsParams = BuiltinsWithOptionalParams & BuiltinsWithRequiredParams;

                                    type PresetDefaultOverrides

                                    type PresetDefaultOverrides = {
                                    [Name in keyof DefaultPlugins]?: DefaultPlugins[Name] | false;
                                    };

                                      type Specificity

                                      type Specificity = [number, number, number];

                                        type StaticStyle

                                        type StaticStyle = {
                                        type: 'static';
                                        inherited: boolean;
                                        value: string;
                                        };

                                          type StringifyOptions

                                          type StringifyOptions = {
                                          doctypeStart?: string;
                                          doctypeEnd?: string;
                                          procInstStart?: string;
                                          procInstEnd?: string;
                                          tagOpenStart?: string;
                                          tagOpenEnd?: string;
                                          tagCloseStart?: string;
                                          tagCloseEnd?: string;
                                          tagShortStart?: string;
                                          tagShortEnd?: string;
                                          attrStart?: string;
                                          attrEnd?: string;
                                          commentStart?: string;
                                          commentEnd?: string;
                                          cdataStart?: string;
                                          cdataEnd?: string;
                                          textStart?: string;
                                          textEnd?: string;
                                          indent?: number | string;
                                          regEntities?: RegExp;
                                          regValEntities?: RegExp;
                                          encodeEntity?: (char: string) => string;
                                          pretty?: boolean;
                                          useShortTags?: boolean;
                                          eol?: 'lf' | 'crlf';
                                          finalNewline?: boolean;
                                          };

                                            type Stylesheet

                                            type Stylesheet = {
                                            rules: StylesheetRule[];
                                            parents: Map<XastElement, XastParent>;
                                            };

                                              type StylesheetDeclaration

                                              type StylesheetDeclaration = {
                                              name: string;
                                              value: string;
                                              important: boolean;
                                              };

                                                type StylesheetRule

                                                type StylesheetRule = {
                                                dynamic: boolean;
                                                selector: string;
                                                specificity: Specificity;
                                                declarations: StylesheetDeclaration[];
                                                };

                                                  type Visitor

                                                  type Visitor = {
                                                  doctype?: VisitorNode<XastDoctype>;
                                                  instruction?: VisitorNode<XastInstruction>;
                                                  comment?: VisitorNode<XastComment>;
                                                  cdata?: VisitorNode<XastCdata>;
                                                  text?: VisitorNode<XastText>;
                                                  element?: VisitorNode<XastElement>;
                                                  root?: VisitorRoot;
                                                  };

                                                    type VisitorNode

                                                    type VisitorNode<Node> = {
                                                    enter?: (node: Node, parentNode: XastParent) => void | symbol;
                                                    exit?: (node: Node, parentNode: XastParent) => void;
                                                    };

                                                      type VisitorRoot

                                                      type VisitorRoot = {
                                                      enter?: (node: XastRoot, parentNode: null) => void;
                                                      exit?: (node: XastRoot, parentNode: null) => void;
                                                      };

                                                        type XastCdata

                                                        type XastCdata = {
                                                        type: 'cdata';
                                                        value: string;
                                                        };

                                                          type XastChild

                                                          type XastChild =
                                                          | XastDoctype
                                                          | XastInstruction
                                                          | XastComment
                                                          | XastCdata
                                                          | XastText
                                                          | XastElement;

                                                            type XastComment

                                                            type XastComment = {
                                                            type: 'comment';
                                                            value: string;
                                                            };

                                                              type XastDoctype

                                                              type XastDoctype = {
                                                              type: 'doctype';
                                                              name: string;
                                                              data: {
                                                              doctype: string;
                                                              };
                                                              };

                                                                type XastElement

                                                                type XastElement = {
                                                                type: 'element';
                                                                name: string;
                                                                attributes: Record<string, string>;
                                                                children: XastChild[];
                                                                };

                                                                  type XastInstruction

                                                                  type XastInstruction = {
                                                                  type: 'instruction';
                                                                  name: string;
                                                                  value: string;
                                                                  };

                                                                    type XastNode

                                                                    type XastNode = XastRoot | XastChild;

                                                                      type XastParent

                                                                      type XastParent = XastRoot | XastElement;

                                                                        type XastRoot

                                                                        type XastRoot = {
                                                                        type: 'root';
                                                                        children: XastChild[];
                                                                        };

                                                                          type XastText

                                                                          type XastText = {
                                                                          type: 'text';
                                                                          value: string;
                                                                          };

                                                                            Package Files (6)

                                                                            Dependencies (7)

                                                                            Dev Dependencies (23)

                                                                            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/svgo.

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