Skip to content

Commit 7721afd

Browse files
committed
feat: add types
1 parent 20e866d commit 7721afd

File tree

2 files changed

+134
-0
lines changed

2 files changed

+134
-0
lines changed

lib/index.d.ts

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
import type {StringifyOptions} from 'query-string';
2+
3+
export type URLParametersConfig = {
4+
/**
5+
Object containing parameter name (key) and its value.
6+
7+
@default undefined
8+
9+
@example
10+
```
11+
import posthtml from 'posthtml'
12+
import urlParams from 'posthtml-url-parameters'
13+
14+
posthtml([
15+
urlParams({
16+
parameters: {
17+
foo: 'bar'
18+
}
19+
})
20+
])
21+
.process('<a href="https://example.com">Test</a>')
22+
.then(result => result.html)
23+
```
24+
*/
25+
parameters: Record<string, string>;
26+
27+
/**
28+
Array of tag names to process.
29+
30+
By default, only URLs inside known attributes of tags in this array will be processed.
31+
32+
@default ['a']
33+
34+
@example
35+
```
36+
import posthtml from 'posthtml'
37+
import urlParams from 'posthtml-url-parameters'
38+
39+
posthtml([
40+
urlParams({
41+
parameters: {
42+
foo: 'bar'
43+
},
44+
tags: ['a', 'img']
45+
})
46+
])
47+
.process(`
48+
<a href="https://example.com">Test</a>
49+
<img src="https://example.com/image.jpg">
50+
`)
51+
.then(result => result.html)
52+
```
53+
*/
54+
tags?: string[];
55+
56+
/**
57+
Array of attributes to process for the given tags.
58+
59+
You may override this with your own list of attributes - the plugin will only process URLs in _these_ attributes.
60+
61+
@default ['href', 'src', 'poster', 'srcset', 'background']
62+
63+
@example
64+
```
65+
import posthtml from 'posthtml'
66+
import urlParams from 'posthtml-url-parameters'
67+
68+
posthtml([
69+
urlParams({
70+
parameters: {
71+
foo: 'bar'
72+
},
73+
attributes: ['data-href']
74+
})
75+
])
76+
.process('<a href="foo.html" data-href="https://example.com">Test</a>')
77+
.then(result => result.html)
78+
```
79+
*/
80+
attributes?: string[];
81+
82+
/**
83+
By default, query parameters are appended only to valid URLs.
84+
85+
Disable strict mode to append parameters to any string.
86+
87+
@default true
88+
89+
@example
90+
```
91+
import posthtml from 'posthtml'
92+
import urlParams from 'posthtml-url-parameters'
93+
94+
posthtml([
95+
urlParams({
96+
parameters: {
97+
foo: 'bar'
98+
},
99+
strict: false
100+
})
101+
])
102+
.process('<a href="example.html">Test</a>')
103+
.then(result => result.html)
104+
```
105+
*/
106+
strict?: boolean;
107+
108+
/**
109+
Options to pass to the `query-string` library.
110+
111+
@default undefined
112+
113+
@example
114+
```
115+
import posthtml from 'posthtml'
116+
import urlParams from 'posthtml-url-parameters'
117+
118+
posthtml([
119+
urlParams({
120+
parameters: {
121+
foo: '@Bar@'
122+
},
123+
qs: {
124+
encode: false
125+
}
126+
})
127+
])
128+
.process('<a href="https://example.com">Test</a>')
129+
.then(result => result.html)
130+
```
131+
*/
132+
qs?: StringifyOptions;
133+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"repository": "posthtml/posthtml-url-parameters",
1010
"type": "module",
1111
"exports": "./lib/index.js",
12+
"types": "./lib/index.d.ts",
1213
"files": [
1314
"lib"
1415
],

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy