Skip to content

Commit 47d0be7

Browse files
chore(deps): update
1 parent cc1e035 commit 47d0be7

29 files changed

+1779
-2841
lines changed

.eslintrc.json

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"root": true,
3-
"plugins": ["node", "prettier"],
3+
"plugins": ["node"],
44
"extends": ["eslint:recommended", "plugin:node/recommended"],
55
"env": {
66
"node": true
@@ -18,15 +18,6 @@
1818
"no-var": "error",
1919
"prefer-const": "error",
2020
"prefer-arrow-callback": "error",
21-
"object-shorthand": "error",
22-
23-
"prettier/prettier": [
24-
"error",
25-
{
26-
"singleQuote": true,
27-
"trailingComma": "es5",
28-
"arrowParens": "always"
29-
}
30-
]
21+
"object-shorthand": "error"
3122
}
3223
}

.prettierignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/coverage
2+
/dist
3+
/node_modules
4+
/test/fixtures
5+
CHANGELOG.md

.prettierrc

Lines changed: 0 additions & 5 deletions
This file was deleted.

.travis.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ cache: yarn
1313

1414
matrix:
1515
include:
16-
- node_js: '12'
16+
- node_js: "12"
1717
script: yarn pretest
1818
env: CI=pretest
19-
- node_js: '8'
19+
- node_js: "8"
2020
script: yarn test:ci
2121
env: CI=tests 8
22-
- node_js: '10'
22+
- node_js: "10"
2323
script: yarn test:ci
2424
env: CI=tests 10
25-
- node_js: '12'
25+
- node_js: "12"
2626
script: yarn test:ci
2727
env: CI=coverage 12
28-
- node_js: '13'
28+
- node_js: "13"
2929
script: yarn test:ci
3030
env: CI=coverage 13
3131

README.md

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@ const options = loaderUtils.getOptions(this);
1212
```
1313

1414
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
15+
- Tries to parse the query string and returns a new object
16+
- Throws if it's not a valid query string
1717
2. If `this.query` is object-like, it just returns `this.query`
1818
3. In any other case, it just returns `null`
1919

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:
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:
2222

2323
```javascript
2424
const options = Object.assign(
25-
{},
26-
defaultOptions,
27-
loaderUtils.getOptions(this) // it is safe to pass null to Object.assign()
25+
{},
26+
defaultOptions,
27+
loaderUtils.getOptions(this) // it is safe to pass null to Object.assign()
2828
);
2929
// don't forget nested objects or arrays
30-
options.obj = Object.assign({}, options.obj);
30+
options.obj = Object.assign({}, options.obj);
3131
options.arr = options.arr.slice();
3232
someLibrary(options);
3333
```
@@ -42,16 +42,16 @@ If the loader options have been passed as loader query string (`loader?some&para
4242

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

