UNPKG

1.01 kBJavaScriptView Raw
1'use-strict'
2
3// attribute - whitelist attributes
4
5module.exports = attribute
6
7function href (attributes) {
8 return attributes.href || attributes.url
9}
10
11function Enclosure (attributes) {
12 this.url = href(attributes)
13 this.length = attributes.length
14 this.type = attributes.type
15}
16function enclosure (key, attributes) {
17 return [key, new Enclosure(attributes)]
18}
19
20function link (key, attributes) {
21 const rel = attributes.rel
22 if (key === 'enclosure' || rel === 'enclosure') {
23 return enclosure('enclosure', attributes)
24 }
25 if (rel && rel !== 'alternate' && rel !== 'payment') return
26 if (rel === 'payment') key = rel
27 if (key === 'link' || key === 'payment') {
28 const uri = href(attributes)
29 return [key, uri]
30 }
31}
32
33function image (key, attributes) {
34 return [key, href(attributes)]
35}
36
37const handlers = {
38 link: link,
39 image: image,
40 enclosure: enclosure
41}
42
43function attribute (key, attributes) {
44 if (handlers.hasOwnProperty(key)) {
45 return handlers[key](key, attributes)
46 }
47}