Skip to main content

validateURL()

This function is used to validate external CSS via a URL.

Options

You can customize the behavior with options, passed as the second argument.

OptionDefaultPossible values
mediumallall, braille, embossed, handheld, print, projection, screen, speech, tty, tv
warningLevel00, 1, 2, 3
timeout10000integer
OptionExplanation
mediumThe equivalent of the @media rule, applied to all of the CSS
warningLevel0 means don’t return any warnings; 1, 2, 3 will return warnings (if any), with higher numbers corresponding to more warnings
timeoutThe time in milliseconds after which the request to the W3C API will be terminated and an error will be thrown
const result = await cssValidator.validateURL(cssSourceURL, {
medium: 'print',
warningLevel: 3,
timeout: 3000,
});

Response structure

By default, the function returns a Promise, which resolves to an object that looks like:

{
valid: boolean;
errors: {
line: number;
message: string;
url: string | null;
}[];
}

If you ask it to return warnings via warningLevel, it will also include a warnings key:

{
...
warnings: {
line: number;
level: 1 | 2 | 3;
message: string;
url: string | null;
}[];
}