Socket
Socket
Sign inDemoInstall

postcss-svgo

Package Overview
Dependencies
Maintainers
6
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-svgo - npm Package Compare versions

Comparing version 2.1.6 to 4.0.0-nightly.2020.1.9

184

dist/index.js

@@ -1,108 +0,126 @@

'use strict';
"use strict";
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _postcss = _interopRequireDefault(require("postcss"));
var _postcss = require('postcss');
var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
var _postcss2 = _interopRequireDefault(_postcss);
var _svgo = _interopRequireDefault(require("svgo"));
var _postcssValueParser = require('postcss-value-parser');
var _isSvg = _interopRequireDefault(require("is-svg"));
var _postcssValueParser2 = _interopRequireDefault(_postcssValueParser);
var _url = require("./lib/url");
var _svgo = require('svgo');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _svgo2 = _interopRequireDefault(_svgo);
const PLUGIN = 'postcss-svgo';
const dataURI = /data:image\/svg\+xml(;((charset=)?utf-8|base64))?,/i;
const dataURIBase64 = /data:image\/svg\+xml;base64,/i;
var _isSvg = require('is-svg');
function minifyPromise(decl, getSvgo, opts) {
const promises = [];
const parsed = (0, _postcssValueParser.default)(decl.value);
decl.value = parsed.walk(node => {
if (node.type !== 'function' || node.value.toLowerCase() !== 'url' || !node.nodes.length) {
return;
}
var _isSvg2 = _interopRequireDefault(_isSvg);
let {
value,
quote
} = node.nodes[0];
let isBase64, isUriEncoded;
const url = new URL(value);
let svg = value.replace(dataURI, '');
var _url = require('./lib/url');
if (dataURIBase64.test(value)) {
let base64String = `${url.protocol}${url.pathname}`.replace(dataURI, '');
svg = Buffer.from(base64String, 'base64').toString('utf8');
isBase64 = true;
} else {
let decodedUri;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
try {
decodedUri = (0, _url.decode)(svg);
isUriEncoded = decodedUri !== svg;
} catch (e) {
// Swallow exception if we cannot decode the value
isUriEncoded = false;
}
var PLUGIN = 'postcss-svgo';
var dataURI = /data:image\/svg\+xml(;(charset=)?utf-8)?,/;
if (isUriEncoded) {
svg = decodedUri;
}
function minifyPromise(svgo, decl, opts) {
var promises = [];
if (opts.encode !== undefined) {
isUriEncoded = opts.encode;
}
}
decl.value = (0, _postcssValueParser2.default)(decl.value).walk(function (node) {
if (node.type !== 'function' || node.value !== 'url' || !node.nodes.length) {
return;
}
var value = node.nodes[0].value;
if (!(0, _isSvg.default)(svg)) {
return;
}
var decodedUri = void 0,
isUriEncoded = void 0;
promises.push(getSvgo().optimize(svg).then(result => {
let data, optimizedValue;
try {
decodedUri = (0, _url.decode)(value);
isUriEncoded = decodedUri !== value;
} catch (e) {
// Swallow exception if we cannot decode the value
isUriEncoded = false;
}
if (isBase64) {
data = Buffer.from(result.data).toString('base64');
optimizedValue = 'data:image/svg+xml;base64,' + data + url.hash;
} else {
data = isUriEncoded ? (0, _url.encode)(result.data) : result.data; // Should always encode # otherwise we yield a broken SVG
// in Firefox (works in Chrome however). See this issue:
// https://github.com/cssnano/cssnano/issues/245
if (isUriEncoded) {
value = decodedUri;
}
if (opts.encode !== undefined) {
isUriEncoded = opts.encode;
}
data = data.replace(/#/g, '%23');
optimizedValue = 'data:image/svg+xml;charset=utf-8,' + data;
quote = isUriEncoded ? '"' : "'";
}
var svg = value.replace(dataURI, '');
node.nodes[0] = Object.assign({}, node.nodes[0], {
value: optimizedValue,
quote: quote,
type: 'string',
before: '',
after: ''
});
}).catch(error => {
throw new Error(`${PLUGIN}: ${error}`);
}));
return false;
});
return Promise.all(promises).then(() => decl.value = decl.value.toString());
}
if (!(0, _isSvg2.default)(svg)) {
return;
}
var _default = _postcss.default.plugin(PLUGIN, (opts = {}) => {
let svgo = null;
promises.push(new Promise(function (resolve, reject) {
return svgo.optimize(svg, function (result) {
if (result.error) {
return reject(PLUGIN + ': ' + result.error);
}
var data = isUriEncoded ? (0, _url.encode)(result.data) : result.data;
// Should always encode # otherwise we yield a broken SVG
// in Firefox (works in Chrome however). See this issue:
// https://github.com/ben-eb/cssnano/issues/245
data = data.replace(/#/g, '%23');
node.nodes[0] = _extends({}, node.nodes[0], {
value: 'data:image/svg+xml;charset=utf-8,' + data,
quote: isUriEncoded ? '"' : '\'',
type: 'string',
before: '',
after: ''
});
return resolve();
});
}));
const getSvgo = () => {
if (!svgo) {
svgo = new _svgo.default(opts);
}
return false;
});
return svgo;
};
return Promise.all(promises).then(function () {
return decl.value = decl.value.toString();
return css => {
return new Promise((resolve, reject) => {
const svgoQueue = [];
css.walkDecls(decl => {
if (!dataURI.test(decl.value)) {
return;
}
svgoQueue.push(minifyPromise(decl, getSvgo, opts));
});
return Promise.all(svgoQueue).then(resolve, reject);
});
}
};
});
exports.default = _postcss2.default.plugin(PLUGIN, function () {
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var svgo = new _svgo2.default(opts);
return function (css) {
return new Promise(function (resolve, reject) {
var promises = [];
css.walkDecls(function (decl) {
if (dataURI.test(decl.value)) {
promises.push(minifyPromise(svgo, decl, opts));
}
});
return Promise.all(promises).then(resolve, reject);
});
};
});
module.exports = exports['default'];
exports.default = _default;
module.exports = exports.default;

@@ -1,9 +0,14 @@

'use strict';
"use strict";
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.encode = encode;
exports.decode = void 0;
function encode(data) {
return data.replace(/"/g, '\'').replace(/%/g, '%25').replace(/</g, '%3C').replace(/>/g, '%3E').replace(/&/g, '%26').replace(/#/g, '%23').replace(/\s+/g, ' ');
};
return data.replace(/"/g, "'").replace(/%/g, '%25').replace(/</g, '%3C').replace(/>/g, '%3E').replace(/&/g, '%26').replace(/#/g, '%23').replace(/\s+/g, ' ');
}
var decode = exports.decode = decodeURIComponent;
const decode = decodeURIComponent;
exports.decode = decode;
{
"name": "postcss-svgo",
"version": "2.1.6",
"version": "4.0.0-nightly.2020.1.9",
"description": "Optimise inline SVG with PostCSS.",
"main": "dist/index.js",
"scripts": {
"contributorAdd": "all-contributors add",
"contributorGenerate": "all-contributors generate",
"pretest": "eslint src",
"prepublish": "del-cli dist && BABEL_ENV=publish babel src --out-dir dist --ignore /__tests__/",
"report": "nyc report --reporter=html",
"test": "nyc --reporter=text ava src/__tests__",
"test-012": "nyc --reporter=text ava src/__tests__"
"prebuild": "",
"build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.js --out-dir dist --ignore \"**/__tests__/\"",
"prepublish": ""
},

@@ -29,22 +25,3 @@ "files": [

"license": "MIT",
"devDependencies": {
"all-contributors-cli": "^3.0.5",
"ava": "^0.16.0",
"babel-cli": "^6.4.5",
"babel-core": "^6.4.5",
"babel-plugin-add-module-exports": "^0.2.0",
"babel-preset-es2015": "^6.3.13",
"babel-preset-es2015-loose": "^7.0.0",
"babel-preset-stage-0": "^6.3.13",
"babel-register": "^6.9.0",
"coveralls": "^2.11.6",
"del-cli": "^0.2.0",
"eslint": "^3.0.0",
"eslint-config-cssnano": "^3.0.0",
"eslint-plugin-babel": "^3.3.0",
"eslint-plugin-import": "^2.0.1",
"nyc": "^10.0.0",
"pleeease-filters": "^3.0.0"
},
"homepage": "https://github.com/ben-eb/postcss-svgo",
"homepage": "https://github.com/cssnano/cssnano",
"author": {

@@ -55,15 +32,15 @@ "name": "Ben Briggs",

},
"repository": "ben-eb/postcss-svgo",
"repository": "cssnano/cssnano",
"dependencies": {
"is-svg": "^2.0.0",
"postcss": "^5.0.14",
"postcss-value-parser": "^3.2.3",
"svgo": "^0.7.0"
"is-svg": "^4.1.0",
"postcss": "^7.0.16",
"postcss-value-parser": "^3.3.1",
"svgo": "^1.2.2"
},
"ava": {
"require": "babel-register"
"bugs": {
"url": "https://github.com/cssnano/cssnano/issues"
},
"eslintConfig": {
"extends": "cssnano"
"engines": {
"node": ">=10.13.0"
}
}
}

@@ -1,2 +0,2 @@

# [postcss][postcss]-svgo [![Build Status](https://travis-ci.org/ben-eb/postcss-svgo.svg?branch=master)][ci] [![NPM version](https://badge.fury.io/js/postcss-svgo.svg)][npm] [![Dependency Status](https://gemnasium.com/ben-eb/postcss-svgo.svg)][deps]
# [postcss][postcss]-svgo

@@ -23,2 +23,6 @@ > Optimise inline SVG with PostCSS.

}
h2 {
background: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRwOi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS5kdGQiPjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iTGF5ZXJfMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+PGNpcmNsZSBjeD0iNTAiIGN5PSI1MCIgcj0iNDAiIGZpbGw9InllbGxvdyIgLz48IS0tdGVzdCBjb21tZW50LS0+PC9zdmc+');
}
```

@@ -32,2 +36,6 @@

}
h2 {
background: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxjaXJjbGUgY3g9IjUwIiBjeT0iNTAiIHI9IjQwIiBmaWxsPSIjZmYwIi8+PC9zdmc+');
}
```

@@ -112,12 +120,5 @@

Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
See [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
| [<img src="https://avatars.githubusercontent.com/u/1282980?v=3" width="100px;"/><br /><sub>Ben Briggs</sub>](http://beneb.info)<br />[๐Ÿ’ป](https://github.com/ben-eb/postcss-svgo/commits?author=ben-eb) [๐Ÿ“–](https://github.com/ben-eb/postcss-svgo/commits?author=ben-eb) ๐Ÿ‘€ [โš ๏ธ](https://github.com/ben-eb/postcss-svgo/commits?author=ben-eb) | [<img src="https://avatars.githubusercontent.com/u/7263665?v=3" width="100px;"/><br /><sub>Sebastian Misch</sub>](https://sebastian-misch.de)<br />[๐Ÿ’ป](https://github.com/ben-eb/postcss-svgo/commits?author=sbstnmsch) [โš ๏ธ](https://github.com/ben-eb/postcss-svgo/commits?author=sbstnmsch) | [<img src="https://avatars.githubusercontent.com/u/11319202?v=3" width="100px;"/><br /><sub>ะ’ัั‡ะตัะปะฐะฒ ะ›ััˆะตะฝะบะพ</sub>](https://github.com/ophyros)<br />[๐Ÿ’ป](https://github.com/ben-eb/postcss-svgo/commits?author=ophyros) [โš ๏ธ](https://github.com/ben-eb/postcss-svgo/commits?author=ophyros) | [<img src="https://avatars.githubusercontent.com/u/1131567?v=3" width="100px;"/><br /><sub>shinnn</sub>](https://shinnn.github.io)<br />[๐Ÿ’ป](https://github.com/ben-eb/postcss-svgo/commits?author=shinnn) | [<img src="https://avatars.githubusercontent.com/u/45338?v=3" width="100px;"/><br /><sub>Jung-gun Lim</sub>](https://github.com/j6lim)<br />[๐Ÿ›](https://github.com/ben-eb/postcss-svgo/issues?q=author%3Aj6lim) | [<img src="https://avatars.githubusercontent.com/u/5635476?v=3" width="100px;"/><br /><sub>Bogdan Chadkin</sub>](https://github.com/TrySound)<br />[๐Ÿ’ป](https://github.com/ben-eb/postcss-svgo/commits?author=TrySound) ๐Ÿ‘€ [โš ๏ธ](https://github.com/ben-eb/postcss-svgo/commits?author=TrySound) | [<img src="https://avatars.githubusercontent.com/u/368561?v=3" width="100px;"/><br /><sub>Piotr Walczyszyn</sub>](http://outof.me)<br />[๐Ÿ›](https://github.com/ben-eb/postcss-svgo/issues?q=author%3Apwalczyszyn) |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
<!-- ALL-CONTRIBUTORS-LIST:END -->
This project follows the [all-contributors] specification. Contributions of
any kind welcome!
## License

@@ -127,8 +128,3 @@

[all-contributors]: https://github.com/kentcdodds/all-contributors
[ci]: https://travis-ci.org/ben-eb/postcss-svgo
[deps]: https://gemnasium.com/ben-eb/postcss-svgo
[npm]: http://badge.fury.io/js/postcss-svgo
[postcss]: https://github.com/postcss/postcss
[plugins]: https://github.com/svg/svgo/tree/master/plugins
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with โšก๏ธ by Socket Inc