1 | 'use-strict'
|
2 |
|
3 |
|
4 |
|
5 | module.exports = attribute
|
6 |
|
7 | function href (attributes) {
|
8 | return attributes.href || attributes.url
|
9 | }
|
10 |
|
11 | function Enclosure (attributes) {
|
12 | this.url = href(attributes)
|
13 | this.length = attributes.length
|
14 | this.type = attributes.type
|
15 | }
|
16 | function enclosure (key, attributes) {
|
17 | return [key, new Enclosure(attributes)]
|
18 | }
|
19 |
|
20 | function 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 |
|
33 | function image (key, attributes) {
|
34 | return [key, href(attributes)]
|
35 | }
|
36 |
|
37 | const handlers = {
|
38 | link: link,
|
39 | image: image,
|
40 | enclosure: enclosure
|
41 | }
|
42 |
|
43 | function attribute (key, attributes) {
|
44 | if (handlers.hasOwnProperty(key)) {
|
45 | return handlers[key](key, attributes)
|
46 | }
|
47 | }
|