Skip to content

Commit 3bfb169

Browse files
refactor!: remove getOptions in favor loaderContext.getOptions (loaderContext is this inside loader function), note - special query parameters like ?something=true is not supported, if you need this please do it on loader side, but we strongly recommend avoid it, as alternative you can use ?something=1 and handle 1 as true in loader
1 parent 09128d7 commit 3bfb169

File tree

4 files changed

+0
-136
lines changed

4 files changed

+0
-136
lines changed

README.md

-32
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,6 @@
22

33
## Methods
44

5-
### `getOptions`
6-
7-
Recommended way to retrieve the options of a loader invocation:
8-
9-
```javascript
10-
// inside your loader
11-
const options = loaderUtils.getOptions(this);
12-
```
13-
14-
1. If `this.query` is a string:
15-
- Tries to parse the query string and returns a new object
16-
- Throws if it's not a valid query string
17-
2. If `this.query` is object-like, it just returns `this.query`
18-
3. In any other case, it just returns `null`
19-
20-
**Please note:** The returned `options` object is _read-only_. It may be re-used across multiple invocations.
21-
If you pass it on to another library, make sure to make a _deep copy_ of it:
22-
23-
```javascript
24-
const options = Object.assign(
25-
{},
26-
defaultOptions,
27-
loaderUtils.getOptions(this) // it is safe to pass null to Object.assign()
28-
);
29-
// don't forget nested objects or arrays
30-
options.obj = Object.assign({}, options.obj);
31-
options.arr = options.arr.slice();
32-
someLibrary(options);
33-
```
34-
35-
[clone](https://www.npmjs.com/package/clone) is a good library to make a deep copy of the options.
36-
375
#### Options as query strings
386

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

lib/getOptions.js

-20
This file was deleted.

lib/index.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"use strict";
22

3-
const getOptions = require("./getOptions");
43
const parseQuery = require("./parseQuery");
54
const stringifyRequest = require("./stringifyRequest");
65
const isUrlRequest = require("./isUrlRequest");
@@ -9,7 +8,6 @@ const parseString = require("./parseString");
98
const getHashDigest = require("./getHashDigest");
109
const interpolateName = require("./interpolateName");
1110

12-
exports.getOptions = getOptions;
1311
exports.parseQuery = parseQuery;
1412
exports.stringifyRequest = stringifyRequest;
1513
exports.isUrlRequest = isUrlRequest;

test/getOptions.test.js

-82
This file was deleted.

0 commit comments

Comments
 (0)