7 Commits

Author SHA1 Message Date
Konstantin Vulsonov
bb2c336781 Fix svg IDs generation 2018-09-21 02:21:10 +03:00
Konstantin Vulsonov
2fc72898d3 fix IDs creation 2018-09-21 02:21:05 +03:00
Konstantin Vulsonov
dbf0994650 readme fix 2018-09-21 01:58:04 +03:00
Konstantin Vulsonov
b9745233ab Update type definition for TS 2018-09-21 01:57:07 +03:00
Konstantin Vulsonov
225e6dea60 add ts typedef 2018-09-21 01:57:02 +03:00
Konstantin Vulsonov
5bc85cfee3 Update README.md 2018-09-20 01:27:07 +03:00
Konstantin Vulsonov
1374a3a65a Update README.md 2018-09-20 01:07:37 +03:00
4 changed files with 10 additions and 7 deletions

View File

@@ -24,7 +24,7 @@ svg-iconset --source=assets/images/icons --result=icons
```
Creates a file `icons-iconset.svg` in same folder
### In Project
```
```javascript
const SvgIconset = require('svg-iconset');
const config = {
@@ -32,9 +32,13 @@ const config = {
result: 'icons', // Required
// This is optional for optimize files using SVGO plugins
optimize: {
removeViewBox: true, // Will remove attribute viewBox (default true)
removeViewBox: true, // Will remove attribute viewBox
}
}
new SvgIconset(config).createSet();
```
#### Additional
[Default SVGO optimisation config](https://github.com/DariusNorv/svg-iconset/wiki#default-svgo-configuration)

2
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{
"name": "@vkl/svg-iconset-builder",
"version": "1.0.0",
"version": "1.0.2",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@@ -1,8 +1,9 @@
{
"name": "@vkl/svg-iconset-builder",
"version": "1.0.0",
"version": "1.0.2",
"description": "create iconset from separated svg icons",
"main": "./dist/app.js",
"types": "./dist/app.d.ts",
"scripts": {
"build": "tsc",
"prepare": "npm run build",

View File

@@ -30,7 +30,6 @@ export class SvgIconset {
svgClean(this.config.source, this.svgoPlugin)
.then(optimizedResponse => {
let idx = 0;
const ids = optimizedResponse.map(el => el.id);
Promise.all(optimizedResponse.map(el => el.optimized))
.then(resFiles => {
@@ -38,9 +37,8 @@ export class SvgIconset {
createWriteStream(resultFile)
.once('open', function (this: WriteStream) {
try {
const data = resFiles.map(res => res.data.replace(/<svg /, `<svg id="${ids[idx]}" `));
const data = resFiles.map((res, idx) => res.data.replace(/<svg /, `<svg id="${ids[idx]}" `));
this.write(`<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">${data.join('')}</svg>`);
idx++;
this.end();
} catch (err) {
console.log('ERROR', err);