svgo
- Version 4.0.0
- Published
- 1.45 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
Functions
Type Aliases
- BuiltinPlugin
- BuiltinPluginOrPreset
- BuiltinsWithOptionalParams
- BuiltinsWithRequiredParams
- ComputedStyles
- Config
- CustomPlugin
- DataUri
- DefaultPlugins
- DynamicStyle
- Output
- PathDataCommand
- PathDataItem
- Plugin
- PluginConfig
- PluginInfo
- PluginsParams
- PresetDefaultOverrides
- Specificity
- StaticStyle
- StringifyOptions
- Stylesheet
- StylesheetDeclaration
- StylesheetRule
- Visitor
- VisitorNode
- VisitorRoot
- XastCdata
- XastChild
- XastComment
- XastDoctype
- XastElement
- XastInstruction
- XastNode
- XastParent
- XastRoot
- XastText
Variables
variable builtinPlugins
const builtinPlugins: readonly ( | BuiltinPluginOrPreset<'cleanupAttrs', CleanupAttrsParams> | BuiltinPluginOrPreset<'cleanupEnableBackground', null> | BuiltinPluginOrPreset<'cleanupIds', CleanupIdsParams> | BuiltinPluginOrPreset<'cleanupNumericValues', CleanupNumericValuesParams> | BuiltinPluginOrPreset<'collapseGroups', null> | BuiltinPluginOrPreset<'convertColors', ConvertColorsParams> | BuiltinPluginOrPreset<'convertEllipseToCircle', null> | BuiltinPluginOrPreset<'convertPathData', ConvertPathDataParams> | BuiltinPluginOrPreset<'convertShapeToPath', ConvertShapeToPathParams> | BuiltinPluginOrPreset<'convertTransform', ConvertTransformParams> | BuiltinPluginOrPreset<'mergeStyles', null> | BuiltinPluginOrPreset<'inlineStyles', InlineStylesParams> | BuiltinPluginOrPreset<'mergePaths', MergePathsParams> | BuiltinPluginOrPreset<'minifyStyles', MinifyStylesParams> | BuiltinPluginOrPreset<'moveElemsAttrsToGroup', null> | BuiltinPluginOrPreset<'moveGroupAttrsToElems', null> | BuiltinPluginOrPreset<'removeComments', RemoveCommentsParams> | BuiltinPluginOrPreset<'removeDeprecatedAttrs', RemoveDeprecatedAttrsParams> | BuiltinPluginOrPreset<'removeDesc', RemoveDescParams> | BuiltinPluginOrPreset<'removeDoctype', null> | BuiltinPluginOrPreset<'removeEditorsNSData', RemoveEditorsNSDataParams> | BuiltinPluginOrPreset<'removeEmptyAttrs', null> | BuiltinPluginOrPreset<'removeEmptyContainers', null> | BuiltinPluginOrPreset<'removeEmptyText', RemoveEmptyTextParams> | BuiltinPluginOrPreset<'removeHiddenElems', RemoveHiddenElemsParams> | BuiltinPluginOrPreset<'removeMetadata', null> | BuiltinPluginOrPreset<'removeNonInheritableGroupAttrs', null> | BuiltinPluginOrPreset< 'removeUnknownsAndDefaults', RemoveUnknownsAndDefaultsParams > | BuiltinPluginOrPreset<'removeUnusedNS', null> | BuiltinPluginOrPreset<'removeUselessDefs', null> | BuiltinPluginOrPreset< 'removeUselessStrokeAndFill', RemoveUselessStrokeAndFillParams > | BuiltinPluginOrPreset<'removeXMLProcInst', null> | BuiltinPluginOrPreset<'sortAttrs', SortAttrsParams> | BuiltinPluginOrPreset<'sortDefsChildren', null> | BuiltinPluginOrPreset< 'preset-default', { floatPrecision?: number; overrides?: PresetDefaultOverrides } > | BuiltinPluginOrPreset<'cleanupListOfValues', CleanupListOfValuesParams> | BuiltinPluginOrPreset<'convertOneStopGradients', null> | BuiltinPluginOrPreset<'convertStyleToAttrs', ConvertStyleToAttrsParams> | BuiltinPluginOrPreset<'prefixIds', PrefixIdsParams> | BuiltinPluginOrPreset<'removeDimensions', null> | BuiltinPluginOrPreset<'removeOffCanvasPaths', null> | BuiltinPluginOrPreset<'removeRasterImages', null> | BuiltinPluginOrPreset<'removeScripts', null> | BuiltinPluginOrPreset<'removeStyleElement', null> | BuiltinPluginOrPreset<'removeTitle', null> | BuiltinPluginOrPreset<'removeViewBox', null> | BuiltinPluginOrPreset<'removeXlink', RemoveXlinkParams> | BuiltinPluginOrPreset<'removeXMLNS', null> | BuiltinPluginOrPreset<'reusePaths', null> | BuiltinPluginOrPreset< 'addAttributesToSVGElement', AddAttributesToSVGElementParams > | BuiltinPluginOrPreset<'addClassesToSVGElement', AddClassesToSVGElementParams> | BuiltinPluginOrPreset<'removeAttributesBySelector', any> | BuiltinPluginOrPreset<'removeAttrs', RemoveAttrsParams> | BuiltinPluginOrPreset<'removeElementsByAttr', RemoveElementsByAttrParams>)[];
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;
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;
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[];
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> & { /** If the plugin is itself a preset that invokes other plugins. */ isPreset?: true; /** * If the plugin is a preset that invokes other plugins, this returns an * array of the plugins in the preset in the order that they are invoked. */ plugins?: ReadonlyArray<BuiltinPlugin<string, Object>>;};
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: any; 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 (24)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto 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[](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>
- Updated .
Package analyzed in 3544 ms. - Missing or incorrect documentation? Open an issue for this package.