# svgo-browser

> svgo tool for browser and node usage

Latest version **1.3.8** (published 2020-10-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install svgo-browser
pnpm add svgo-browser
yarn add svgo-browser
bun add svgo-browser
```

Provides the command `svgo`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.8 |
| Published | 2020-10-23 |
| First published | 2020-08-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4.0.0 |
| Dependencies | 12 |
| Unpacked size | 333.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 25 |
| Author | Kir Belevich |
| Maintainers | rtivital |
| Keywords | svgo, svg, optimize, minify |

## Links

- npm: https://www.npmjs.com/package/svgo-browser
- Repository: https://github.com/rtivital/svgo-browser
- Issues: https://github.com/rtivital/svgo-browser/issues
- npm.io page: https://npm.io/package/svgo-browser

## Dependencies (12)

- [coa](https://npm.io/package/coa.md) ^2.0.2
- [sax](https://npm.io/package/sax.md) ~1.2.4
- [csso](https://npm.io/package/csso.md) ^4.0.2
- [chalk](https://npm.io/package/chalk.md) ^2.4.1
- [mkdirp](https://npm.io/package/mkdirp.md) ~0.5.1
- [stable](https://npm.io/package/stable.md) ^0.1.8
- [js-yaml](https://npm.io/package/js-yaml.md) ^3.13.1
- [unquote](https://npm.io/package/unquote.md) ~1.1.1
- [css-tree](https://npm.io/package/css-tree.md) 1.0.0-alpha.37
- [css-select](https://npm.io/package/css-select.md) ^2.0.0
- [util.promisify](https://npm.io/package/util.promisify.md) ~1.0.0
- [css-select-base-adapter](https://npm.io/package/css-select-base-adapter.md) ^0.1.1

## Recent versions

- 1.3.8 (latest) — 2020-10-23
- 1.3.7 — 2020-08-13
- 1.3.6 — 2020-08-13
- 1.3.5 — 2020-08-13
- 1.3.4 — 2020-08-13
- 1.3.3 — 2020-08-13
- 1.3.2 — 2020-08-12

## README

# SVGO Browser

This package is fork of original svgo tool and focused on two things:

- providing support for browser usage
- better svgo api for node.js interface

This readme includes documentation only for changes and does not cover original features. To get more information about svgo please refer to [original repository](https://github.com/svg/svgo)

## Installation

```
npm install svgo-browser

yarn add svgo-browser
```

## Usage

svgo-browser can be used as is with node, but only with build tools (webpack, rollup, parcel, .etc) in browser as it uses node require syntax under the hood. Package includes everything from original svgo plus some extra helpers that can be imported separately.

### Usage with build tool

Was tested to work properly with webpack

```js
// Test data will be used in all examples to illustrate output
const testData = `
  <svg version="1.1" width="10" height="20">
      test
  </svg>
`;
```

**Optimize with all default configuration:**

```js
import optimize from 'svgo-browser/lib/optimize';

optimize(testData).then(console.log); // -> <svg viewBox="0 0 10 20">test</svg>
```

**Get separate instance:**

```js
import getSvgoInstance from 'svgo-browser/lib/get-svgo-instance';

const svgo = getSvgoInstance();
svgo.optimize(testData).then(console.log); // -> { data: "<svg viewBox="0 0 10 20">test</svg>", info: {}}
```

**Provide plugins to svgo instance:**

```js
import getSvgoInstance from 'svgo-browser/lib/get-svgo-instance';

// everything included in default configuration
const svgo = getSvgoInstance({
  cleanupAttrs: true,
  removeDoctype: true,
  removeXMLProcInst: true,
  removeComments: true,
  removeMetadata: true,
  removeTitle: true,
  removeDesc: true,
  removeUselessDefs: true,
  removeEditorsNSData: true,
  removeEmptyAttrs: true,
  removeHiddenElems: true,
  removeEmptyText: true,
  removeEmptyContainers: true,
  removeViewBox: false,
  cleanupEnableBackground: true,
  convertStyleToAttrs: true,
  convertColors: true,
  convertPathData: true,
  convertTransform: true,
  removeUnknownsAndDefaults: true,
  removeNonInheritableGroupAttrs: true,
  removeUselessStrokeAndFill: true,
  removeUnusedNS: true,
  cleanupIDs: true,
  cleanupNumericValues: true,
  moveElemsAttrsToGroup: true,
  moveGroupAttrsToElems: true,
  collapseGroups: true,
  removeRasterImages: false,
  mergePaths: true,
  convertShapeToPath: true,
  sortAttrs: true,
  removeDimensions: true,
  removeAttrs: {
    attrs: '(stroke|fill)',
  },
});

svgo.optimize(testData).then(console.log); // -> <svg viewBox="0 0 10 20">test</svg>
```

---
_Source: https://npm.io/package/svgo-browser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
