-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
46 lines (43 loc) · 1.19 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
module.exports = {
name: 'VueOxford',
render (h) {
let children = (this.$slots.default || []).filter(node => {
if (typeof node.text === 'string' && !node.text.trim()) return false
if (node.isComment) return false
return true
})
let components = []
if (children.length <= 1) {
components = children
} else if (children.length === 2) {
components = children.concat()
components.splice(1, 0, ' and ')
} else {
children.forEach((child, i) => {
if (i < children.length - 2) {
components.push(child, ', ')
} else if (i === children.length - 2) {
components.push(child, ', and ')
} else {
components.push(child)
}
})
}
return h('span', components)
}
}
module.exports.join = (strings=[], conjunction='and') => {
switch (strings.length) {
case 0: return ''
case 1: return strings[0] || ''
case 2: {
const [first, second] = strings
return `${first} ${conjunction} ${second}`
}
default: {
const start = strings.slice(0, -1)
const end = strings[strings.length - 1]
return `${start.join(', ')}, ${conjunction} ${end}`
}
}
}