-
-
Notifications
You must be signed in to change notification settings - Fork 862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecate chalk.constructor()
in favor of new chalk.Instance()
#322
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8cb6c68
Add ChalkClass
tom-sherman ed509bc
Add chalk factory method
tom-sherman f66f1c0
Update readme to include chalk.instance instead of constructor
tom-sherman 438f326
Replace Chalk.constructor() with deprecation error
tom-sherman 08f9e5f
Update type definitions
tom-sherman 6768476
Add tests
tom-sherman cf981e6
Fix code style. Only new-cap linting errors remain
tom-sherman bb16265
Change to capital case Instance
tom-sherman 39037cb
Wording changes
tom-sherman fc50493
Update error message
tom-sherman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -140,12 +140,12 @@ Multiple arguments will be separated by space. | |||||
|
||||||
Color support is automatically detected, as is the level (see `chalk.level`). However, if you'd like to simply enable/disable Chalk, you can do so via the `.enabled` property. When `chalk.enabled` is `true`, `chalk.level` must *also* be greater than `0` for colored output to be produced. | ||||||
|
||||||
Chalk is enabled by default unless explicitly disabled via the constructor or `chalk.level` is `0`. | ||||||
Chalk is enabled by default unless explicitly disabled via `Chalk.Instance()` or `chalk.level` is `0`. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
If you need to change this in a reusable module, create a new instance: | ||||||
|
||||||
```js | ||||||
const ctx = new chalk.constructor({enabled: false}); | ||||||
const ctx = new chalk.Instance({enabled: false}); | ||||||
``` | ||||||
|
||||||
### chalk.level | ||||||
|
@@ -155,7 +155,7 @@ Color support is automatically detected, but you can override it by setting the | |||||
If you need to change this in a reusable module, create a new instance: | ||||||
|
||||||
```js | ||||||
const ctx = new chalk.constructor({level: 0}); | ||||||
const ctx = new chalk.Instance({level: 0}); | ||||||
``` | ||||||
|
||||||
Levels are as follows: | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,15 @@ | ||
import test from 'ava'; | ||
|
||
// Spoof supports-color | ||
require('./_supports-color')(__dirname); | ||
|
||
const chalk = require('..'); | ||
|
||
test('create an isolated context where colors can be disabled (by level)', t => { | ||
const instance = new chalk.constructor({level: 0, enabled: true}); | ||
t.is(instance.red('foo'), 'foo'); | ||
t.is(chalk.red('foo'), '\u001B[31mfoo\u001B[39m'); | ||
instance.level = 2; | ||
t.is(instance.red('foo'), '\u001B[31mfoo\u001B[39m'); | ||
}); | ||
test('Chalk.constructor should throw an expected error', t => { | ||
const expectedError = t.throws(() => { | ||
chalk.constructor(); | ||
}); | ||
|
||
test('create an isolated context where colors can be disabled (by enabled flag)', t => { | ||
const instance = new chalk.constructor({enabled: false}); | ||
t.is(instance.red('foo'), 'foo'); | ||
t.is(chalk.red('foo'), '\u001B[31mfoo\u001B[39m'); | ||
instance.enabled = true; | ||
t.is(instance.red('foo'), '\u001B[31mfoo\u001B[39m'); | ||
}); | ||
|
||
test('the `level` option should be a number from 0 to 3', t => { | ||
/* eslint-disable no-new */ | ||
t.throws(() => { | ||
new chalk.constructor({level: 10}); | ||
}, /should be an integer from 0 to 3/); | ||
t.is(expectedError.message, 'Chalk.constructor() is deprecated. Use new Chalk.Instance() instead.'); | ||
|
||
t.throws(() => { | ||
new chalk.constructor({level: -1}); | ||
}, /should be an integer from 0 to 3/); | ||
/* eslint-enable no-new */ | ||
new chalk.constructor(); // eslint-disable-line no-new | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import test from 'ava'; | ||
|
||
// Spoof supports-color | ||
require('./_supports-color')(__dirname); | ||
|
||
const chalk = require('..'); | ||
|
||
test('create an isolated context where colors can be disabled (by level)', t => { | ||
const instance = new chalk.Instance({level: 0, enabled: true}); | ||
t.is(instance.red('foo'), 'foo'); | ||
t.is(chalk.red('foo'), '\u001B[31mfoo\u001B[39m'); | ||
instance.level = 2; | ||
t.is(instance.red('foo'), '\u001B[31mfoo\u001B[39m'); | ||
}); | ||
|
||
test('create an isolated context where colors can be disabled (by enabled flag)', t => { | ||
const instance = new chalk.Instance({enabled: false}); | ||
t.is(instance.red('foo'), 'foo'); | ||
t.is(chalk.red('foo'), '\u001B[31mfoo\u001B[39m'); | ||
instance.enabled = true; | ||
t.is(instance.red('foo'), '\u001B[31mfoo\u001B[39m'); | ||
}); | ||
|
||
test('the `level` option should be a number from 0 to 3', t => { | ||
/* eslint-disable no-new */ | ||
t.throws(() => { | ||
new chalk.Instance({level: 10}); | ||
}, /should be an integer from 0 to 3/); | ||
|
||
t.throws(() => { | ||
new chalk.Instance({level: -1}); | ||
}, /should be an integer from 0 to 3/); | ||
/* eslint-enable no-new */ | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.