Skip to content

Commit 5d0c8e0

Browse files
author
Eduardo García Sanz
committed
accepting configuration...
1 parent 9de53bf commit 5d0c8e0

2 files changed

Lines changed: 33 additions & 12 deletions

File tree

index.js

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
var through = require('through'),
2+
extend = require('extend'),
23
SVGO = require('svgo'),
34
react = require('react-tools');
45

6+
var svgo = new SVGO();
7+
8+
var settings = {
9+
react: {
10+
es5 : true,
11+
sourceMap : false,
12+
stripTypes: false,
13+
harmony : false
14+
},
15+
svgo: {}
16+
};
17+
518
var isSVG = function (filename) {
619

720
return (/\.svg$/i).test(filename);
821
};
922

10-
var svgo = new SVGO();
11-
12-
module.exports = function (filename) {
23+
var transform = function (filename) {
1324

1425
var write = function (buffer) {
1526

@@ -24,13 +35,7 @@ module.exports = function (filename) {
2435
var out = function (svg) {
2536

2637
var source = "var React = require('react');module.exports = React.createClass({render: function () { return (" + svg.data + "); }});",
27-
output = react.transform(source, {
28-
es5 : true,
29-
sourceMap : false,
30-
sourceFilename: filename,
31-
stripTypes : false,
32-
harmony : false
33-
});
38+
output = react.transform(source, settings.react);
3439

3540
stream.queue(output);
3641
stream.queue(null);
@@ -41,3 +46,18 @@ module.exports = function (filename) {
4146

4247
return stream;
4348
};
49+
50+
module.exports = function (a) {
51+
52+
if (typeof a === 'string' || a instanceof String) {
53+
54+
return transform(a);
55+
}
56+
57+
extend(settings.react, a.react);
58+
extend(settings.svgo, a.svgo);
59+
60+
svgo = new SVGO(settings.svgo);
61+
62+
return transform;
63+
};

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"homepage" : "https://github.com/coma/svg-reactify",
55
"repository" : "https://github.com/coma/svg-reactify",
66
"main" : "./index.js",
7-
"version" : "0.2.0",
7+
"version" : "0.3.0",
88
"license" : "MIT",
99
"private" : false,
1010
"authors" : [
@@ -19,7 +19,8 @@
1919
"dependencies" : {
2020
"through" : "^2.3",
2121
"react-tools": "^0.13",
22-
"svgo" : "^0.5"
22+
"svgo" : "^0.5",
23+
"extend" : "^2"
2324
},
2425
"devDependencies": {},
2526
"scripts" : {},

0 commit comments

Comments
 (0)