# multiple-svgs

> Convert multiple SVG's (as strings with co-ordinates) into one SVG. Making use of `` and ``

Latest version **1.2.0** (published 2023-04-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install multiple-svgs
pnpm add multiple-svgs
yarn add multiple-svgs
bun add multiple-svgs
```

## 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.2.0 |
| Published | 2023-04-26 |
| First published | 2022-05-19 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 23.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | edwilliams |

## Links

- npm: https://www.npmjs.com/package/multiple-svgs
- Repository: https://github.com/edwilliams/multiple-svgs
- Homepage: https://github.com/edwilliams/multiple-svgs#readme
- Issues: https://github.com/edwilliams/multiple-svgs/issues
- npm.io page: https://npm.io/package/multiple-svgs

## Dependencies (1)

- [js-beautify](https://npm.io/package/js-beautify.md) ^1.14.3

## Recent versions

- 1.2.0 (latest) — 2023-04-26
- 1.1.0 — 2022-09-16
- 1.0.2 — 2022-05-19
- 1.0.1 — 2022-05-19
- 1.0.0 — 2022-05-19

## README

# Multiple SVGs

[![npm](https://img.shields.io/npm/v/multiple-svgs.svg)](https://www.npmjs.com/package/multiple-svgs)

This library would be better called combine SVGs!

## Install

```
$ npm install multiple-svgs
```

## Getting Started

Pass in an array of objects to receive a combined SVG. For example

```json
[
  {
    "x": 0,
    "y": 0,
    "str": `<svg>...</svg>`
  },
  {
    "x": 100,
    "y": 0,
    "str": `<svg>...</svg>`
  }
]
```

## Full Usage

**input**

```javascript
const nested = multipleSvgs({
  width: 50,
  height: 50,
  svgs: [
    {
      x: 0,
      y: 0,
      str: `<svg width="25" height="50" xmlns="http://www.w3.org/2000/svg">
              <rect x="0" y="0" width="25" height="50" style="fill: blue;" />
            </svg>`,
    },
    {
      x: 25,
      y: 0,
      str: `<svg width="25" height="50" xmlns="http://www.w3.org/2000/svg">
              <rect width="25" height="50" style="fill: yellow;" />
            </svg>`,
    },
  ],
})

const demo = multipleSvgs({
  id: 'demo',
  defs: `<style type="text/css">svg { background: pink; }</style>`,
  width: 320,
  height: 640,
  svgs: [
    {
      x: 250,
      y: 10,
      str: nested, // multipleSvgs can be used recursively
    },
    {
      x: 10,
      y: 10,
      str: `<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg">
              <rect x="0" y="0" width="200" height="100" style="fill: red;" />
              <rect x="0" y="100" width="200" height="100" style="fill: orange;" />
            </svg>`,
    },
    {
      x: 10,
      y: 220,
      str: `<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg">
              <rect width="200" height="200" style="fill: yellow;" />
            </svg>`,
    },
    {
      x: 10,
      y: 430,
      str: `<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg">
              <rect width="200" height="200" style="fill: green;" />
            </svg>`,
    },
  ],
})
```

**output**

```html
<svg id="demo" width="320" height="640" xmlns="http://www.w3.org/2000/svg">
  <defs>
    <style type="text/css">
      svg {
        background: pink;
      }
    </style>
  </defs>
  <g width="50" height="50" transform="translate(250, 10)">
    <g width="25" height="50" transform="translate(0, 0)">
      <rect x="0" y="0" width="25" height="50" style="fill: blue;"></rect>
    </g>
    <g width="25" height="50" transform="translate(25, 0)">
      <rect width="25" height="50" style="fill: yellow;"></rect>
    </g>
  </g>
  <g width="200" height="200" transform="translate(10, 10)">
    <rect x="0" y="0" width="200" height="100" style="fill: red;"></rect>
    <rect x="0" y="100" width="200" height="100" style="fill: orange;"></rect>
  </g>
  <g width="200" height="200" transform="translate(10, 220)">
    <rect width="200" height="200" style="fill: yellow;"></rect>
  </g>
  <g width="200" height="200" transform="translate(10, 430)">
    <rect width="200" height="200" style="fill: green;"></rect>
  </g>
</svg>
```

## Notes

The `html2json` repo has issues bundling, hence an edited version has been included in the src of this repo

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