From cf7eb2d0c7ac20ad6864773451dd59210e7a4612 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Wed, 4 Jun 2014 01:43:07 +0200 Subject: [PATCH] various tweaks --- .gitattributes | 2 +- .jshintrc | 8 ++------ index.js | 10 +++++----- license | 21 +++++++++++++++++++++ readme.md | 6 +++--- test.js | 22 +++++++++++----------- 6 files changed, 43 insertions(+), 26 deletions(-) create mode 100644 license diff --git a/.gitattributes b/.gitattributes index fcadb2c..176a458 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1 @@ -* text eol=lf +* text=auto diff --git a/.jshintrc b/.jshintrc index ac35c13..c511975 100644 --- a/.jshintrc +++ b/.jshintrc @@ -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 } diff --git a/index.js b/index.js index 1a8d3f5..1cc7434 100644 --- a/index.js +++ b/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; diff --git a/license b/license new file mode 100644 index 0000000..654d0bf --- /dev/null +++ b/license @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) Sindre Sorhus (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. diff --git a/readme.md b/readme.md index e1eb086..7841d1b 100644 --- a/readme.md +++ b/readme.md @@ -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) diff --git a/test.js b/test.js index 6434156..c65e55b 100644 --- a/test.js +++ b/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'); }); });