Content-Length: 348330 | pFad | https://snyk.io/redirect/github/chalk/chalk/commit/0d2144904b9b5769076106aa67583273e160f801

60AB check parent builder object for enabled status (#142) · chalk/chalk@0d21449 · GitHub
Skip to content

Commit 0d21449

Browse files
authored
check parent builder object for enabled status (#142)
1 parent 5a69476 commit 0d21449

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

index.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,20 @@ function build(_styles) {
3636
return applyStyle.apply(builder, arguments);
3737
};
3838

39+
var self = this;
40+
3941
builder._styles = _styles;
40-
builder.enabled = this.enabled;
42+
43+
Object.defineProperty(builder, 'enabled', {
44+
enumerable: true,
45+
get: function () {
46+
return self.enabled;
47+
},
48+
set: function (v) {
49+
self.enabled = v;
50+
}
51+
});
52+
4153
// __proto__ is used because we must return a function, but there is
4254
// no way to create a function with a different prototype.
4355
/* eslint-disable no-proto */

test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,28 @@ describe('chalk.enabled', function () {
138138
assert.equal(chalk.red('foo'), 'foo');
139139
chalk.enabled = true;
140140
});
141+
142+
it('should enable/disable colors based on overall chalk enabled property, not individual instances', function () {
143+
chalk.enabled = true;
144+
var red = chalk.red;
145+
assert.equal(red.enabled, true);
146+
chalk.enabled = false;
147+
assert.equal(red.enabled, chalk.enabled);
148+
chalk.enabled = true;
149+
});
150+
151+
it('should propagate enable/disable changes from child colors', function () {
152+
chalk.enabled = true;
153+
var red = chalk.red;
154+
assert.equal(red.enabled, true);
155+
assert.equal(chalk.enabled, true);
156+
red.enabled = false;
157+
assert.equal(red.enabled, false);
158+
assert.equal(chalk.enabled, false);
159+
chalk.enabled = true;
160+
assert.equal(red.enabled, true);
161+
assert.equal(chalk.enabled, true);
162+
});
141163
});
142164

143165
describe('chalk.constructor', function () {

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://snyk.io/redirect/github/chalk/chalk/commit/0d2144904b9b5769076106aa67583273e160f801

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy