.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / remark-stringify / lib / visitors / list-item.js
1 'use strict';
2
3 var repeat = require('repeat-string');
4 var pad = require('../util/pad');
5
6 module.exports = listItem;
7
8 /* Which checkbox to use. */
9 var CHECKBOX_MAP = {
10   undefined: '',
11   null: '',
12   true: '[x] ',
13   false: '[ ] '
14 };
15
16 /* Stringify a list item.
17  *
18  * Prefixes the content with a checked checkbox when
19  * `checked: true`:
20  *
21  *     [x] foo
22  *
23  * Prefixes the content with an unchecked checkbox when
24  * `checked: false`:
25  *
26  *     [ ] foo
27  */
28 function listItem(node, parent, position, bullet) {
29   var self = this;
30   var style = self.options.listItemIndent;
31   var loose = node.loose;
32   var children = node.children;
33   var length = children.length;
34   var values = [];
35   var index = -1;
36   var value;
37   var indent;
38   var spacing;
39
40   while (++index < length) {
41     values[index] = self.visit(children[index], node);
42   }
43
44   value = CHECKBOX_MAP[node.checked] + values.join(loose ? '\n\n' : '\n');
45
46   if (style === '1' || (style === 'mixed' && value.indexOf('\n') === -1)) {
47     indent = bullet.length + 1;
48     spacing = ' ';
49   } else {
50     indent = Math.ceil((bullet.length + 1) / 4) * 4;
51     spacing = repeat(' ', indent - bullet.length);
52   }
53
54   value = bullet + spacing + pad(value, indent / 4).slice(indent);
55
56   if (loose && parent.children.length - 1 !== position) {
57     value += '\n';
58   }
59
60   return value;
61 }