Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions .github/workflows/build.yml

This file was deleted.

22 changes: 0 additions & 22 deletions .nowignore

This file was deleted.

8 changes: 0 additions & 8 deletions .travis.yml

This file was deleted.

54 changes: 0 additions & 54 deletions CHANGELOG.md

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020-Present Atanas Atanasov
Copyright (c) 2021-Present Atanas Atanasov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
105 changes: 65 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<img src="https://raw.githubusercontent.com/scriptex/initial-commit/master/initial-commit.svg" alt="Initial commit Logo" width="200" />
# SVGO Add viewBox [![npm][npm-version-img]][npm-version-url] [![MIT license][license-img]][license-url] [![Twitter][twitter-img]][twitter-url] [![Analytics][analytics-img]][analytics-url]

# Initial Commit [![npm][npm-version-img]][npm-version-url] [![MIT license][license-img]][license-url] [![Twitter][twitter-img]][twitter-url] [![Analytics][analytics-img]][analytics-url]

> A starter template for a git repository.
> An SVGO plugin to add `viewBox` attribute based on `width` and `height` attributes

[![All issues on Github][github-issues-img]][github-issues-url]
[![Open issues on Github][github-open-issues-img]][github-open-issues-url]
Expand All @@ -23,14 +21,41 @@
[![Renovate App Status][renovateapp-img]][renovateapp-url]
[![Make A Pull Request][prs-welcome-img]][prs-welcome-url]

