Skip to content

Commit 8bcde17

Browse files
Yanis Bensonsindresorhus
authored andcommitted
Hide prefixText when it's an empty string (#124)
1 parent b653b5a commit 8bcde17

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

index.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ declare namespace ora {
2525
readonly text?: string;
2626

2727
/**
28-
Text to display before the spinner.
28+
Text to display before the spinner. No prefix text will be displayed if set to empty string.
2929
*/
3030
readonly prefixText?: string;
3131

@@ -105,7 +105,7 @@ declare namespace ora {
105105
readonly text?: string;
106106

107107
/**
108-
Text to be persisted before the symbol. Default: Current `prefixText`.
108+
Text to be persisted before the symbol. No prefix text will be displayed if set to empty string. Default: Current `prefixText`.
109109
*/
110110
readonly prefixText?: string;
111111
}
@@ -122,7 +122,7 @@ declare namespace ora {
122122
text: string;
123123

124124
/**
125-
Change the text before the spinner.
125+
Change the text before the spinner. No prefix text will be displayed if set to empty string.
126126
*/
127127
prefixText: string;
128128

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class Ora {
120120
}
121121

122122
this.frameIndex = ++this.frameIndex % frames.length;
123-
const fullPrefixText = typeof this.prefixText === 'string' ? this.prefixText + ' ' : '';
123+
const fullPrefixText = (typeof this.prefixText === 'string' && this.prefixText !== '') ? this.prefixText + ' ' : '';
124124
const fullText = typeof this.text === 'string' ? ' ' + this.text : '';
125125

126126
return fullPrefixText + frame + fullText;
@@ -211,7 +211,7 @@ class Ora {
211211

212212
stopAndPersist(options = {}) {
213213
const prefixText = options.prefixText || this.prefixText;
214-
const fullPrefixText = (typeof prefixText === 'string') ? prefixText + ' ' : '';
214+
const fullPrefixText = (typeof prefixText === 'string' && prefixText !== '') ? prefixText + ' ' : '';
215215
const text = options.text || this.text;
216216
const fullText = (typeof text === 'string') ? ' ' + text : '';
217217

readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Text to display after the spinner.
5151

5252
Type: `string`
5353

54-
Text to display before the spinner.
54+
Text to display before the spinner. No prefix text will be displayed if set to empty string.
5555

5656
##### spinner
5757

@@ -174,7 +174,7 @@ Text to be persisted after the symbol
174174
Type: `string`<br>
175175
Default: Current `prefixText`
176176

177-
Text to be persisted before the symbol.
177+
Text to be persisted before the symbol. No prefix text will be displayed if set to empty string.
178178

179179
<img src="screenshot-2.gif" width="480">
180180

@@ -196,7 +196,7 @@ Change the text after the spinner.
196196

197197
#### .prefixText
198198

199-
Change the text before the spinner.
199+
Change the text before the spinner. No prefix text will be displayed if set to empty string.
200200

201201
#### .color
202202

test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,14 @@ test('.stopAndPersist() with prefixText', macro, spinner => {
332332
spinner.stopAndPersist({symbol: '@', text: 'foo'});
333333
}, /bar @ foo\n$/, {prefixText: 'bar'});
334334

335+
test('.stopAndPersist() with empty prefixText', macro, spinner => {
336+
spinner.stopAndPersist({symbol: '@', text: 'foo'});
337+
}, /@ foo\n$/, {prefixText: ''});
338+
335339
test('.stopAndPersist() with manual prefixText', macro, spinner => {
336340
spinner.stopAndPersist({symbol: '@', prefixText: 'baz', text: 'foo'});
337341
}, /baz @ foo\n$/, {prefixText: 'bar'});
342+
343+
test('.stopAndPersist() with manual empty prefixText', macro, spinner => {
344+
spinner.stopAndPersist({symbol: '@', prefixText: '', text: 'foo'});
345+
}, /@ foo\n$/, {prefixText: 'bar'});

0 commit comments

Comments
 (0)