loader-utils
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -7,5 +7,9 @@ "use strict"; | ||
const query = loaderContext.query; | ||
if(typeof query === "string") { | ||
if(typeof query === "string" && query !== "") { | ||
return parseQuery(loaderContext.query); | ||
} | ||
if(!query || typeof query !== "object") { | ||
// Not object-like queries are not supported. | ||
return null; | ||
} | ||
return query; | ||
@@ -12,0 +16,0 @@ } |
@@ -16,2 +16,5 @@ "use strict"; | ||
query = query.substr(1); | ||
if(!query) { | ||
return {}; | ||
} | ||
if(query.substr(0, 1) === "{" && query.substr(-1) === "}") { | ||
@@ -18,0 +21,0 @@ return JSON5.parse(query); |
{ | ||
"name": "loader-utils", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"author": "Tobias Koppers @sokra", | ||
@@ -5,0 +5,0 @@ "description": "utils for webpack loaders", |
@@ -14,2 +14,8 @@ # loader-utils | ||
1. If `this.query` is a string: | ||
- Tries to parse the query string and returns a new object | ||
- Throws if it's not a valid query string | ||
2. If `this.query` is object-like, it just returns `this.query` | ||
3. In any other case, it just returns `null` | ||
**Please note:** The returned `options` object is *read-only*. It may be re-used across multiple invocations. | ||
@@ -19,3 +25,7 @@ If you pass it on to another library, make sure to make a *deep copy* of it: | ||
```javascript | ||
const options = Object.assign({}, loaderUtils.getOptions(this)); | ||
const options = Object.assign( | ||
{}, | ||
loaderUtils.getOptions(this), // it is safe to pass null to Object.assign() | ||
defaultOptions | ||
); | ||
// don't forget nested objects or arrays | ||
@@ -27,3 +37,3 @@ options.obj = Object.assign({}, options.obj); | ||
[assign-deep](https://www.npmjs.com/package/assign-deep) is a good library to make a deep copy of the options. | ||
[clone-deep](https://www.npmjs.com/package/clone-deep) is a good library to make a deep copy of the options. | ||
@@ -35,3 +45,3 @@ #### Options as query strings | ||
``` text | ||
null -> {} | ||
-> null | ||
? -> {} | ||
@@ -42,3 +52,3 @@ ?flag -> { flag: true } | ||
?xyz=test -> { xyz: "test" } | ||
?xyz=1 -> { xyz: "1" } | ||
?xyz=1 -> { xyz: "1" } // numbers are NOT parsed | ||
?xyz[]=a -> { xyz: ["a"] } | ||
@@ -45,0 +55,0 @@ ?flag1&flag2 -> { flag1: true, flag2: true } |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
21857
348
217
0