Installations
npm install svgo
Developer Guide
Typescript
Yes
Module System
CommonJS
Min. Node Version
>=14.0.0
Score
62.7
Supply Chain
99.6
Quality
84.7
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Languages
JavaScript (100%)
Developer
Download Statistics
Total Downloads
3,862,890,860
Last Day
2,121,267
Last Week
15,886,997
Last Month
72,566,518
Last Year
877,229,785
GitHub Statistics
21,146 Stars
1,539 Commits
1,390 Forks
242 Watching
5 Branches
203 Contributors
Bundle Size
562.98 kB
Minified
176.02 kB
Minified + Gzipped
Sponsor this package
Package Meta Information
Latest Version
3.3.2
Package Id
svgo@3.3.2
Unpacked Size
1.42 MB
Size
357.05 kB
File Count
79
Publised On
09 May 2024
Total Downloads
Cumulative downloads
Total Downloads
3,862,890,860
Last day
-33.3%
2,121,267
Compared to previous day
Last week
-10.3%
15,886,997
Compared to previous week
Last month
-4.2%
72,566,518
Compared to previous month
Last year
5.5%
877,229,785
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
SVGO
SVGO, short for SVG Optimizer, is a Node.js library and command-line application for optimizing SVG files.
Why?
SVG files, especially those exported from vector editors, usually contain a lot of redundant information. This includes editor metadata, comments, hidden elements, default or suboptimal values, and other stuff that can be safely removed or converted without impacting rendering.
Installation
You can install SVGO globally through npm, yarn, or pnpm. Alternatively, drop the global flag (global
/-g
) to use it in your Node.js project.
1# npm 2npm install -g svgo 3 4# yarn 5yarn global add svgo 6 7# pnpm 8pnpm add -g svgo
Command-line usage
Process single files:
1svgo one.svg two.svg -o one.min.svg two.min.svg
Process a directory of files recursively with -r
/--recursive
and -f
/--folder
:
1svgo -rf path/to/directory_with_svgs -o path/to/output_directory
Help for advanced usage:
1svgo --help
Configuration
SVGO has a plugin architecture. You can read more about all plugins in Plugins | SVGO Documentation, and the default plugins in Preset Default | SVGO Documentation.
SVGO reads the configuration from svgo.config.mjs
or the --config path/to/config.mjs
command-line option. Some other parameters can be configured though command-line options too.
svgo.config.mjs
1export default { 2 multipass: false, // boolean 3 datauri: 'base64', // 'base64'|'enc'|'unenc' 4 js2svg: { 5 indent: 4, // number 6 pretty: false, // boolean 7 }, 8 plugins: [ 9 'preset-default', // built-in plugins enabled by default 10 'prefixIds', // enable built-in plugins by name 11 12 // enable built-in plugins with an object to configure plugins 13 { 14 name: 'prefixIds', 15 params: { 16 prefix: 'uwu', 17 }, 18 }, 19 ], 20};
Default preset
Instead of configuring SVGO from scratch, you can tweak the default preset to suit your needs by configuring or disabling the respective plugin.
svgo.config.mjs
1export default { 2 plugins: [ 3 { 4 name: 'preset-default', 5 params: { 6 overrides: { 7 // disable a default plugin 8 cleanupIds: false, 9 10 // customize the params of a default plugin 11 inlineStyles: { 12 onlyMatchedOnce: false, 13 }, 14 }, 15 }, 16 }, 17 ], 18};
You can find a list of the default plugins in the order they run in Preset Default | SVGO Documentation.
Custom plugins
You can also specify custom plugins:
svgo.config.mjs
1import importedPlugin from './imported-plugin'; 2 3export default { 4 plugins: [ 5 // plugin imported from another JavaScript file 6 importedPlugin, 7 8 // plugin defined inline 9 { 10 name: 'customPlugin', 11 params: { 12 paramName: 'paramValue', 13 }, 14 fn: (ast, params, info) => {}, 15 }, 16 ], 17};
API usage
SVGO provides a few low level utilities.
optimize
The core of SVGO is optimize
function.
1import { optimize } from 'svgo'; 2 3const result = optimize(svgString, { 4 path: 'path-to.svg', // recommended 5 multipass: true, // all other config fields are available here 6}); 7 8const optimizedSvgString = result.data;
loadConfig
If you write a tool on top of SVGO you may want to resolve the svgo.config.mjs
file.
1import { loadConfig } from 'svgo'; 2 3const config = await loadConfig();
You can also specify a path and customize the current working directory.
1const config = await loadConfig(configFile, cwd);
Donors
SheetJS LLC | Fontello |
License and Copyright
This software is released under the terms of the MIT license.
Logo by André Castillo.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
security policy file detected
Details
- Info: security policy file detected: github.com/svg/.github/SECURITY.md:1
- Info: Found linked content: github.com/svg/.github/SECURITY.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/svg/.github/SECURITY.md:1
- Info: Found text in security policy: github.com/svg/.github/SECURITY.md:1
Reason
SAST tool is run on all commits
Details
- Info: SAST configuration detected: CodeQL
- Info: all commits (30) are checked with a SAST tool
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Info: jobLevel 'contents' permission set to 'read': .github/workflows/codeql.yml:20
- Info: jobLevel 'actions' permission set to 'read': .github/workflows/codeql.yml:19
- Warn: no topLevel permission defined: .github/workflows/codeql.yml:1
- Info: topLevel 'contents' permission set to 'read': .github/workflows/main.yml:13
- Info: no jobLevel write permissions found
Reason
3 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
Reason
3 commit(s) and 3 issue activity found in the last 90 days -- score normalized to 5
Reason
Found 13/30 approved changesets -- score normalized to 4
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/svg/svgo/codeql.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql.yml:30: update your workflow using https://app.stepsecurity.io/secureworkflow/svg/svgo/codeql.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql.yml:36: update your workflow using https://app.stepsecurity.io/secureworkflow/svg/svgo/codeql.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql.yml:39: update your workflow using https://app.stepsecurity.io/secureworkflow/svg/svgo/codeql.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/svg/svgo/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/svg/svgo/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:43: update your workflow using https://app.stepsecurity.io/secureworkflow/svg/svgo/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:44: update your workflow using https://app.stepsecurity.io/secureworkflow/svg/svgo/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:62: update your workflow using https://app.stepsecurity.io/secureworkflow/svg/svgo/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:63: update your workflow using https://app.stepsecurity.io/secureworkflow/svg/svgo/main.yml/main?enable=pin
- Info: 0 out of 10 GitHub-owned GitHubAction dependencies pinned
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
Project has not signed or included provenance with any releases.
Details
- Warn: release artifact v4.0.0-rc.1 not signed: https://api.github.com/repos/svg/svgo/releases/173981721
- Warn: release artifact v4.0.0-rc.0 not signed: https://api.github.com/repos/svg/svgo/releases/159386092
- Warn: release artifact v3.3.2 not signed: https://api.github.com/repos/svg/svgo/releases/154902380
- Warn: release artifact v3.3.1 not signed: https://api.github.com/repos/svg/svgo/releases/154860435
- Warn: release artifact v3.3.0 not signed: https://api.github.com/repos/svg/svgo/releases/153911434
- Warn: release artifact v4.0.0-rc.1 does not have provenance: https://api.github.com/repos/svg/svgo/releases/173981721
- Warn: release artifact v4.0.0-rc.0 does not have provenance: https://api.github.com/repos/svg/svgo/releases/159386092
- Warn: release artifact v3.3.2 does not have provenance: https://api.github.com/repos/svg/svgo/releases/154902380
- Warn: release artifact v3.3.1 does not have provenance: https://api.github.com/repos/svg/svgo/releases/154860435
- Warn: release artifact v3.3.0 does not have provenance: https://api.github.com/repos/svg/svgo/releases/153911434
Score
6.1
/10
Last Scanned on 2024-12-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More