|
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') |
0 commit comments