Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

svgo

Package Overview
Dependencies
Maintainers
4
Versions
104
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svgo - npm Package Compare versions

Comparing version 3.0.4 to 3.0.5

lib/types.d.ts

5

lib/svgo.d.ts

@@ -66,2 +66,5 @@ import type { StringifyOptions, DataUri, Plugin as PluginFn } from './types';

): Promise<Config>;
export declare function loadConfig(): Promise<Config | null>;
export declare function loadConfig(
configFile?: null,
cwd?: string
): Promise<Config | null>;

37

lib/svgo/coa.js

@@ -15,2 +15,3 @@ 'use strict';

* Synchronously check if path is a directory. Tolerant to errors like ENOENT.
*
* @param {string} path

@@ -280,2 +281,3 @@ */

* Optimize SVG files in a directory.
*
* @param {Object} config options

@@ -297,2 +299,3 @@ * @param {string} dir input directory

* Process given files, take only SVG.
*
* @param {Object} config options

@@ -324,3 +327,4 @@ * @param {string} dir input directory

/**
* Get svg files descriptions
* Get SVG files descriptions.
*
* @param {Object} config options

@@ -367,2 +371,3 @@ * @param {string} dir input directory

* Read SVG file and pass to processing.
*
* @param {Object} config options

@@ -383,2 +388,3 @@ * @param {string} file

* Optimize SVG data.
*
* @param {Object} config options

@@ -434,2 +440,3 @@ * @param {string} data SVG content to optimize

* Write result of an optimization.
*
* @param {string} input

@@ -454,3 +461,4 @@ * @param {string} output output file name. '-' for stdout

/**
* Write a time taken by optimization.
* Write time taken to optimize.
*
* @param {number} time time in milliseconds.

@@ -463,3 +471,4 @@ */

/**
* Write optimizing information in human readable format.
* Write optimizing stats in a human-readable format.
*
* @param {number} inBytes size before optimization.

@@ -469,12 +478,12 @@ * @param {number} outBytes size after optimization.

function printProfitInfo(inBytes, outBytes) {
var profitPercents = 100 - (outBytes * 100) / inBytes;
const profitPercent = 100 - (outBytes * 100) / inBytes;
/** @type {[string, Function]} */
const ui = profitPercent < 0 ? ['+', colors.red] : ['-', colors.green];
console.log(
Math.round((inBytes / 1024) * 1000) / 1000 +
' KiB' +
(profitPercents < 0 ? ' + ' : ' - ') +
colors.green(Math.abs(Math.round(profitPercents * 10) / 10) + '%') +
' = ' +
Math.round((outBytes / 1024) * 1000) / 1000 +
' KiB'
Math.round((inBytes / 1024) * 1000) / 1000 + ' KiB',
ui[0],
ui[1](Math.abs(Math.round(profitPercent * 10) / 10) + '%'),
'=',
Math.round((outBytes / 1024) * 1000) / 1000 + ' KiB'
);

@@ -485,2 +494,3 @@ }

* Check for errors, if it's a dir optimize the dir.
*
* @param {Object} config

@@ -505,2 +515,3 @@ * @param {string} input

* Check for saving file error. If the output is a dir, then write file there.
*
* @param {string} input

@@ -524,5 +535,3 @@ * @param {string} output

/**
* Show list of available plugins with short description.
*/
/** Show list of available plugins with short description. */
function showAvailablePlugins() {

@@ -529,0 +538,0 @@ const list = builtin

@@ -80,3 +80,4 @@ 'use strict';

/**
* @type {(node: XastChild, parentNode: XastParent) => void}
* @param {XastChild} node
* @param {XastParent} parentNode
*/

@@ -83,0 +84,0 @@ const detachNodeFromParent = (node, parentNode) => {

{
"packageManager": "yarn@2.4.3",
"name": "svgo",
"version": "3.0.4",
"version": "3.0.5",
"description": "Nodejs-based tool for optimizing SVG vector graphics files",

@@ -6,0 +6,0 @@ "license": "MIT",

@@ -16,3 +16,3 @@ 'use strict';

const regReferencesHref = /^#(.+?)$/;
const regReferencesBegin = /(\D+)\./;
const regReferencesBegin = /(\w+)\.[a-zA-Z]/;
const generateIdChars = [

@@ -19,0 +19,0 @@ 'a',

@@ -688,4 +688,8 @@ 'use strict';

) {
// @ts-ignore
if (pathBase[0] === item.coords[0] && pathBase[1] === item.coords[1]) {
if (
// @ts-ignore
Math.abs(pathBase[0] - item.coords[0]) < error &&
// @ts-ignore
Math.abs(pathBase[1] - item.coords[1]) < error
) {
command = 'z';

@@ -828,4 +832,2 @@ data = [];

item.args = data;
prev = item;
} else {

@@ -837,3 +839,2 @@ // z resets coordinates

if (prev.command === 'Z' || prev.command === 'z') return false;
prev = item;
}

@@ -845,8 +846,9 @@ if (

// @ts-ignore
item.base[0] === item.coords[0] &&
Math.abs(item.base[0] - item.coords[0]) < error / 10 &&
// @ts-ignore
item.base[1] === item.coords[1]
Math.abs(item.base[1] - item.coords[1]) < error / 10
)
return false;
prev = item;
return true;

@@ -853,0 +855,0 @@ });

@@ -107,9 +107,7 @@ 'use strict';

// if no element separators (:), assume it's attribute name, and apply to all elements *regardless of value*
if (pattern.includes(elemSeparator) === false) {
pattern = ['.*', elemSeparator, pattern, elemSeparator, '.*'].join(
''
);
if (!pattern.includes(elemSeparator)) {
pattern = ['.*', pattern, '.*'].join(elemSeparator);
// if only 1 separator, assume it's element and attribute name, and apply regardless of attribute value
} else if (pattern.split(elemSeparator).length < 3) {
pattern = [pattern, elemSeparator, '.*'].join('');
pattern = [pattern, '.*'].join(elemSeparator);
}

@@ -116,0 +114,0 @@

@@ -52,2 +52,5 @@ 'use strict';

}
if (parentNode.type === 'element' && parentNode.name === 'switch') {
return;
}
detachNodeFromParent(node, parentNode);

@@ -54,0 +57,0 @@ },

'use strict';
/**
* @typedef {import('../lib/types').XastChild} XastChild
* @typedef {import('../lib/types').XastElement} XastElement

@@ -69,2 +70,26 @@ * @typedef {import('../lib/types').XastParent} XastParent

/**
* IDs for removed hidden definitions.
*
* @type {Set<string>}
*/
const removedDefIds = new Set();
/**
* @param {XastChild} node
* @param {XastParent} parentNode
*/
function removeElement(node, parentNode) {
if (
node.type === 'element' &&
node.attributes.id != null &&
parentNode.type === 'element' &&
parentNode.name === 'defs'
) {
removedDefIds.add(node.attributes.id);
}
detachNodeFromParent(node, parentNode);
}
visit(root, {

@@ -75,2 +100,7 @@ element: {

if (nonRendering.includes(node.name)) {
if (node.attributes.id == null) {
detachNodeFromParent(node, parentNode);
return visitSkip;
}
nonRenderedNodes.set(node, parentNode);

@@ -89,4 +119,3 @@ return visitSkip;

) {
detachNodeFromParent(node, parentNode);
return;
removeElement(node, parentNode);
}

@@ -111,3 +140,3 @@ },

) {
detachNodeFromParent(node, parentNode);
removeElement(node, parentNode);
return;

@@ -129,3 +158,3 @@ }

) {
detachNodeFromParent(node, parentNode);
removeElement(node, parentNode);
return;

@@ -146,3 +175,3 @@ }

) {
detachNodeFromParent(node, parentNode);
removeElement(node, parentNode);
return;

@@ -163,3 +192,3 @@ }

) {
detachNodeFromParent(node, parentNode);
removeElement(node, parentNode);
return;

@@ -180,3 +209,3 @@ }

) {
detachNodeFromParent(node, parentNode);
removeElement(node, parentNode);
return;

@@ -197,3 +226,3 @@ }

) {
detachNodeFromParent(node, parentNode);
removeElement(node, parentNode);
return;

@@ -215,3 +244,3 @@ }

) {
detachNodeFromParent(node, parentNode);
removeElement(node, parentNode);
return;

@@ -231,3 +260,3 @@ }

) {
detachNodeFromParent(node, parentNode);
removeElement(node, parentNode);
return;

@@ -247,3 +276,3 @@ }

) {
detachNodeFromParent(node, parentNode);
removeElement(node, parentNode);
return;

@@ -263,3 +292,3 @@ }

) {
detachNodeFromParent(node, parentNode);
removeElement(node, parentNode);
return;

@@ -279,3 +308,3 @@ }

) {
detachNodeFromParent(node, parentNode);
removeElement(node, parentNode);
return;

@@ -291,3 +320,3 @@ }

if (node.attributes.d == null) {
detachNodeFromParent(node, parentNode);
removeElement(node, parentNode);
return;

@@ -297,3 +326,3 @@ }

if (pathData.length === 0) {
detachNodeFromParent(node, parentNode);
removeElement(node, parentNode);
return;

@@ -307,3 +336,3 @@ }

) {
detachNodeFromParent(node, parentNode);
removeElement(node, parentNode);
return;

@@ -324,3 +353,3 @@ }

) {
detachNodeFromParent(node, parentNode);
removeElement(node, parentNode);
return;

@@ -339,4 +368,3 @@ }

) {
detachNodeFromParent(node, parentNode);
return;
removeElement(node, parentNode);
}

@@ -346,21 +374,38 @@ },

exit: (node, parentNode) => {
if (node.name !== 'svg' || parentNode.type !== 'root') {
if (node.name === 'defs' && node.children.length === 0) {
removeElement(node, parentNode);
return;
}
for (const [
nonRenderedNode,
nonRenderedParent,
] of nonRenderedNodes.entries()) {
if (nonRenderedNode.attributes.id == null) {
detachNodeFromParent(node, nonRenderedParent);
continue;
if (node.name === 'use') {
const referencesRemovedDef = Object.entries(node.attributes).some(
([attrKey, attrValue]) =>
(attrKey === 'href' || attrKey.endsWith(':href')) &&
removedDefIds.has(
attrValue.slice(attrValue.indexOf('#') + 1).trim()
)
);
if (referencesRemovedDef) {
detachNodeFromParent(node, parentNode);
}
const selector = referencesProps
.map((attr) => `[${attr}="url(#${nonRenderedNode.attributes.id})"]`)
.join(',');
return;
}
const element = querySelector(root, selector);
if (element == null) {
detachNodeFromParent(node, nonRenderedParent);
if (node.name === 'svg' && parentNode.type === 'root') {
for (const [
nonRenderedNode,
nonRenderedParent,
] of nonRenderedNodes.entries()) {
const selector = referencesProps
.map(
(attr) => `[${attr}="url(#${nonRenderedNode.attributes.id})"]`
)
.join(',');
const element = querySelector(root, selector);
if (element == null) {
detachNodeFromParent(node, nonRenderedParent);
}
}

@@ -367,0 +412,0 @@ }

Sorry, the diff of this file is too big to display

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