Skip to content
This repository was archived by the owner on Mar 17, 2021. It is now read-only.

Commit ced5990

Browse files
michael-ciniawskyjoshwiens
authored andcommittedJun 13, 2017
feat(index): add options validation (schema-utils) (#78)
1 parent 5574ed3 commit ced5990

File tree

3 files changed

+48
-19
lines changed

3 files changed

+48
-19
lines changed
 

‎index.js

+21-16
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,37 @@
33
Author Tobias Koppers @sokra
44
*/
55
var loaderUtils = require("loader-utils");
6+
var validateOptions = require("schema-utils");
7+
68
var mime = require("mime");
79

810
module.exports = function(content) {
9-
this.cacheable && this.cacheable();
11+
this.cacheable && this.cacheable();
1012

11-
var options = loaderUtils.getOptions(this) || {};
12-
// Options `dataUrlLimit` is backward compatibility with first loader versions
13-
var limit = options.limit || (this.options && this.options.url && this.options.url.dataUrlLimit);
13+
var options = loaderUtils.getOptions(this) || {};
1414

15-
if(limit) {
16-
limit = parseInt(limit, 10);
17-
}
15+
validateOptions(require("./options"), options, "URL Loader")
16+
// Options `dataUrlLimit` is backward compatibility with first loader versions
17+
var limit = options.limit || (this.options && this.options.url && this.options.url.dataUrlLimit);
1818

19-
var mimetype = options.mimetype || options.minetype || mime.lookup(this.resourcePath);
19+
if(limit) {
20+
limit = parseInt(limit, 10);
21+
}
2022

21-
// No limits or limit more than content length
22-
if(!limit || content.length < limit) {
23-
if(typeof content === "string") {
24-
content = new Buffer(content);
25-
}
26-
return "module.exports = " + JSON.stringify("data:" + (mimetype ? mimetype + ";" : "") + "base64," + content.toString("base64"));
23+
var mimetype = options.mimetype || options.minetype || mime.lookup(this.resourcePath);
24+
25+
// No limits or limit more than content length
26+
if(!limit || content.length < limit) {
27+
if(typeof content === "string") {
28+
content = new Buffer(content);
2729
}
2830

29-
var fileLoader = require("file-loader");
31+
return "module.exports = " + JSON.stringify("data:" + (mimetype ? mimetype + ";" : "") + "base64," + content.toString("base64"));
32+
}
33+
34+
var fileLoader = require("file-loader");
3035

31-
return fileLoader.call(this, content);
36+
return fileLoader.call(this, content);
3237
}
3338

3439
module.exports.raw = true;

‎options.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"limit": {
5+
"type": "number"
6+
},
7+
"prefix": {
8+
"type": "string"
9+
},
10+
"mimetype": {
11+
"type": "string"
12+
},
13+
"encoding": {
14+
"type": "string"
15+
}
16+
},
17+
"additionalProperties": false
18+
}

‎package.json

+9-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
},
1010
"dependencies": {
1111
"loader-utils": "^1.0.2",
12-
"mime": "1.3.x"
12+
"mime": "^1.3.6",
13+
"schema-utils": "^0.3.0"
1314
},
1415
"devDependencies": {
1516
"standard-version": "^4.0.0"
@@ -19,6 +20,11 @@
1920
},
2021
"repository": {
2122
"type": "git",
22-
"url": "git@github.com:webpack/url-loader.git"
23-
}
23+
"url": "git+https://github.com/webpack-contrib/url-loader.git"
24+
},
25+
"bugs": {
26+
"url": "https://github.com/webpack-contrib/url-loader/issues"
27+
},
28+
"homepage": "https://github.com/webpack-contrib/url-loader",
29+
"license": "MIT"
2430
}

0 commit comments

Comments
 (0)
This repository has been archived.