-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (35 loc) · 962 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
34
35
36
37
38
39
40
41
42
43
44
45
46
const cheerio = require('cheerio');
function createOrderedList(items, options = {}) {
const { class: className, id } = options;
const $ = cheerio.load('<ol></ol>');
const $list = $('ol');
if (className) {
$list.attr('class', className);
}
if (id) {
$list.attr('id', id);
}
items.forEach((item) => {
const $item = cheerio.load(`<li>${item}</li>`)('li');
$list.append($item);
});
return $.html('ol');
}
function createUnorderedList(items, options = {}) {
const { class: className, id } = options;
const $ = cheerio.load('<ul></ul>');
const $list = $('ul');
if (className) {
$list.attr('class', className);
}
if (id) {
$list.attr('id', id);
}
items.forEach((item) => {
const $item = cheerio.load(`<li>${item}</li>`)('li');
$list.append($item);
});
return $.html('ul');
}
module.exports.createOrderedList = createOrderedList;
module.exports.createUnorderedList = createUnorderedList;