Skip to content

Commit 4adfdc3

Browse files
committed
added docs
1 parent ab5d5c0 commit 4adfdc3

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

website/docs/functions/validate-url.md

+54-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,57 @@
22
title: validateURL()
33
---
44

5-
Interested in this capability? Help us bring it into existence by submitting a PR! https://github.com/sparksuite/w3c-css-validator/issues/31
5+
This function is used to validate external CSS via a URL.
6+
7+
## Options
8+
9+
You can customize the behavior with options, passed as the second argument.
10+
11+
Option | Default | Possible values
12+
:--- | :--- | :---
13+
`medium` | `all` | `all`, `braille`, `embossed`, `handheld`, `print`, `projection`, `screen`, `speech`, `tty`, `tv`
14+
`warningLevel` | `0` | `0`, `1`, `2`, `3`
15+
`timeout` | `10000` | `integer`
16+
17+
Option | Explanation
18+
:--- | :---
19+
`medium` | The equivalent of the `@media` rule, applied to all of the CSS
20+
`warningLevel` | `0` means don’t return any warnings; `1`, `2`, `3` will return warnings (if any), with higher numbers corresponding to more warnings
21+
`timeout` | The time in milliseconds after which the request to the W3C API will be terminated and an error will be thrown
22+
23+
```ts
24+
const result = await cssValidator.validateURL(cssSourceURL, {
25+
medium: 'print',
26+
warningLevel: 3,
27+
timeout: 3000,
28+
});
29+
```
30+
31+
## Response structure
32+
33+
By default, the function returns a Promise, which resolves to an object that looks like:
34+
35+
```ts
36+
{
37+
valid: boolean;
38+
errors: {
39+
line: number;
40+
message: string;
41+
url: string | null;
42+
}[];
43+
}
44+
```
45+
46+
If you ask it to return warnings via `warningLevel`, it will also include a `warnings` key:
47+
48+
```ts
49+
{
50+
...
51+
warnings: {
52+
line: number;
53+
level: 1 | 2 | 3;
54+
message: string;
55+
url: string | null;
56+
}[];
57+
}
58+
```

0 commit comments

Comments
 (0)