export-svg-typescript 0.1.4 → 0.1.6

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.
package/demo/index.ts CHANGED
@@ -1,9 +1,7 @@
1
- // Do a Barrel Roll index of SVG icons as JS exports, enabling tree shaking to only the icons you import.
2
-
1
+ // Do a Barrel Roll (auto-generated) index of SVG icons as JS exports, tree shaking to only the icons used.
3
2
 
4
3
  /**
5
- * Returns a customized SVG string for loading icon bouncy-ball
6
- *
4
+ * Returns a customized SVG string for icon loading-bouncy-ball
7
5
  * ![loading-bouncy-ball](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJ4TWlkWU1pZCIgd2lkdGg9IjIwMCIgaGVpZ2h0PSIyMDAiIHN0eWxlPSJzaGFwZS1yZW5kZXJpbmc6IGF1dG87IGRpc3BsYXk6IGJsb2NrOyAiIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIj48Zz48Y2lyY2xlIGZpbGw9IiNlMTViNjQiIHI9IjEzIiBjeT0iMjMiIGN4PSI1MCI+CiAgPGFuaW1hdGUgdmFsdWVzPSIyMzs3NzsyMyIga2V5VGltZXM9IjA7MC41OzEiIGtleVNwbGluZXM9IjAuNDUgMCAwLjkgMC41NTswIDAuNDUgMC41NSAwLjkiIGNhbGNNb2RlPSJzcGxpbmUiIHJlcGVhdENvdW50PSJpbmRlZmluaXRlIiBkdXI9IjFzIiBhdHRyaWJ1dGVOYW1lPSJjeSI+PC9hbmltYXRlPgo8L2NpcmNsZT48Zz48L2c+PC9nPjwvc3ZnPg==)
8
6
  * @param {Object} options - Configuration options
9
7
  * @param {string[]} [options.colors] - Array of hex colors to replace existing colors
@@ -16,10 +14,8 @@
16
14
  export const loadingBouncyBall = (options: LoadingOptions = {}) => customSVG(options,
17
15
  `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid" width="200" height="200" style="shape-rendering: auto; display: block; "><g><circle fill="#e15b64" r="13" cy="23" cx="50"><animate values="23;77;23" keyTimes="0;0.5;1" keySplines="0.45 0 0.9 0.55;0 0.45 0.55 0.9" calcMode="spline" repeatCount="indefinite" dur="1s" attributeName="cy"></animate></circle><g></g></g></svg>`);
18
16
 
19
-
20
17
  /**
21
- * Returns a customized SVG string for loading icon double-ring
22
- *
18
+ * Returns a customized SVG string for icon loading-double-ring
23
19
  * ![loading-double-ring](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJ4TWlkWU1pZCIgd2lkdGg9IjIwMCIgaGVpZ2h0PSIyMDAiIHN0eWxlPSJzaGFwZS1yZW5kZXJpbmc6IGF1dG87IGRpc3BsYXk6IGJsb2NrOyAiIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIj48Zz48Y2lyY2xlIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgZmlsbD0ibm9uZSIgc3Ryb2tlLWRhc2hhcnJheT0iNTAuMjY1NDgyNDU3NDM2NjkgNTAuMjY1NDgyNDU3NDM2NjkiIHN0cm9rZT0iIzAwOTllNSIgc3Ryb2tlLXdpZHRoPSI4IiByPSIzMiIgY3k9IjUwIiBjeD0iNTAiPgogIDxhbmltYXRlVHJhbnNmb3JtIHZhbHVlcz0iMCA1MCA1MDszNjAgNTAgNTAiIGtleVRpbWVzPSIwOzEiIHJlcGVhdENvdW50PSJpbmRlZmluaXRlIiBkdXI9IjFzIiB0eXBlPSJyb3RhdGUiIGF0dHJpYnV0ZU5hbWU9InRyYW5zZm9ybSI+PC9hbmltYXRlVHJhbnNmb3JtPgo8L2NpcmNsZT4KPGNpcmNsZSBzdHJva2UtbGluZWNhcD0icm91bmQiIGZpbGw9Im5vbmUiIHN0cm9rZS1kYXNob2Zmc2V0PSIzNi4xMjgzMTU1MTYyODI2MiIgc3Ryb2tlLWRhc2hhcnJheT0iMzYuMTI4MzE1NTE2MjgyNjIgMzYuMTI4MzE1NTE2MjgyNjIiIHN0cm9rZT0iI2ZmNGM0YyIgc3Ryb2tlLXdpZHRoPSI4IiByPSIyMyIgY3k9IjUwIiBjeD0iNTAiPgogIDxhbmltYXRlVHJhbnNmb3JtIHZhbHVlcz0iMCA1MCA1MDstMzYwIDUwIDUwIiBrZXlUaW1lcz0iMDsxIiByZXBlYXRDb3VudD0iaW5kZWZpbml0ZSIgZHVyPSIxcyIgdHlwZT0icm90YXRlIiBhdHRyaWJ1dGVOYW1lPSJ0cmFuc2Zvcm0iPjwvYW5pbWF0ZVRyYW5zZm9ybT4KPC9jaXJjbGU+PGc+PC9nPjwvZz48L3N2Zz4=)
24
20
  * @param {Object} options - Configuration options
25
21
  * @param {string[]} [options.colors] - Array of hex colors to replace existing colors
@@ -32,10 +28,8 @@ export const loadingBouncyBall = (options: LoadingOptions = {}) => customSVG(op
32
28
  export const loadingDoubleRing = (options: LoadingOptions = {}) => customSVG(options,
33
29
  `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid" width="200" height="200" style="shape-rendering: auto; display: block; "><g><circle stroke-linecap="round" fill="none" stroke-dasharray="50.26548245743669 50.26548245743669" stroke="#0099e5" stroke-width="8" r="32" cy="50" cx="50"><animateTransform values="0 50 50;360 50 50" keyTimes="0;1" repeatCount="indefinite" dur="1s" type="rotate" attributeName="transform"></animateTransform></circle><circle stroke-linecap="round" fill="none" stroke-dashoffset="36.12831551628262" stroke-dasharray="36.12831551628262 36.12831551628262" stroke="#ff4c4c" stroke-width="8" r="23" cy="50" cx="50"><animateTransform values="0 50 50;-360 50 50" keyTimes="0;1" repeatCount="indefinite" dur="1s" type="rotate" attributeName="transform"></animateTransform></circle><g></g></g></svg>`);
34
30
 
35
-
36
31
  /**
37
- * Returns a customized SVG string for loading icon eclipse
38
- *
32
+ * Returns a customized SVG string for icon loading-eclipse
39
33
  * ![loading-eclipse](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJ4TWlkWU1pZCIgd2lkdGg9IjIwMCIgaGVpZ2h0PSIyMDAiIHN0eWxlPSJzaGFwZS1yZW5kZXJpbmc6IGF1dG87IGRpc3BsYXk6IGJsb2NrOyI+PGc+PHBhdGggc3Ryb2tlPSJub25lIiBmaWxsPSIjZmZiOTAwIiBkPSJNMTAgNTBBNDAgNDAgMCAwIDAgOTAgNTBBNDAgNDIgMCAwIDEgMTAgNTAiPgogIDxhbmltYXRlVHJhbnNmb3JtIHZhbHVlcz0iMCA1MCA1MTszNjAgNTAgNTEiIGtleVRpbWVzPSIwOzEiIHJlcGVhdENvdW50PSJpbmRlZmluaXRlIiBkdXI9IjFzIiB0eXBlPSJyb3RhdGUiIGF0dHJpYnV0ZU5hbWU9InRyYW5zZm9ybSI+PC9hbmltYXRlVHJhbnNmb3JtPgo8L3BhdGg+PGc+PC9nPjwvZz48L3N2Zz4=)
40
34
  * @param {Object} options - Configuration options
41
35
  * @param {string[]} [options.colors] - Array of hex colors to replace existing colors
@@ -85,7 +79,7 @@ function customSVG( options: LoadingOptions, svgString: string) {
85
79
  });
86
80
  }
87
81
  if (!raw)
88
- svgString = `<img alt="loading-icon" src="data:image/svg+xml;utf8,${encodeURIComponent(svgString)}" />`
82
+ svgString = `<img alt="icon" src="data:image/svg+xml;utf8,${encodeURIComponent(svgString)}" />`
89
83
 
90
84
  return svgString;
91
85
  }
@@ -19,7 +19,7 @@ export function convertSVGFolderToExportIndex(inputFolder, indexPath) {
19
19
 
20
20
  // Generate index file
21
21
 
22
- let indexContent = `// Do a Barrel Roll index (auto-generated) of SVG icons as JS exports, tree shaking to only the icons used.\n\n`;
22
+ let indexContent = `// Do a Barrel Roll (auto-generated) index of SVG icons as JS exports, tree shaking to only the icons used.\n\n`;
23
23
  const exportData = [];
24
24
 
25
25
  svgFiles.forEach((svgFile) => {
@@ -41,23 +41,19 @@ export function convertSVGFolderToExportIndex(inputFolder, indexPath) {
41
41
  )}`;
42
42
 
43
43
  const jsContent = `/**
44
- * Returns a customizable SVG string for icon ${baseName.replace(
45
- /loading-/g,
46
- ""
47
- )}
44
+ * Returns a customized SVG string for icon ${baseName.replace(/icon-/g, "" )}
48
45
  * ![${baseName}](${svgBase64})
46
+ * @param {Object} options - Configuration options
49
47
  * @param {string[]} [options.colors] - Array of hex colors to replace existing colors
50
48
  * @param {number} [options.width] - Width of the SVG (default: ${defaultWidth})
51
49
  * @param {number} [options.height] - Height of the SVG (default: ${defaultHeight})
52
50
  * @param {number} [options.size] - Size for both width and height
53
51
  * @example ${toCamelCase(
54
- baseName
55
- )}({ colors: ['#0099e5', '#ff4c4c'], size: 100 });
52
+ baseName
53
+ )}({ colors: ['#0099e5', '#ff4c4c'], size: 100 });
56
54
  * @returns {string} SVG string with applied customizations
57
55
  */
