@html-validate/plugin-utils 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -0
- package/dist/tsdoc-metadata.json +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,3 +1,51 @@
|
|
|
1
1
|
# @html-validate/plugin-utils`
|
|
2
2
|
|
|
3
3
|
Plugin utilities and helpers for writing plugins to HTML-Validate
|
|
4
|
+
|
|
5
|
+
## API
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { Source } from "html-validate";
|
|
9
|
+
|
|
10
|
+
export interface Position {
|
|
11
|
+
column: number;
|
|
12
|
+
line: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function positionFromOffset(text: string, offset: number): [line: number, column: number];
|
|
16
|
+
|
|
17
|
+
export function positionToOffset(position: Position, data: string): number;
|
|
18
|
+
|
|
19
|
+
export class TemplateExtractor {
|
|
20
|
+
static fromString(source: string, filename?: string): TemplateExtractor;
|
|
21
|
+
extractObjectProperty(key: string): Source[];
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
### `TemplateExtractor`
|
|
28
|
+
|
|
29
|
+
Extracts HTML-snippets from Javascript based files.
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
/* javascript with HTML in the "template" property */
|
|
33
|
+
const sourceCode = `
|
|
34
|
+
export default {
|
|
35
|
+
template: "<p>lorem ipsum</i>",
|
|
36
|
+
}
|
|
37
|
+
`;
|
|
38
|
+
|
|
39
|
+
/* extract HTML snippets */
|
|
40
|
+
const templateExtractor = TemplateExtractor.fromString(sourceCode);
|
|
41
|
+
const snippets = templateExtractor.extractObjectProperty("template");
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Typically used in a transformation plugin to but it could also be validated directly:
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
for (const snippet of snippets) {
|
|
48
|
+
const result = htmlvalidate.validateSource(snippet);
|
|
49
|
+
console.log(result);
|
|
50
|
+
}
|
|
51
|
+
```
|
package/dist/tsdoc-metadata.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@html-validate/plugin-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Plugin utilities and helpers for writing plugins to HTML-Validate",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"html-validate"
|
|
@@ -26,13 +26,14 @@
|
|
|
26
26
|
},
|
|
27
27
|
"main": "dist/index.cjs.js",
|
|
28
28
|
"module": "dist/index.esm.js",
|
|
29
|
+
"types": "dist/index.d.ts",
|
|
29
30
|
"files": [
|
|
30
31
|
"dist"
|
|
31
32
|
],
|
|
32
33
|
"peerDependencies": {
|
|
33
34
|
"acorn-walk": "^8",
|
|
34
35
|
"espree": "^9",
|
|
35
|
-
"html-validate": "^5 || ^6 || ^7"
|
|
36
|
+
"html-validate": "^5 || ^6 || ^7 || ^8"
|
|
36
37
|
},
|
|
37
38
|
"engines": {
|
|
38
39
|
"node": ">= 16.0"
|