-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
33 lines (28 loc) · 793 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const querystring = require('querystring')
const axios = require('axios')
const validUrl = require('valid-url')
const uri = 'https://achecker.ca/checkacc.php'
function makeUrl (options) {
const query = {
uri: options.uri,
id: options.id,
output: options.output || 'html',
guide: options.guide || 'WCAG2-AA',
offset: options.offset || 0
}
return `${uri}?${querystring.stringify(query)}`
}
module.exports = async function (options) {
if (!options.uri) {
throw new Error('Missing required param: uri')
}
if (options.uri && !validUrl.isWebUri(options.uri)) {
throw new Error('Invalid url')
}
if (!options.id) {
throw new Error('Missing required param: id')
}
const url = makeUrl(options)
const { data } = await axios(url)
return data
}