45-
``` javascript
45+
```javascript
4646
const params = loaderUtils.parseQuery(this.resourceQuery); // resource: `file?param1=foo`
4747
if (params.param1 === "foo") {
48-
// do something
48+
// do something
4949
}
5050
```
5151

5252
The string is parsed like this:
5353

54-
``` text
54+
```text
5555
-> Error
5656
? -> {}
5757
?flag -> { flag: true }
@@ -168,35 +168,39 @@ Interpolates a filename template using multiple placeholders and/or a regular ex
168168
The template and regular expression are set as query params called `name` and `regExp` on the current loader's context.
169169

170170
```javascript
171-
const interpolatedName = loaderUtils.interpolateName(loaderContext, name, options);
171+
const interpolatedName = loaderUtils.interpolateName(
172+
loaderContext,
173+
name,
174+
options
175+
);
172176
```
173177

174178
The following tokens are replaced in the `name` parameter:
175179

176-
* `[ext]` the extension of the resource
177-
* `[name]` the basename of the resource
178-
* `[path]` the path of the resource relative to the `context` query parameter or option.
179-
* `[folder]` the folder the resource is in
180-
* `[query]` the queryof the resource, i.e. `?foo=bar`
181-
* `[emoji]` a random emoji representation of `options.content`
182-
* `[emoji:<length>]` same as above, but with a customizable number of emojis
183-
* `[contenthash]` the hash of `options.content` (Buffer) (by default it's the hex digest of the md4 hash)
184-
* `[<hashType>:contenthash:<digestType>:<length>]` optionally one can configure
185-
* other `hashType`s, i. e. `sha1`, `md4`, `md5`, `sha256`, `sha512`
186-
* other `digestType`s, i. e. `hex`, `base26`, `base32`, `base36`, `base49`, `base52`, `base58`, `base62`, `base64`
187-
* and `length` the length in chars
188-
* `[hash]` the hash of `options.content` (Buffer) (by default it's the hex digest of the md4 hash)
189-
* `[<hashType>:hash:<digestType>:<length>]` optionally one can configure
190-
* other `hashType`s, i. e. `sha1`, `md4`, `md5`, `sha256`, `sha512`
191-
* other `digestType`s, i. e. `hex`, `base26`, `base32`, `base36`, `base49`, `base52`, `base58`, `base62`, `base64`
192-
* and `length` the length in chars
193-
* `[N]` the N-th match obtained from matching the current file name against `options.regExp`
180+
- `[ext]` the extension of the resource
181+
- `[name]` the basename of the resource
182+
- `[path]` the path of the resource relative to the `context` query parameter or option.
183+
- `[folder]` the folder the resource is in
184+
- `[query]` the queryof the resource, i.e. `?foo=bar`
185+
- `[emoji]` a random emoji representation of `options.content`
186+
- `[emoji:<length>]` same as above, but with a customizable number of emojis
187+
- `[contenthash]` the hash of `options.content` (Buffer) (by default it's the hex digest of the md4 hash)
188+
- `[<hashType>:contenthash:<digestType>:<length>]` optionally one can configure
189+
- other `hashType`s, i. e. `sha1`, `md4`, `md5`, `sha256`, `sha512`
190+
- other `digestType`s, i. e. `hex`, `base26`, `base32`, `base36`, `base49`, `base52`, `base58`, `base62`, `base64`
191+
- and `length` the length in chars
192+
- `[hash]` the hash of `options.content` (Buffer) (by default it's the hex digest of the md4 hash)
193+
- `[<hashType>:hash:<digestType>:<length>]` optionally one can configure
194+
- other `hashType`s, i. e. `sha1`, `md4`, `md5`, `sha256`, `sha512`
195+
- other `digestType`s, i. e. `hex`, `base26`, `base32`, `base36`, `base49`, `base52`, `base58`, `base62`, `base64`
196+
- and `length` the length in chars
197+
- `[N]` the N-th match obtained from matching the current file name against `options.regExp`
194198

195199
In loader context `[hash]` and `[contenthash]` are the same, but we recommend using `[contenthash]` for avoid misleading.
196200

197201
Examples
198202

199-
``` javascript
203+
```javascript
200204
// loaderContext.resourcePath = "/absolute/path/to/app/js/javascript.js"
201205
loaderUtils.interpolateName(loaderContext, "js/[hash].script.[ext]", { content: ... });
202206
// => js/9473fdd0d880a43c21b7778d34872157.script.js
@@ -247,28 +251,33 @@ loaderUtils.interpolateName(loaderContext, "script-[1].[ext]", { regExp: "page-(
247251
// loaderContext.resourcePath = "/absolute/path/to/app/js/javascript.js"
248252
// loaderContext.resourceQuery = "?foo=bar"
249253
loaderUtils.interpolateName(
250-
loaderContext,
251-
(resourcePath, resourceQuery) => {
254+
loaderContext,
255+
(resourcePath, resourceQuery) => {
252256
// resourcePath - `/app/js/javascript.js`
253257
// resourceQuery - `?foo=bar`
254258

255-
return "js/[hash].script.[ext]";
256-
},
259+
return "js/[hash].script.[ext]";
260+
},
257261
{ content: ... }
258262
);
259263
// => js/9473fdd0d880a43c21b7778d34872157.script.js
260264
```
261265

262266
### `getHashDigest`
263267

