Skip to content

Commit

Permalink
refactor!: parseString was removed in favor `new URLSearchParams(lo…
Browse files Browse the repository at this point in the history
…aderContext.resourceQuery.slice(1))` where `loaderContext` is `this` in loader function
  • Loading branch information
alexander-akait committed Oct 20, 2021
1 parent 246e345 commit e31e8b5
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 182 deletions.
30 changes: 0 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,6 @@

If the loader options have been passed as loader query string (`loader?some&params`), the string is parsed by using [`parseQuery`](#parsequery).

### `parseQuery`

Parses a passed string (e.g. `loaderContext.resourceQuery`) as a query string, and returns an object.

```javascript
const params = loaderUtils.parseQuery(this.resourceQuery); // resource: `file?param1=foo`

if (params.param1 === "foo") {
// do something
}
```

The string is parsed like this:

```text
-> Error
? -> {}
?flag -> { flag: true }
?+flag -> { flag: true }
?-flag -> { flag: false }
?xyz=test -> { xyz: "test" }
?xyz=1 -> { xyz: "1" } // numbers are NOT parsed
?xyz[]=a -> { xyz: ["a"] }
?flag1&flag2 -> { flag1: true, flag2: true }
?+flag1,-flag2 -> { flag1: true, flag2: false }
?xyz[]=a,xyz[]=b -> { xyz: ["a", "b"] }
?a%2C%26b=c%2C%26d -> { "a,&b": "c,&d" }
?{data:{a:1},isJSON5:true} -> { data: { a: 1 }, isJSON5: true }
```

### `urlToRequest`

Converts some resource URL to a webpack module request.
Expand Down
2 changes: 0 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
"use strict";

const parseQuery = require("./parseQuery");
const urlToRequest = require("./urlToRequest");
const getHashDigest = require("./getHashDigest");
const interpolateName = require("./interpolateName");

exports.parseQuery = parseQuery;
exports.urlToRequest = urlToRequest;
exports.getHashDigest = getHashDigest;
exports.interpolateName = interpolateName;
69 changes: 0 additions & 69 deletions lib/parseQuery.js

This file was deleted.

81 changes: 0 additions & 81 deletions test/parseQuery.test.js

This file was deleted.

0 comments on commit e31e8b5

Please sign in to comment.