Socket
Socket
Sign inDemoInstall

@svgr/babel-plugin-svg-em-dimensions

Package Overview
Dependencies
53
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 6.0.0-alpha.1 to 6.0.0-alpha.4

10

dist/index.d.ts

@@ -1,4 +0,8 @@

import { NodePath, types } from '@babel/core';
import { ConfigAPI, NodePath, types } from '@babel/core';
declare const plugin: () => {
interface Options {
width: number | string;
height: number | string;
}
declare const plugin: (_: ConfigAPI, opts: Options) => {
visitor: {

@@ -9,2 +13,2 @@ JSXOpeningElement(path: NodePath<types.JSXOpeningElement>): void;

export { plugin as default };
export { Options, plugin as default };

@@ -6,4 +6,15 @@ 'use strict';

const elements = ["svg", "Svg"];
const value = core.types.stringLiteral("1em");
const plugin = () => ({
const getValue = (raw) => {
if (raw === void 0)
return core.types.stringLiteral("1em");
switch (typeof raw) {
case "number":
return core.types.jsxExpressionContainer(core.types.numericLiteral(raw));
case "string":
return core.types.stringLiteral(raw);
default:
return core.types.stringLiteral("1em");
}
};
const plugin = (_, opts) => ({
visitor: {

@@ -13,3 +24,7 @@ JSXOpeningElement(path) {

return;
const requiredAttributes = ["width", "height"];
const values = {
width: getValue(opts.width),
height: getValue(opts.height)
};
const requiredAttributes = Object.keys(values);
path.get("attributes").forEach((attributePath) => {

@@ -25,6 +40,6 @@ if (!attributePath.isJSXAttribute())

const valuePath = attributePath.get("value");
valuePath.replaceWith(value);
valuePath.replaceWith(values[namePath.node.name]);
requiredAttributes.splice(index, 1);
});
path.pushContainer("attributes", requiredAttributes.map((attr) => core.types.jsxAttribute(core.types.jsxIdentifier(attr), value)));
path.pushContainer("attributes", requiredAttributes.map((attr) => core.types.jsxAttribute(core.types.jsxIdentifier(attr), values[attr])));
}

@@ -31,0 +46,0 @@ }

{
"name": "@svgr/babel-plugin-svg-em-dimensions",
"description": "Transform SVG to use em-based dimensions",
"version": "6.0.0-alpha.1",
"version": "6.0.0-alpha.4",
"main": "./dist/index.js",

@@ -33,3 +33,3 @@ "exports": "./dist/index.js",

},
"gitHead": "22e2736665552263fff88683e1551b8ad852b150"
"gitHead": "a5effba17307c1ab1c04da3c1b8cee79c060cd46"
}

@@ -15,3 +15,5 @@ # @svgr/babel-plugin-svg-em-dimensions

{
"plugins": ["@svgr/babel-plugin-svg-em-dimensions"]
"plugins": [
["@svgr/babel-plugin-svg-em-dimensions", { "width": 24, "height": 24 }]
]
}

@@ -18,0 +20,0 @@ ```

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc