Skip to content

Commit 8ee129c

Browse files
authored
chore: update createMatcher types (#49)
1 parent d7e8e22 commit 8ee129c

4 files changed

Lines changed: 27 additions & 17 deletions

File tree

examples/append/src/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
const fs = require('fs');
2-
const posthtml = require('posthtml');
3-
const { insertAt } = require('posthtml-insert-at');
1+
const fs = require("fs");
2+
const posthtml = require("posthtml");
3+
const { insertAt } = require("posthtml-insert-at");
44

5-
const html = fs.readFileSync('./src/index.html');
5+
const html = fs.readFileSync("./src/index.html");
66

77
posthtml()
88
.use(
99
insertAt({
10-
selector: '.foo',
10+
selector: ".foo",
1111
append: `
1212
<footer id="footer">
1313
&copy; ${new Date().getFullYear()}
1414
</footer>
1515
`,
16-
behavior: 'outside'
16+
behavior: "outside",
1717
})
1818
)
1919
.process(html)
20-
.then(result => fs.writeFileSync('./src/after.html', result.html));
20+
.then((result) => fs.writeFileSync("./src/after.html", result.html));

examples/prepend/src/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
const fs = require('fs');
2-
const posthtml = require('posthtml');
3-
const { insertAt } = require('posthtml-insert-at');
1+
const fs = require("fs");
2+
const posthtml = require("posthtml");
3+
const { insertAt } = require("posthtml-insert-at");
44

5-
const html = fs.readFileSync('./src/index.html');
5+
const html = fs.readFileSync("./src/index.html");
66

77
posthtml()
88
.use(
99
insertAt({
10-
selector: 'main',
10+
selector: "main",
1111
prepend: `
1212
<header>
1313
<a href="/">Home</a>
1414
</header>
1515
`,
16-
behavior: 'outside'
16+
behavior: "outside",
1717
})
1818
)
1919
.process(html)
20-
.then(result => fs.writeFileSync('./src/after.html', result.html));
20+
.then((result) => fs.writeFileSync("./src/after.html", result.html));

src/global.d.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
declare module "posthtml-match-helper" {
2-
function createMatcher(matcher: string | string[]): string[];
3-
export default createMatcher;
2+
interface Matcher {
3+
tag?: string;
4+
attrs: {
5+
id?: string;
6+
class?: RegExp;
7+
[attr: string]: any;
8+
};
9+
}
10+
11+
export default function createMatcher(
12+
matcher: string | string[]
13+
): Matcher | Matcher[];
414
}

src/insertAt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function insertAt(options: Options) {
3333

3434
const matchingNode = siblingNode as PostHTML.Node["content"];
3535

36-
tree.match({ content: [matcher] }, (node) =>
36+
tree.match({ content: [matcher as PostHTML.ContentMatcher] }, (node) =>
3737
insertNode({ node, option, content: [matchingNode] })
3838
);
3939
}

0 commit comments

Comments
 (0)