58
- export const ${toCamelCase(
59
- baseName
60
- )} = (options: LoadingOptions = {}) => customSVG(options,
56
+ export const ${toCamelCase(baseName)} = (options: LoadingOptions = {}) => customSVG(options,
61
57
  \`${svgContent
62
58
  .replace(/`/g, "\\`")
63
59
  .replace(' xmlns:xlink="http://www.w3.org/1999/xlink"', "")
@@ -118,7 +114,7 @@ function customSVG( options: LoadingOptions, svgString: string) {
118
114
  });
119
115
  }
120
116
  if (!raw)
121
- svgString = \`<img alt="loading-icon" src="data:image/svg+xml;utf8,\${encodeURIComponent(svgString)}" />\`
117
+ svgString = \`<img alt="icon" src="data:image/svg+xml;utf8,\${encodeURIComponent(svgString)}" />\`
122
118
 
123
119
  return svgString;
124
120
  }
@@ -139,6 +135,9 @@ interface LoadingOptions {
139
135
 
140
136
  fs.writeFileSync(indexPath, indexContent);
141
137
 
138
+
139
+
140
+
142
141
  console.log(
143
142
  `✨ Converted ${svgFiles.length} SVG files to customizable JS export files`
144
143
  );
@@ -163,9 +162,13 @@ function toCamelCase(str) {
163
162
  .join("");
164
163
  }
165
164
 
166
- // Get folder path from command line args
167
- const inputFolder = process.argv[2] || "./svg";
168
- const outputPath = process.argv[3] || `${inputFolder}/index.ts`;
165
+ // Get input/output folders from command line args
166
+ const args = process.argv.slice(2);
167
+ const inputIndex = args.indexOf("-i");
168
+ const outputIndex = args.indexOf("-o");
169
+
170
+ const inputFolder = inputIndex >= 0 ? args[inputIndex + 1] : "./svg"; // Folder containing SVG files
171
+ const outputPath = outputIndex >= 0 ? args[outputIndex + 1] : "./index.ts"; // Folder for generated JS files
169
172
 
170
173
  // Run the converter
171
174
  convertSVGFolderToExportIndex(inputFolder, outputPath);
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "export-svg-typescript",
3
- "description": "Export SVG icons to TypeScript index with tooltips and customizations",
3
+ "module": "export-svg-typescript.js",
4
4
  "author": "vtempest",
5
5
  "license": "MIT",
6
- "version": "0.1.4",
6
+ "version": "0.1.6",
7
+ "description": "Export SVG to TypeScript",
7
8
  "type": "module",
8
- "module": "export-svg-typescript.js",
9
9
  "scripts": {
10
10
  "demo": "node export-svg-typescript.js -i ./demo -o ./demo/index.ts"
11
11
  },
package/readme.md CHANGED
@@ -11,32 +11,23 @@ Convert a folder of SVG icons into a color-customizable, tree-shakable TypeScrip
11
11
  Global install:
12
12
  ```
13
13
  npm install -g export-svg-typescript
14
+ ```
14
15
  Or add to package.json:
15
16
  ```
16
- <<<<<<< HEAD
17
17
  "icons": "npx export-svg-typescript -i ./src/icons",
18
18
  ```
19
19
  Or use npx without installing globally with index output file set
20
20
  ```
21
21
  npx export-svg-typescript -i ./src/icons -o ./src/icons/index.ts
22
- =======
23
- "icons": "npx export-svg-typescript ./src/icons",
24
- ```
25
- Or use npx without installing globally with index output file set
26
- >>>>>>> c0be8d9515fa79c37c249ff6f2a0139d15d2f374
27
- ```
28
- npx export-svg-typescript ./src/icons ./src/icons/index.ts
29
22
  ```
30
23
 
31
-
32
-
33
24
  ### Example
34
25
 
35
26
  Clone this repo and run `npm run demo` to see icons in demo folder.
36
27
 
37
28
  ```javascript
38
29
  import { loadingDoubleRing } from './demo';
39
-
30
+
40
31
  loadingDoubleRing({size: 200, colors: ["#5345bb"] })
41
32
  ```
42
33
  ![screenshot](https://i.imgur.com/aXczCC2.png)