forked from orbit-oss/chalk
various tweaks
This commit is contained in:
parent
fa9bd4ebd9
commit
cf7eb2d0c7
6 changed files with 43 additions and 26 deletions
2
.gitattributes
vendored
2
.gitattributes
vendored
|
|
@ -1 +1 @@
|
|||
* text eol=lf
|
||||
* text=auto
|
||||
|
|
|
|||
|
|
@ -7,14 +7,10 @@
|
|||
"eqeqeq": true,
|
||||
"immed": true,
|
||||
"indent": 4,
|
||||
"latedef": true,
|
||||
"newcap": true,
|
||||
"noarg": true,
|
||||
"quotmark": "single",
|
||||
"regexp": true,
|
||||
"undef": true,
|
||||
"unused": true,
|
||||
"strict": true,
|
||||
"trailing": true,
|
||||
"smarttabs": true
|
||||
"unused": "vars",
|
||||
"strict": true
|
||||
}
|
||||
|
|
|
|||
10
index.js
10
index.js
|
|
@ -1,5 +1,5 @@
|
|||
'use strict';
|
||||
var ansi = require('ansi-styles');
|
||||
var ansiStyles = require('ansi-styles');
|
||||
var stripAnsi = require('strip-ansi');
|
||||
var hasColor = require('has-color');
|
||||
var defineProps = Object.defineProperties;
|
||||
|
|
@ -8,9 +8,9 @@ var chalk = module.exports;
|
|||
var styles = (function () {
|
||||
var ret = {};
|
||||
|
||||
ansi.grey = ansi.gray;
|
||||
ansiStyles.grey = ansiStyles.gray;
|
||||
|
||||
Object.keys(ansi).forEach(function (key) {
|
||||
Object.keys(ansiStyles).forEach(function (key) {
|
||||
ret[key] = {
|
||||
get: function () {
|
||||
this._styles.push(key);
|
||||
|
|
@ -36,7 +36,7 @@ function init() {
|
|||
}
|
||||
|
||||
return self._styles.reduce(function (str, name) {
|
||||
var code = ansi[name];
|
||||
var code = ansiStyles[name];
|
||||
return str ? code.open + str + code.close : '';
|
||||
}, str);
|
||||
}, styles);
|
||||
|
|
@ -53,7 +53,7 @@ function init() {
|
|||
|
||||
defineProps(chalk, init());
|
||||
|
||||
chalk.styles = ansi;
|
||||
chalk.styles = ansiStyles;
|
||||
chalk.stripColor = stripAnsi;
|
||||
chalk.supportsColor = hasColor;
|
||||
|
||||
|
|
|
|||
21
license
Normal file
21
license
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
```sh
|
||||
$ npm install --save chalk
|
||||
```
|
||||
|
||||
|
|
@ -100,7 +100,7 @@ Generally not useful, but you might need just the `.open` or `.close` escape cod
|
|||
var chalk = require('chalk');
|
||||
|
||||
console.log(chalk.styles.red);
|
||||
//=> {open: '\x1b[31m', close: '\x1b[39m'}
|
||||
//=> {open: '\u001b[31m', close: '\u001b[39m'}
|
||||
|
||||
console.log(chalk.styles.red.open + 'Hello' + chalk.styles.red.close);
|
||||
```
|
||||
|
|
@ -162,4 +162,4 @@ if (!chalk.supportsColor) {
|
|||
|
||||
## License
|
||||
|
||||
[MIT](http://opensource.org/licenses/MIT) © [Sindre Sorhus](http://sindresorhus.com)
|
||||
MIT © [Sindre Sorhus](http://sindresorhus.com)
|
||||
|
|
|
|||
22
test.js
22
test.js
|
|
@ -4,37 +4,37 @@ var chalk = require('./index');
|
|||
|
||||
describe('chalk', function () {
|
||||
it('should style string', function () {
|
||||
assert.equal(chalk.underline('foo'), '\x1b[4mfoo\x1b[24m');
|
||||
assert.equal(chalk.red('foo'), '\x1b[31mfoo\x1b[39m');
|
||||
assert.equal(chalk.bgRed('foo'), '\x1b[41mfoo\x1b[49m');
|
||||
assert.equal(chalk.underline('foo'), '\u001b[4mfoo\u001b[24m');
|
||||
assert.equal(chalk.red('foo'), '\u001b[31mfoo\u001b[39m');
|
||||
assert.equal(chalk.bgRed('foo'), '\u001b[41mfoo\u001b[49m');
|
||||
});
|
||||
|
||||
it('should support applying multiple styles at once', function () {
|
||||
assert.equal(chalk.red.bgGreen.underline('foo'), '\x1b[4m\x1b[42m\x1b[31mfoo\x1b[39m\x1b[49m\x1b[24m');
|
||||
assert.equal(chalk.underline.red.bgGreen('foo'), '\x1b[42m\x1b[31m\x1b[4mfoo\x1b[24m\x1b[39m\x1b[49m');
|
||||
assert.equal(chalk.red.bgGreen.underline('foo'), '\u001b[4m\u001b[42m\u001b[31mfoo\u001b[39m\u001b[49m\u001b[24m');
|
||||
assert.equal(chalk.underline.red.bgGreen('foo'), '\u001b[42m\u001b[31m\u001b[4mfoo\u001b[24m\u001b[39m\u001b[49m');
|
||||
});
|
||||
|
||||
it('should support nesting styles', function () {
|
||||
assert.equal(
|
||||
chalk.red('foo' + chalk.underline.bgBlue('bar') + '!'),
|
||||
'\x1b[31mfoo\x1b[44m\x1b[4mbar\x1b[24m\x1b[49m!\x1b[39m'
|
||||
'\u001b[31mfoo\u001b[44m\u001b[4mbar\u001b[24m\u001b[49m!\u001b[39m'
|
||||
);
|
||||
});
|
||||
|
||||
it('should reset all styles with `.reset()`', function () {
|
||||
assert.equal(chalk.reset(chalk.red.bgGreen.underline('foo') + 'foo'), '\x1b[0m\x1b[4m\x1b[42m\x1b[31mfoo\x1b[39m\x1b[49m\x1b[24mfoo\x1b[0m');
|
||||
assert.equal(chalk.reset(chalk.red.bgGreen.underline('foo') + 'foo'), '\u001b[0m\u001b[4m\u001b[42m\u001b[31mfoo\u001b[39m\u001b[49m\u001b[24mfoo\u001b[0m');
|
||||
});
|
||||
|
||||
it('should alias gray to grey', function () {
|
||||
assert.equal(chalk.grey('foo'), '\x1b[90mfoo\x1b[39m');
|
||||
assert.equal(chalk.grey('foo'), '\u001b[90mfoo\u001b[39m');
|
||||
});
|
||||
|
||||
it('should support variable number of arguments', function () {
|
||||
assert.equal(chalk.red('foo', 'bar'), '\x1b[31mfoo bar\x1b[39m');
|
||||
assert.equal(chalk.red('foo', 'bar'), '\u001b[31mfoo bar\u001b[39m');
|
||||
});
|
||||
|
||||
it('should support falsy values', function () {
|
||||
assert.equal(chalk.red(0), '\x1b[31m0\x1b[39m');
|
||||
assert.equal(chalk.red(0), '\u001b[31m0\u001b[39m');
|
||||
});
|
||||
|
||||
it('don\'t output escape codes if the input is empty', function () {
|
||||
|
|
@ -52,7 +52,7 @@ describe('chalk.enabled', function () {
|
|||
|
||||
describe('chalk.styles', function () {
|
||||
it('should expose the styles as ANSI escape codes', function () {
|
||||
assert.equal(chalk.styles.red.open, '\x1b[31m');
|
||||
assert.equal(chalk.styles.red.open, '\u001b[31m');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue