Skip to content

Commit c4ebb6a

Browse files
docs(readme): add types (#424)
1 parent 677b98e commit c4ebb6a

File tree

1 file changed

+95
-18
lines changed

1 file changed

+95
-18
lines changed

README.md

Lines changed: 95 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,38 @@ module.exports = {
6262

6363
## Options
6464

65-
| Name | Type | Default | Description |
66-
| :---------------------------------: | :-----------------: | :------------------------------------------: | :----------------------------------------------- |
67-
| **[`sources`](#sources)** | `{Boolean\|Object}` | `true` | Enables/Disables sources handling |
68-
| **[`preprocessor`](#preprocessor)** | `{Function}` | `undefined` | Allows pre-processing of content before handling |
69-
| **[`minimize`](#minimize)** | `{Boolean\|Object}` | `true` in production mode, otherwise `false` | Tell `html-loader` to minimize HTML |
70-
| **[`esModule`](#esmodule)** | `{Boolean}` | `true` | Enable/disable ES modules syntax |
65+
- **[`sources`](#sources)**
66+
- **[`preprocessor`](#preprocessor)**
67+
- **[`minimize`](#minimize)**
68+
- **[`esModule`](#esmodule)**
7169

7270
### `sources`
7371

74-
Type: `Boolean|Object`
72+
Type:
73+
74+
```ts
75+
type sources =
76+
| boolean
77+
| {
78+
list?: Array<{
79+
tag?: string;
80+
attribute?: string;
81+
type?: string;
82+
filter?: (
83+
tag: string,
84+
attribute: string,
85+
attributes: string,
86+
resourcePath: string
87+
) => boolean;
88+
}>;
89+
urlFilter?: (
90+
attribute: string,
91+
value: string,
92+
resourcePath: string
93+
) => boolean;
94+
};
95+
```
96+
7597
Default: `true`
7698

7799
By default every loadable attributes (for example - `<img src="image.png">`) is imported (`const img = require('./image.png')` or `import img from "./image.png""`).
@@ -102,7 +124,7 @@ Supported tags and attributes:
102124
- the `content` attribute of the `meta` tag when the `name` attribute is `msapplication-tileimage`, `msapplication-square70x70logo`, `msapplication-square150x150logo`, `msapplication-wide310x150logo`, `msapplication-square310x310logo`, `msapplication-config`, `twitter:image` or when the `property` attribute is `og:image`, `og:image:url`, `og:image:secure_url`, `og:audio`, `og:audio:secure_url`, `og:video`, `og:video:secure_url`, `vk:image` or when the `itemprop` attribute is `image`, `logo`, `screenshot`, `thumbnailurl`, `contenturl`, `downloadurl`, `duringmedia`, `embedurl`, `installurl`, `layoutimage`
103125
- the `icon-uri` value component in `content` attribute of the `meta` tag when the `name` attribute is `msapplication-task`
104126

105-
#### `Boolean`
127+
#### `boolean`
106128

107129
The `true` value enables processing of all default elements and attributes, the `false` disable processing of all attributes.
108130

@@ -125,7 +147,7 @@ module.exports = {
125147
};
126148
```
127149

128-
#### `Object`
150+
#### `object`
129151

130152
Allows you to specify which tags and attributes to process, filter them, filter urls and process sources starts with `/`.
131153

@@ -177,7 +199,22 @@ module.exports = {
177199

178200
#### `list`
179201

180-
Type: `Array`
202+
Type:
203+
204+
```ts
205+
type list = Array<{
206+
tag?: string;
207+
attribute?: string;
208+
type?: string;
209+
filter?: (
210+
tag: string,
211+
attribute: string,
212+
attributes: string,
213+
resourcePath: string
214+
) => boolean;
215+
}>;
216+
```
217+
181218
Default: [supported tags and attributes](#sources).
182219

183220
Allows to setup which tags and attributes to process and how, and the ability to filter some of them.
@@ -366,7 +403,16 @@ module.exports = {
366403

367404
#### `urlFilter`
368405

369-
Type: `Function`
406+
Type:
407+
408+
```ts
409+
type urlFilter = (
410+
attribute: string,
411+
value: string,
412+
resourcePath: string
413+
) => boolean;
414+
```
415+
370416
Default: `undefined`
371417

372418
Allow to filter urls. All filtered urls will not be resolved (left in the code as they were written).
@@ -402,7 +448,15 @@ module.exports = {
402448

403449
### `preprocessor`
404450

405-
Type: `Function`
451+
Type:
452+
453+
```ts
454+
type preprocessor = (
455+
content: string | Buffer,
456+
loaderContext: LoaderContext
457+
) => HTMLElement;
458+
```
459+
406460
Default: `undefined`
407461

408462
Allows pre-processing of content before handling.
@@ -418,9 +472,9 @@ Allows pre-processing of content before handling.
418472
<div>
419473
```
420474

421-
#### `Function`
475+
#### `function`
422476

423-
You can set the `preprocessor` option as a `Function` instance.
477+
You can set the `preprocessor` option as a `function` instance.
424478

425479
**webpack.config.js**
426480

@@ -498,12 +552,30 @@ module.exports = {
498552

499553
### `minimize`
500554

501-
Type: `Boolean|Object`
555+
Type:
556+
557+
```ts
558+
type minimize =
559+
| boolean
560+
| {
561+
caseSensitive?: boolean;
562+
collapseWhitespace?: boolean;
563+
conservativeCollapse?: boolean;
564+
keepClosingSlash?: boolean;
565+
minifyCSS?: boolean;
566+
minifyJS?: boolean;
567+
removeComments?: boolean;
568+
removeRedundantAttributes?: boolean;
569+
removeScriptTypeAttributes?: boolean;
570+
removeStyleLinkTypeAttributes?: boolean;
571+
};
572+
```
573+
502574
Default: `true` in production mode, otherwise `false`
503575

504576
Tell `html-loader` to minimize HTML.
505577

506-
#### `Boolean`
578+
#### `boolean`
507579

508580
The enabled rules for minimizing by default are the following ones:
509581

@@ -540,7 +612,7 @@ module.exports = {
540612
};
541613
```
542614

543-
#### `Object`
615+
#### `object`
544616

545617
**webpack.config.js**
546618

@@ -597,7 +669,12 @@ module.exports = {
597669

598670
### `esModule`
599671

600-
Type: `Boolean`
672+
Type:
673+
674+
```ts
675+
type esModule = boolean;
676+
```
677+
601678
Default: `true`
602679

603680
By default, `html-loader` generates JS modules that use the ES modules syntax.

0 commit comments

Comments
 (0)