export-svg-typescript 0.1.11 → 0.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -56,7 +56,7 @@ export function convertSVGFolderToExportIndex(inputFolder, indexPath) {
56
56
  )}({ colors: ['#0099e5', '#ff4c4c'], size: 100 });
57
57
  * @returns {string} SVG string with applied customizations
58
58
  */
59
- export const ${toCamelCase(baseName)} = (options: LoadingOptions = {}) => customSVG(options,
59
+ export const ${toCamelCase(baseName)} = (options: LoadingOptions = {}) => customSVG(options,
60
60
  \`${svgContent
61
61
  .replace(/`/g, "\\`")
62
62
  .replace(' xmlns:xlink="http://www.w3.org/1999/xlink"', "")
@@ -94,13 +94,16 @@ export const ${toCamelCase(baseName)} = (options: LoadingOptions = {}) => custo
94
94
  function customSVG( options: LoadingOptions, svgString: string) {
95
95
  const { colors = [], width, height, size, raw = false } = options;
96
96
 
97
- const widthMatch = svgString.match(/width="(d+)"/);
98
- const heightMatch = svgString.match(/height="(d+)"/);
97
+ const widthMatch = svgString.match(/width="[^"]*"/);
98
+ const heightMatch = svgString.match(/height="[^"]*"/);
99
99
  const finalWidth = size || width || widthMatch?.[1] || '100';
100
100
  const finalHeight = size || height || heightMatch?.[1] || '100';
101
-
102
- svgString = svgString.replace(/width="[^"]*"/g, \`width="\${finalWidth}"\`);
103
- svgString = svgString.replace(/height="[^"]*"/g, \`height="\${finalHeight}"\`);
101
+
102
+ if (width || height || size) {
103
+ svgString = svgString.replace(/width="[^"]*"/, \`width="${finalWidth}px"\`);
104
+ svgString = svgString.replace(/height="[^"]*"/, \`height="${finalHeight}px"\`);
105
+ }
106
+
104
107
 
105
108
  // If colors array is provided, replace hex colors in order of appearance
106
109
  if (colors && colors.length > 0) {
@@ -133,14 +136,10 @@ interface LoadingOptions {
133
136
  /** Whether to return the raw SVG string or an img tag */
134
137
  raw?: boolean;
135
138
  }
136
-
137
139
  `;
138
140
 
139
141
  fs.writeFileSync(indexPath, indexContent);
140
142
 
141
-
142
-
143
-
144
143
  console.log(
145
144
  `✨ Converted ${svgFiles.length} SVG files to customizable JS export files`
146
145
  );
package/package.json CHANGED
@@ -3,10 +3,11 @@
3
3
  "module": "./export-svg-typescript.js",
4
4
  "author": "vtempest",
5
5
  "license": "MIT",
6
- "version": "0.1.11",
6
+ "version": "0.1.12",
7
7
  "description": "Export SVG to TypeScript",
8
8
  "type": "module",
9
9
  "scripts": {
10
+ "pub": "npm version patch && npm publish",
10
11
  "demo": "node export-svg-typescript.js -i ./demo -o ./demo/index.ts"
11
12
  },
12
13
  "bin": {