.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / enquirer / lib / prompts / list.js
1 'use strict';
2
3 const StringPrompt = require('../types/string');
4
5 class ListPrompt extends StringPrompt {
6   constructor(options = {}) {
7     super(options);
8     this.sep = this.options.separator || /, */;
9     this.initial = options.initial || '';
10   }
11
12   split(input = this.value) {
13     return input ? String(input).split(this.sep) : [];
14   }
15
16   format() {
17     let style = this.state.submitted ? this.styles.primary : val => val;
18     return this.list.map(style).join(', ');
19   }
20
21   async submit(value) {
22     let result = this.state.error || await this.validate(this.list, this.state);
23     if (result !== true) {
24       this.state.error = result;
25       return super.submit();
26     }
27     this.value = this.list;
28     return super.submit();
29   }
30
31   get list() {
32     return this.split();
33   }
34 }
35
36 module.exports = ListPrompt;