-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
101 lines (84 loc) · 2.15 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
'use strict';
var debug = require('debug')('choices-separator');
var strip = require('strip-color');
var dim = require('ansi-dim');
/**
* Separator object, used in choices arrays in prompts, to
* create a visual break between sections. The default separator
* line is `────────` styled with [ansi-dim].
*
* ```js
* new Separator('----');
* new Separator({line: '----'})
* new Separator({line: '----', prefix: ' '});
* ```
* @param {String} `options` Optionally provide a custom `line` and or `prefix` to use.
* @api public
*/
function Separator(options) {
debug('initializing from <%s>', __filename);
this.isSeparator = true;
this.type = 'separator';
if (typeof options === 'string') {
options = { line: options };
}
this.options = options || {};
this.prefix = ' ';
if (typeof this.options.prefix === 'string') {
this.prefix = this.options.prefix;
}
if (typeof this.options.line === 'string') {
this.line = this.options.line;
} else {
this.line = dim('────────');
}
}
/**
* Returns the `separator.line` stripped of ansi styling.
*
* ```js
* var separator = new Separator();
* console.log(separator.raw());
* //=> '────────'
* ```
* @return {String}
* @api public
*/
Separator.prototype.raw = function() {
return strip(this.line);
};
/**
* Render `separator.prefix` plus `separator.line`.
*
* ```js
* var separator = new Separator();
* console.log(separator.render());
* //=> ' \u001b[2m────────\u001b[22m\n')
* ```
* @return {String}
* @api public
*/
Separator.prototype.render = function() {
return this.prefix + this.line + '\n';
};
/**
* Returns false if the given object is a separator.
* @param {Object} `choice` object to test against
* @return {Boolean} Returns false if the given object is a separator
* @api public
*/
Separator.exclude = function(choice) {
return choice.type !== 'separator';
};
/**
* Stringify separator
* @return {String} Returns the `separator.line` string
* @api public
*/
Separator.prototype.toString = function() {
return this.line;
};
/**
* Expose `Separator`
*/
module.exports = Separator;