Socket
Socket
Sign inDemoInstall

loader-utils

Package Overview
Dependencies
3
Maintainers
2
Versions
47
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.0.1

6

lib/getOptions.js

@@ -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);

2

package.json
{
"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 }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc