Skip to content

Commit

Permalink
refactor!: remove getOptions in favor loaderContext.getOptions (`…
Browse files Browse the repository at this point in the history
…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`
  • Loading branch information
alexander-akait committed Oct 20, 2021
1 parent 09128d7 commit 3bfb169
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 136 deletions.
32 changes: 0 additions & 32 deletions README.md
Expand Up @@ -2,38 +2,6 @@

## Methods

### `getOptions`

Recommended way to retrieve the options of a loader invocation:

```javascript
// inside your loader
const options = loaderUtils.getOptions(this);
```

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.
If you pass it on to another library, make sure to make a _deep copy_ of it:

```javascript
const options = Object.assign(
{},
defaultOptions,
loaderUtils.getOptions(this) // it is safe to pass null to Object.assign()
);
// don't forget nested objects or arrays
options.obj = Object.assign({}, options.obj);
options.arr = options.arr.slice();
someLibrary(options);
```

[clone](https://www.npmjs.com/package/clone) is a good library to make a deep copy of the options.

#### Options as query strings

If the loader options have been passed as loader query string (`loader?some&params`), the string is parsed by using [`parseQuery`](#parsequery).
Expand Down
20 changes: 0 additions & 20 deletions lib/getOptions.js

This file was deleted.

2 changes: 0 additions & 2 deletions lib/index.js
@@ -1,6 +1,5 @@
"use strict";

const getOptions = require("./getOptions");
const parseQuery = require("./parseQuery");
const stringifyRequest = require("./stringifyRequest");
const isUrlRequest = require("./isUrlRequest");
Expand All @@ -9,7 +8,6 @@ const parseString = require("./parseString");
const getHashDigest = require("./getHashDigest");
const interpolateName = require("./interpolateName");

exports.getOptions = getOptions;
exports.parseQuery = parseQuery;
exports.stringifyRequest = stringifyRequest;
exports.isUrlRequest = isUrlRequest;
Expand Down
82 changes: 0 additions & 82 deletions test/getOptions.test.js

This file was deleted.

0 comments on commit 3bfb169

Please sign in to comment.