Skip to content

Commit c6011d3

Browse files
authored
Merge pull request #315 from bhovhannes/improvements
Improvements
2 parents 39362ca + 90e1bdc commit c6011d3

File tree

7 files changed

+7876
-151
lines changed

7 files changed

+7876
-151
lines changed

index.js

+1-54
Original file line numberDiff line numberDiff line change
@@ -1,54 +1 @@
1-
/*
2-
* @license MIT http://www.opensource.org/licenses/mit-license.php
3-
* @author Hovhannes Babayan <bhovhannes at gmail dot com>
4-
*/
5-
var loaderUtils = require('loader-utils');
6-
7-
module.exports = function(content) {
8-
this.cacheable && this.cacheable();
9-
10-
var query = loaderUtils.getOptions(this) || {};
11-
query.encoding = query.encoding || "none";
12-
13-
var limit = query.limit ? parseInt(query.limit, 10) : 0;
14-
15-
if (limit <= 0 || content.length < limit) {
16-
var newContent = content.toString('utf8');
17-
18-
var hasStyleElement = /<style[\s\S]*?>[\s\S]*?<\/style>/i.test(newContent)
19-
20-
if (query.stripdeclarations) {
21-
newContent = newContent.replace(/^\s*<\?xml [^>]*>\s*/i, "");
22-
}
23-
24-
var data;
25-
if (query.encoding === "base64") {
26-
if (typeof newContent === "string") {
27-
newContent = new Buffer(newContent);
28-
}
29-
data = "data:image/svg+xml;base64," + newContent.toString("base64");
30-
} else {
31-
newContent = newContent.replace(/"/g, "'");
32-
newContent = newContent.replace(/\s+/g, " ");
33-
newContent = newContent.replace(/[{}\|\\\^~\[\]`"<>#%]/g, function(match) {
34-
return '%'+match[0].charCodeAt(0).toString(16).toUpperCase();
35-
});
36-
37-
data = 'data:image/svg+xml,' + newContent.trim();
38-
39-
}
40-
41-
if (!(query.iesafe && hasStyleElement && data.length > 4096)) {
42-
if (query.encoding === "none" && !query.noquotes) {
43-
data = '"'+data+'"';
44-
}
45-
46-
return 'module.exports = ' + JSON.stringify(data);
47-
}
48-
}
49-
50-
var fileLoader = require('file-loader');
51-
return fileLoader.call(this, content);
52-
};
53-
54-
module.exports.raw = true;
1+
module.exports = require('./src/loader')

jest.config.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
coverageDirectory: './coverage',
3+
coverageReporters: ['lcov', 'html', 'text-summary'],
4+
collectCoverageFrom: ['./src/**/*.js'],
5+
setupFilesAfterEnv: [
6+
'<rootDir>/test/setupFiles/timeout.js'
7+
]
8+
}

0 commit comments

Comments
 (0)