-
Notifications
You must be signed in to change notification settings - Fork 0
/
wcagify.js
36 lines (28 loc) · 819 Bytes
/
wcagify.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
34
35
36
const slugify = require('slugify')
const criteria = require('./criteria')
const wcagpath = 'https://www.w3.org/WAI/WCAG22/Understanding'
function wcagify (string) {
const notFound = new Error(`${string}: No WCAG reference found`)
const wcagMatch = string.match(/(\d*\.\d*\.\d*)/)
if (!wcagMatch) throw notFound
const ref = wcagMatch[1]
let name, slug, level, impacts
criteria.forEach(criterion => {
if (criterion.ref === ref) {
name = criterion.name
slug = slugify(criterion.name, { lower: true, strict: true })
level = criterion.level
impacts = criterion.impacts
}
})
if (name === undefined) throw notFound
return {
criterion: `${ref} ${name}`,
ref,
name,
link: `${wcagpath}/${slug}.html`,
level,
impacts
}
}
module.exports = wcagify