Skip to content

Commit 51c30e5

Browse files
hanslvikerman
authored andcommitted
refactor(@angular/cli): refactor isTTY() function
It was really hard to read with double negatives and such.
1 parent 3aee401 commit 51c30e5

File tree

1 file changed

+9
-4
lines changed
  • packages/angular/cli/utilities

1 file changed

+9
-4
lines changed

packages/angular/cli/utilities/tty.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8+
9+
function _isTruthy(value: undefined | string): boolean {
10+
// Returns true if value is a string that is anything but 0 or false.
11+
return value !== undefined && value !== '0' && value.toUpperCase() !== 'FALSE';
12+
}
13+
814
export function isTTY(): boolean {
15+
// If we force TTY, we always return true.
916
const force = process.env['NG_FORCE_TTY'];
1017
if (force !== undefined) {
11-
return !(force === '0' || force.toUpperCase() === 'FALSE');
18+
return _isTruthy(force);
1219
}
1320

14-
const ci = process.env['CI'];
15-
16-
return !!process.stdout.isTTY && (!ci || ci === '0' || ci.toUpperCase() === 'FALSE');
21+
return !!process.stdout.isTTY && !_isTruthy(process.env['CI']);
1722
}

0 commit comments

Comments
 (0)