Skip to content

Commit f892f0d

Browse files
committed
fix(ticker): treat empty NO_COLOR as color-enabled per no-color.org
1 parent 87aefba commit f892f0d

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/lib/ticker.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,14 +273,15 @@ describe('createTicker — NO_COLOR support', () => {
273273
});
274274

275275
describe('isNoColor', () => {
276-
it('returns true when NO_COLOR is present in env', () => {
277-
expect(isNoColor({ NO_COLOR: '' })).toBe(true);
276+
it('returns true when NO_COLOR is set to a non-empty value', () => {
278277
expect(isNoColor({ NO_COLOR: '1' })).toBe(true);
279278
expect(isNoColor({ NO_COLOR: 'true' })).toBe(true);
280279
});
281280

282-
it('returns false when NO_COLOR is not present in env', () => {
281+
it('returns false when NO_COLOR is absent or empty', () => {
283282
expect(isNoColor({})).toBe(false);
284283
expect(isNoColor({ OTHER_VAR: '1' })).toBe(false);
284+
// Per https://no-color.org/, an empty NO_COLOR does NOT disable color.
285+
expect(isNoColor({ NO_COLOR: '' })).toBe(false);
285286
});
286287
});

src/lib/ticker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ export interface Ticker {
3333
* an empty string, per https://no-color.org/.
3434
*/
3535
export function isNoColor(env: NodeJS.ProcessEnv = process.env): boolean {
36-
return 'NO_COLOR' in env;
36+
const value = env.NO_COLOR;
37+
return typeof value === 'string' && value.length > 0;
3738
}
3839

3940
/**

0 commit comments

Comments
 (0)