264-
``` javascript
265-
const digestString = loaderUtils.getHashDigest(buffer, hashType, digestType, maxLength);
268+
```javascript
269+
const digestString = loaderUtils.getHashDigest(
270+
buffer,
271+
hashType,
272+
digestType,
273+
maxLength
274+
);
266275
```
267276

268-
* `buffer` the content that should be hashed
269-
* `hashType` one of `sha1`, `md4`, `md5`, `sha256`, `sha512` or any other node.js supported hash type
270-
* `digestType` one of `hex`, `base26`, `base32`, `base36`, `base49`, `base52`, `base58`, `base62`, `base64`
271-
* `maxLength` the maximum length in chars
277+
- `buffer` the content that should be hashed
278+
- `hashType` one of `sha1`, `md4`, `md5`, `sha256`, `sha512` or any other node.js supported hash type
279+
- `digestType` one of `hex`, `base26`, `base32`, `base36`, `base49`, `base52`, `base58`, `base62`, `base64`
280+
- `maxLength` the maximum length in chars
272281

273282
## License
274283

appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ environment:
99

1010
clone_depth: 10
1111

12-
version: '{build}'
12+
version: "{build}"
1313
build: off
1414
deploy: off
1515

@@ -28,4 +28,4 @@ cache:
2828
test_script:
2929
- node --version
3030
- npm --version
31-
- cmd: 'yarn test:ci'
31+
- cmd: "yarn test:ci"

lib/getCurrentRequest.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'use strict';
1+
"use strict";
22

33
function getCurrentRequest(loaderContext) {
44
if (loaderContext.currentRequest) {
@@ -10,7 +10,7 @@ function getCurrentRequest(loaderContext) {
1010
.map((obj) => obj.request)
1111
.concat([loaderContext.resource]);
1212

13-
return request.join('!');
13+
return request.join("!");
1414
}
1515

1616
module.exports = getCurrentRequest;

lib/getHashDigest.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
'use strict';
1+
"use strict";
22

33
const baseEncodeTables = {
4-
26: 'abcdefghijklmnopqrstuvwxyz',
5-
32: '123456789abcdefghjkmnpqrstuvwxyz', // no 0lio
6-
36: '0123456789abcdefghijklmnopqrstuvwxyz',
7-
49: 'abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ', // no lIO
8-
52: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
9-
58: '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ', // no 0lIO
10-
62: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
11-
64: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_',
4+
26: "abcdefghijklmnopqrstuvwxyz",
5+
32: "123456789abcdefghjkmnpqrstuvwxyz", // no 0lio
6+
36: "0123456789abcdefghijklmnopqrstuvwxyz",
7+
49: "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ", // no lIO
8+
52: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
9+
58: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ", // no 0lIO
10+
62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
11+
64: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_",
1212
};
1313

1414
function encodeBufferToBase(buffer, base) {
1515
const encodeTable = baseEncodeTables[base];
1616
if (!encodeTable) {
17-
throw new Error('Unknown encoding base' + base);
17+
throw new Error("Unknown encoding base" + base);
1818
}
1919

2020
const readLength = buffer.length;
21-
const Big = require('big.js');
21+
const Big = require("big.js");
2222

2323
Big.RM = Big.DP = 0;
2424
let b = new Big(0);
@@ -27,7 +27,7 @@ function encodeBufferToBase(buffer, base) {
2727
b = b.times(256).plus(buffer[i]);
2828
}
2929

30-
let output = '';
30+
let output = "";
3131
while (b.gt(0)) {
3232
output = encodeTable[b.mod(base)] + output;
3333
b = b.div(base);
@@ -40,29 +40,29 @@ function encodeBufferToBase(buffer, base) {
4040
}
4141

4242
function getHashDigest(buffer, hashType, digestType, maxLength) {
43-
hashType = hashType || 'md4';
43+
hashType = hashType || "md4";
4444
maxLength = maxLength || 9999;
4545

46-
const hash = require('crypto').createHash(hashType);
46+
const hash = require("crypto").createHash(hashType);
4747

4848
hash.update(buffer);
4949

5050
if (
51-
digestType === 'base26' ||
52-
digestType === 'base32' ||
53-
digestType === 'base36' ||
54-
digestType === 'base49' ||
55-
digestType === 'base52' ||
56-
digestType === 'base58' ||
57-
digestType === 'base62' ||
58-
digestType === 'base64'
51+
digestType === "base26" ||
52+
digestType === "base32" ||
53+
digestType === "base36" ||
54+
digestType === "base49" ||
55+
digestType === "base52" ||
56+
digestType === "base58" ||
57+
digestType === "base62" ||
58+
digestType === "base64"
5959
) {
6060
return encodeBufferToBase(hash.digest(), digestType.substr(4)).substr(
6161
0,
6262
maxLength
6363
);
6464
} else {
65-
return hash.digest(digestType || 'hex').substr(0, maxLength);
65+
return hash.digest(digestType || "hex").substr(0, maxLength);
6666
}
6767
}
6868

lib/getOptions.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
'use strict';
1+
"use strict";
22

3-
const parseQuery = require('./parseQuery');
3+
const parseQuery = require("./parseQuery");
44

55
function getOptions(loaderContext) {
66
const query = loaderContext.query;
77

8-
if (typeof query === 'string' && query !== '') {
8+
if (typeof query === "string" && query !== "") {
99
return parseQuery(loaderContext.query);
1010
}
1111

12-
if (!query || typeof query !== 'object') {
12+
if (!query || typeof query !== "object") {
1313
// Not object-like queries are not supported.
1414
return {};
1515
}

lib/getRemainingRequest.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'use strict';
1+
"use strict";
22

33
function getRemainingRequest(loaderContext) {
44
if (loaderContext.remainingRequest) {
@@ -10,7 +10,7 @@ function getRemainingRequest(loaderContext) {
1010
.map((obj) => obj.request)
1111
.concat([loaderContext.resource]);
1212

13-
return request.join('!');
13+
return request.join("!");
1414
}
1515

1616
module.exports = getRemainingRequest;

0 commit comments

Comments
 (0)