Skip to content

Commit ca10d7d

Browse files
authored
Update all files (#4)
1 parent df04f54 commit ca10d7d

File tree

11 files changed

+280
-369
lines changed

11 files changed

+280
-369
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

.nowignore

Lines changed: 0 additions & 22 deletions
This file was deleted.

.travis.yml

Lines changed: 0 additions & 8 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 0 additions & 54 deletions
This file was deleted.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020-Present Atanas Atanasov
3+
Copyright (c) 2021-Present Atanas Atanasov
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 65 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
<img src="https://raw.githubusercontent.com/scriptex/initial-commit/master/initial-commit.svg" alt="Initial commit Logo" width="200" />
1+
# 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]
22

3-
# 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]
4-
5-
> A starter template for a git repository.
3+
> An SVGO plugin to add `viewBox` attribute based on `width` and `height` attributes
64
75
[![All issues on Github][github-issues-img]][github-issues-url]
86
[![Open issues on Github][github-open-issues-img]][github-open-issues-url]
@@ -23,14 +21,41 @@
2321
[![Renovate App Status][renovateapp-img]][renovateapp-url]
2422
[![Make A Pull Request][prs-welcome-img]][prs-welcome-url]
2523

26-
Use this when creating a NPM package, static website, or any other repository in a git environment
24+
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.
25+
26+
In order to use this plugin correctly, you SVGs should have their `width` and `height` attributes specified.
2727

2828
## Usage
2929

30-
1. Clone this repository
31-
2. Modify relevant files
32-
3. Push to your new repository location
33-
4. Profit
30+
**This plugin should be used with SVGO v2 and above.**
31+
32+
1. Create a `svgo.config.js` file following the [official configuration guide](https://github.com/svg/svgo#configuration)
33+
2. Use the option to specify a custom plugin.
34+
3. Install this module from NPM
35+
```sh
36+
npm install svgo-add-viewbox --save-dev
37+
# or
38+
yarn add svgo-add-viewbox -D
39+
```
40+
4. `require` the module which you just created in your `svgo.config.js` file:
41+
```javascript
42+
const addViewBox = require('svgo-add-viewbox');
43+
```
44+
5. In the `plugins` array in your `svgo.config.js` file add the following:
45+
```javascript
46+
plugins: [
47+
// ... more plugins
48+
{
49+
fn: addViewBox.fn,
50+
name: 'addViewBox',
51+
type: addViewBox.type,
52+
active: addViewBox.active,
53+
description: addViewBox.description
54+
}
55+
// ... more plugins
56+
];
57+
```
58+
6. Execute your SVG transformation NPM script.
3459

3560
## Support this project
3661

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

4671
[MIT][license-url]
4772

48-
[npm-version-img]: https://badgen.net/npm/v/webpack-mpa?icon=npm
49-
[npm-version-url]: https://www.npmjs.com/package/webpack-mpa
50-
[license-img]: https://badgen.net/npm/license/webpack-mpa
51-
[license-url]: https://github.com/scriptex/webpack-mpa/blob/master/LICENSE
73+
[npm-version-img]: https://badgen.net/npm/v/svgo-add-viewbox?icon=npm
74+
[npm-version-url]: https://www.npmjs.com/package/svgo-add-viewbox
75+
[license-img]: https://badgen.net/npm/license/svgo-add-viewbox
76+
[license-url]: https://github.com/scriptex/svgo-add-viewbox/blob/master/LICENSE
5277
[twitter-url]: https://twitter.com/scriptexbg
5378
[twitter-img]: https://badgen.net/twitter/follow/scriptexbg?icon=twitter&color=1da1f2&cache=300
54-
[github-tag-img]: https://badgen.net/github/tag/scriptex/webpack-mpa?icon=github
55-
[github-tag-url]: https://github.com/scriptex/webpack-mpa/releases/latest
56-
[github-checks-img]: https://badgen.net/github/checks/scriptex/webpack-mpa?icon=github
57-
[github-checks-url]: https://github.com/scriptex/webpack-mpa
58-
[github-issues-img]: https://badgen.net/github/issues/scriptex/webpack-mpa?icon=github
59-
[github-issues-url]: https://github.com/scriptex/webpack-mpa/issues
60-
[github-open-issues-img]: https://badgen.net/github/open-issues/scriptex/webpack-mpa?icon=github
61-
[github-open-issues-url]: https://github.com/scriptex/webpack-mpa/issues?q=is%3Aopen+is%3Aissue
62-
[github-closed-issues-img]: https://badgen.net/github/closed-issues/scriptex/webpack-mpa?icon=github
63-
[github-closed-issues-url]: https://github.com/scriptex/webpack-mpa/issues?q=is%3Aissue+is%3Aclosed
64-
[last-commit-img]: https://badgen.net/github/last-commit/scriptex/webpack-mpa?icon=github
65-
[last-commit-url]: https://github.com/scriptex/webpack-mpa/commits/master
66-
[analytics-img]: https://ga-beacon.appspot.com/UA-83446952-1/github.com/scriptex/webpack-mpa/README.md
67-
[analytics-url]: https://github.com/scriptex/webpack-mpa/
68-
[npm-downloads-weekly-img]: https://badgen.net/npm/dw/webpack-mpa?icon=npm
69-
[npm-downloads-monthly-img]: https://badgen.net/npm/dm/webpack-mpa?icon=npm
70-
[npm-downloads-yearly-img]: https://badgen.net/npm/dy/webpack-mpa?icon=npm
71-
[npm-downloads-total-img]: https://badgen.net/npm/dt/webpack-mpa?icon=npm
72-
[npm-url]: https://www.npmjs.com/package/webpack-mpa
79+
[github-tag-img]: https://badgen.net/github/tag/scriptex/svgo-add-viewbox?icon=github
80+
[github-tag-url]: https://github.com/scriptex/svgo-add-viewbox/releases/latest
81+
[github-checks-img]: https://badgen.net/github/checks/scriptex/svgo-add-viewbox?icon=github
82+
[github-checks-url]: https://github.com/scriptex/svgo-add-viewbox
83+
[github-issues-img]: https://badgen.net/github/issues/scriptex/svgo-add-viewbox?icon=github
84+
[github-issues-url]: https://github.com/scriptex/svgo-add-viewbox/issues
85+
[github-open-issues-img]: https://badgen.net/github/open-issues/scriptex/svgo-add-viewbox?icon=github
86+
[github-open-issues-url]: https://github.com/scriptex/svgo-add-viewbox/issues?q=is%3Aopen+is%3Aissue
87+
[github-closed-issues-img]: https://badgen.net/github/closed-issues/scriptex/svgo-add-viewbox?icon=github
88+
[github-closed-issues-url]: https://github.com/scriptex/svgo-add-viewbox/issues?q=is%3Aissue+is%3Aclosed
89+
[last-commit-img]: https://badgen.net/github/last-commit/scriptex/svgo-add-viewbox?icon=github
90+
[last-commit-url]: https://github.com/scriptex/svgo-add-viewbox/commits/master
91+
[analytics-img]: https://ga-beacon.appspot.com/UA-83446952-1/github.com/scriptex/svgo-add-viewbox/README.md
92+
[analytics-url]: https://github.com/scriptex/svgo-add-viewbox/
93+
[npm-downloads-weekly-img]: https://badgen.net/npm/dw/svgo-add-viewbox?icon=npm
94+
[npm-downloads-monthly-img]: https://badgen.net/npm/dm/svgo-add-viewbox?icon=npm
95+
[npm-downloads-yearly-img]: https://badgen.net/npm/dy/svgo-add-viewbox?icon=npm
96+
[npm-downloads-total-img]: https://badgen.net/npm/dt/svgo-add-viewbox?icon=npm
97+
[npm-url]: https://www.npmjs.com/package/svgo-add-viewbox
7398
[tweet-img]: https://img.shields.io/badge/Tweet-Share_this_repository-blue.svg?style=flat-square&logo=twitter&color=38A1F3
74-
[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
99+
[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
75100
[paypal-img]: https://img.shields.io/badge/Donate-Support_me_on_PayPal-blue.svg?style=flat-square&logo=paypal&color=222d65
76101
[paypal-url]: https://www.paypal.me/scriptex
77102
[patreon-img]: https://img.shields.io/badge/Become_Patron-Support_me_on_Patreon-blue.svg?style=flat-square&logo=patreon&color=e64413
@@ -81,13 +106,13 @@ Use this when creating a NPM package, static website, or any other repository in
81106
[liberapay-img]: https://img.shields.io/liberapay/receives/scriptex.svg?logo=liberapay
82107
[liberapay-url]: https://liberapay.com/scriptex
83108
[issuehunt-img]: https://raw.githubusercontent.com/BoostIO/issuehunt-materials/master/v1/issuehunt-shield-v1.svg
84-
[issuehunt-url]: https://issuehunt.io/r/scriptex/webpack-mpa
85-
[publish-size-img]: https://badgen.net/packagephobia/publish/webpack-mpa
109+
[issuehunt-url]: https://issuehunt.io/r/scriptex/svgo-add-viewbox
110+
[publish-size-img]: https://badgen.net/packagephobia/publish/svgo-add-viewbox
86111
[renovateapp-img]: https://badgen.net/badge/renovate/enabled/green?cache=300
87112
[renovateapp-url]: https://renovatebot.com
88113
[prs-welcome-img]: https://badgen.net/badge/PRs/welcome/green?cache=300
89-
[prs-welcome-url]: https://github.com/scriptex/webpack-mpa/pulls
90-
[github-status-img]: https://badgen.net/github/status/scriptex/webpack-mpa?icon=github
91-
[github-status-url]: https://github.com/scriptex/webpack-mpa/actions/workflows/build.yml
92-
[github-languages-img]: https://img.shields.io/github/languages/count/scriptex/webpack-mpa
93-
[github-top-language-img]: https://img.shields.io/github/languages/top/scriptex/webpack-mpa
114+
[prs-welcome-url]: https://github.com/scriptex/svgo-add-viewbox/pulls
115+
[github-status-img]: https://badgen.net/github/status/scriptex/svgo-add-viewbox?icon=github
116+
[github-status-url]: https://github.com/scriptex/svgo-add-viewbox/actions/workflows/build.yml
117+
[github-languages-img]: https://img.shields.io/github/languages/count/scriptex/svgo-add-viewbox
118+
[github-top-language-img]: https://img.shields.io/github/languages/top/scriptex/svgo-add-viewbox

index.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@ exports.description = 'Adds viewBox attribute based on width and height';
2020
* @author Atanas Atanasov
2121
*/
2222
exports.fn = function (item) {
23-
const {
24-
name,
25-
type,
26-
attributes: { width, height, viewBox },
27-
} = item;
23+
const {
24+
name,
25+
type,
26+
attributes: { width, height, viewBox }
27+
} = item;
2828

29-
if (
30-
name === 'svg' &&
31-
type === 'element' &&
32-
width != null &&
33-
height != null &&
34-
viewBox == null &&
35-
Number.isNaN(Number(width)) === false &&
36-
Number.isNaN(Number(height)) === false
37-
) {
38-
item.attributes.viewBox = `0 0 ${Number(width)} ${Number(height)}`;
39-
}
29+
if (
30+
name === 'svg' &&
31+
type === 'element' &&
32+
width != null &&
33+
height != null &&
34+
viewBox == null &&
35+
Number.isNaN(Number(width)) === false &&
36+
Number.isNaN(Number(height)) === false
37+
) {
38+
item.attributes.viewBox = `0 0 ${Number(width)} ${Number(height)}`;
39+
}
4040
};

initial-commit.svg

Lines changed: 0 additions & 9 deletions
This file was deleted.

package.json

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
{
2-
"name": "initial-commit",
3-
"version": "0.1.2",
4-
"description": "Starting template for repository",
5-
"keywords": [],
6-
"homepage": "https://atanas.info/projects/initial-commit.html",
2+
"name": "svgo-add-viewbox",
3+
"version": "1.0.0",
4+
"description": "SVGO plugin which adds 'viewBox' attribute based on 'width' and 'height' attributes",
5+
"keywords": [
6+
"SVG",
7+
"SVGO",
8+
"SVGO plugin",
9+
"viewBox"
10+
],
11+
"homepage": "https://atanas.info/projects/svgo-add-viewbox.html",
712
"bugs": {
8-
"url": "https://github.com/scriptex/initial-commit/issues",
13+
"url": "https://github.com/scriptex/svgo-add-viewbox/issues",
914
"email": "scriptex.bg@gmail.com"
1015
},
1116
"license": "MIT",
@@ -29,7 +34,7 @@
2934
}
3035
],
3136
"main": "index.js",
32-
"repository": "https://github.com/scriptex/initial-commit",
37+
"repository": "https://github.com/scriptex/svgo-add-viewbox",
3338
"scripts": {
3439
"test": "echo 'No tests found'",
3540
"release-minor": "release-it minor --ci",

repository-image.png

-14.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)