Use this when creating a NPM package, static website, or any other repository in a git environment
This plugin adds the `viewBox` attribute to your SVGs based on the `width` and `height` attributes. The difference between this plugin and the built-in [`removeDimensions`](https://github.com/svg/svgo/blob/master/plugins/removeDimensions.js) plugin is that `svgo-add-viewbox` does not remove the `width` and `height` of your SVGs.

In order to use this plugin correctly, you SVGs should have their `width` and `height` attributes specified.

## Usage

1. Clone this repository
2. Modify relevant files
3. Push to your new repository location
4. Profit
**This plugin should be used with SVGO v2 and above.**

1. Create a `svgo.config.js` file following the [official configuration guide](https://github.com/svg/svgo#configuration)
2. Use the option to specify a custom plugin.
3. Install this module from NPM
```sh
npm install svgo-add-viewbox --save-dev
# or
yarn add svgo-add-viewbox -D
```
4. `require` the module which you just created in your `svgo.config.js` file:
```javascript
const addViewBox = require('svgo-add-viewbox');
```
5. In the `plugins` array in your `svgo.config.js` file add the following:
```javascript
plugins: [
// ... more plugins
{
fn: addViewBox.fn,
name: 'addViewBox',
type: addViewBox.type,
active: addViewBox.active,
description: addViewBox.description
}
// ... more plugins
];
```
6. Execute your SVG transformation NPM script.

## Support this project

Expand All @@ -45,33 +70,33 @@ Use this when creating a NPM package, static website, or any other repository in

[MIT][license-url]

[npm-version-img]: https://badgen.net/npm/v/webpack-mpa?icon=npm
[npm-version-url]: https://www.npmjs.com/package/webpack-mpa
[license-img]: https://badgen.net/npm/license/webpack-mpa
[license-url]: https://github.com/scriptex/webpack-mpa/blob/master/LICENSE
[npm-version-img]: https://badgen.net/npm/v/svgo-add-viewbox?icon=npm
[npm-version-url]: https://www.npmjs.com/package/svgo-add-viewbox
[license-img]: https://badgen.net/npm/license/svgo-add-viewbox
[license-url]: https://github.com/scriptex/svgo-add-viewbox/blob/master/LICENSE
[twitter-url]: https://twitter.com/scriptexbg
[twitter-img]: https://badgen.net/twitter/follow/scriptexbg?icon=twitter&color=1da1f2&cache=300
[github-tag-img]: https://badgen.net/github/tag/scriptex/webpack-mpa?icon=github
[github-tag-url]: https://github.com/scriptex/webpack-mpa/releases/latest
[github-checks-img]: https://badgen.net/github/checks/scriptex/webpack-mpa?icon=github
[github-checks-url]: https://github.com/scriptex/webpack-mpa
[github-issues-img]: https://badgen.net/github/issues/scriptex/webpack-mpa?icon=github
[github-issues-url]: https://github.com/scriptex/webpack-mpa/issues
[github-open-issues-img]: https://badgen.net/github/open-issues/scriptex/webpack-mpa?icon=github
[github-open-issues-url]: https://github.com/scriptex/webpack-mpa/issues?q=is%3Aopen+is%3Aissue
[github-closed-issues-img]: https://badgen.net/github/closed-issues/scriptex/webpack-mpa?icon=github
[github-closed-issues-url]: https://github.com/scriptex/webpack-mpa/issues?q=is%3Aissue+is%3Aclosed
[last-commit-img]: https://badgen.net/github/last-commit/scriptex/webpack-mpa?icon=github
[last-commit-url]: https://github.com/scriptex/webpack-mpa/commits/master
[analytics-img]: https://ga-beacon.appspot.com/UA-83446952-1/github.com/scriptex/webpack-mpa/README.md
[analytics-url]: https://github.com/scriptex/webpack-mpa/
[npm-downloads-weekly-img]: https://badgen.net/npm/dw/webpack-mpa?icon=npm
[npm-downloads-monthly-img]: https://badgen.net/npm/dm/webpack-mpa?icon=npm
[npm-downloads-yearly-img]: https://badgen.net/npm/dy/webpack-mpa?icon=npm
[npm-downloads-total-img]: https://badgen.net/npm/dt/webpack-mpa?icon=npm
[npm-url]: https://www.npmjs.com/package/webpack-mpa
[github-tag-img]: https://badgen.net/github/tag/scriptex/svgo-add-viewbox?icon=github
[github-tag-url]: https://github.com/scriptex/svgo-add-viewbox/releases/latest
[github-checks-img]: https://badgen.net/github/checks/scriptex/svgo-add-viewbox?icon=github
[github-checks-url]: https://github.com/scriptex/svgo-add-viewbox
[github-issues-img]: https://badgen.net/github/issues/scriptex/svgo-add-viewbox?icon=github
[github-issues-url]: https://github.com/scriptex/svgo-add-viewbox/issues
[github-open-issues-img]: https://badgen.net/github/open-issues/scriptex/svgo-add-viewbox?icon=github
[github-open-issues-url]: https://github.com/scriptex/svgo-add-viewbox/issues?q=is%3Aopen+is%3Aissue
[github-closed-issues-img]: https://badgen.net/github/closed-issues/scriptex/svgo-add-viewbox?icon=github
[github-closed-issues-url]: https://github.com/scriptex/svgo-add-viewbox/issues?q=is%3Aissue+is%3Aclosed
[last-commit-img]: https://badgen.net/github/last-commit/scriptex/svgo-add-viewbox?icon=github
[last-commit-url]: https://github.com/scriptex/svgo-add-viewbox/commits/master
[analytics-img]: https://ga-beacon.appspot.com/UA-83446952-1/github.com/scriptex/svgo-add-viewbox/README.md
[analytics-url]: https://github.com/scriptex/svgo-add-viewbox/
[npm-downloads-weekly-img]: https://badgen.net/npm/dw/svgo-add-viewbox?icon=npm
[npm-downloads-monthly-img]: https://badgen.net/npm/dm/svgo-add-viewbox?icon=npm
[npm-downloads-yearly-img]: https://badgen.net/npm/dy/svgo-add-viewbox?icon=npm
[npm-downloads-total-img]: https://badgen.net/npm/dt/svgo-add-viewbox?icon=npm
[npm-url]: https://www.npmjs.com/package/svgo-add-viewbox
[tweet-img]: https://img.shields.io/badge/Tweet-Share_this_repository-blue.svg?style=flat-square&logo=twitter&color=38A1F3
[tweet-url]: https://twitter.com/intent/tweet?text=Checkout%20this%20awesome%20software%20project%3A&url=https%3A%2F%2Fgithub.com%2Fscriptex%2Fwebpack-mpa&via=scriptexbg&hashtags=software%2Cgithub%2Ccode%2Cawesome
[tweet-url]: https://twitter.com/intent/tweet?text=Checkout%20this%20awesome%20software%20project%3A&url=https%3A%2F%2Fgithub.com%2Fscriptex%2Fsvgo-add-viewbox&via=scriptexbg&hashtags=software%2Cgithub%2Ccode%2Cawesome
[paypal-img]: https://img.shields.io/badge/Donate-Support_me_on_PayPal-blue.svg?style=flat-square&logo=paypal&color=222d65
[paypal-url]: https://www.paypal.me/scriptex
[patreon-img]: https://img.shields.io/badge/Become_Patron-Support_me_on_Patreon-blue.svg?style=flat-square&logo=patreon&color=e64413
Expand All @@ -81,13 +106,13 @@ Use this when creating a NPM package, static website, or any other repository in
[liberapay-img]: https://img.shields.io/liberapay/receives/scriptex.svg?logo=liberapay
[liberapay-url]: https://liberapay.com/scriptex
[issuehunt-img]: https://raw.githubusercontent.com/BoostIO/issuehunt-materials/master/v1/issuehunt-shield-v1.svg
[issuehunt-url]: https://issuehunt.io/r/scriptex/webpack-mpa
[publish-size-img]: https://badgen.net/packagephobia/publish/webpack-mpa
[issuehunt-url]: https://issuehunt.io/r/scriptex/svgo-add-viewbox
[publish-size-img]: https://badgen.net/packagephobia/publish/svgo-add-viewbox
[renovateapp-img]: https://badgen.net/badge/renovate/enabled/green?cache=300
[renovateapp-url]: https://renovatebot.com
[prs-welcome-img]: https://badgen.net/badge/PRs/welcome/green?cache=300
[prs-welcome-url]: https://github.com/scriptex/webpack-mpa/pulls
[github-status-img]: https://badgen.net/github/status/scriptex/webpack-mpa?icon=github
[github-status-url]: https://github.com/scriptex/webpack-mpa/actions/workflows/build.yml
[github-languages-img]: https://img.shields.io/github/languages/count/scriptex/webpack-mpa
[github-top-language-img]: https://img.shields.io/github/languages/top/scriptex/webpack-mpa
[prs-welcome-url]: https://github.com/scriptex/svgo-add-viewbox/pulls
[github-status-img]: https://badgen.net/github/status/scriptex/svgo-add-viewbox?icon=github
[github-status-url]: https://github.com/scriptex/svgo-add-viewbox/actions/workflows/build.yml
[github-languages-img]: https://img.shields.io/github/languages/count/scriptex/svgo-add-viewbox
[github-top-language-img]: https://img.shields.io/github/languages/top/scriptex/svgo-add-viewbox
32 changes: 16 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ exports.description = 'Adds viewBox attribute based on width and height';
* @author Atanas Atanasov
*/
exports.fn = function (item) {
const {
name,
type,
attributes: { width, height, viewBox },
} = item;
const {
name,
type,
attributes: { width, height, viewBox }
} = item;

if (
name === 'svg' &&
type === 'element' &&
width != null &&
height != null &&
viewBox == null &&
Number.isNaN(Number(width)) === false &&
Number.isNaN(Number(height)) === false
) {
item.attributes.viewBox = `0 0 ${Number(width)} ${Number(height)}`;
}
if (
name === 'svg' &&
type === 'element' &&
width != null &&
height != null &&
viewBox == null &&
Number.isNaN(Number(width)) === false &&
Number.isNaN(Number(height)) === false
) {
item.attributes.viewBox = `0 0 ${Number(width)} ${Number(height)}`;
}
};
9 changes: 0 additions & 9 deletions initial-commit.svg

This file was deleted.

19 changes: 12 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
{
"name": "initial-commit",
"version": "0.1.2",
"description": "Starting template for repository",
"keywords": [],
"homepage": "https://atanas.info/projects/initial-commit.html",
"name": "svgo-add-viewbox",
"version": "1.0.0",
"description": "SVGO plugin which adds 'viewBox' attribute based on 'width' and 'height' attributes",
"keywords": [
"SVG",
"SVGO",
"SVGO plugin",
"viewBox"
],
"homepage": "https://atanas.info/projects/svgo-add-viewbox.html",
"bugs": {
"url": "https://github.com/scriptex/initial-commit/issues",
"url": "https://github.com/scriptex/svgo-add-viewbox/issues",
"email": "scriptex.bg@gmail.com"
},
"license": "MIT",
Expand All @@ -29,7 +34,7 @@
}
],
"main": "index.js",
"repository": "https://github.com/scriptex/initial-commit",
"repository": "https://github.com/scriptex/svgo-add-viewbox",
"scripts": {
"test": "echo 'No tests found'",
"release-minor": "release-it minor --ci",
Expand Down
Binary file removed repository-image.png
Binary file not shown.
Loading