Socket
Socket
Sign inDemoInstall

chalk

Package Overview
Dependencies
6
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.4.0 to 0.5.0

59

index.js
'use strict';
var ansi = require('ansi-styles');
var escapeStringRegexp = require('escape-string-regexp');
var ansiStyles = require('ansi-styles');
var stripAnsi = require('strip-ansi');
var hasColor = require('has-color');
var hasAnsi = require('has-ansi');
var supportsColor = require('supports-color');
var defineProps = Object.defineProperties;

@@ -11,5 +13,7 @@ var chalk = module.exports;

ansi.grey = ansi.gray;
ansiStyles.grey = ansiStyles.gray;
Object.keys(ansi).forEach(function (key) {
Object.keys(ansiStyles).forEach(function (key) {
ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
ret[key] = {

@@ -26,2 +30,23 @@ get: function () {

function applyStyle() {
// support varags, but simply cast to string in case there's only one arg
var str = arguments.length === 1 ? String(arguments[0]) : [].slice.call(arguments).join(' ');
if (!chalk.enabled || !str) {
return str;
}
var nestedStyles = applyStyle._styles;
for (var i = 0; i < nestedStyles.length; i++) {
var code = ansiStyles[nestedStyles[i]];
// Replace any instances already present with a re-opening code
// otherwise only the part of the string until said closing code
// will be colored, and the rest will simply be 'plain'.
str = code.open + str.replace(code.closeRe, code.open) + code.close;
}
return str;
}
function init() {

@@ -31,22 +56,9 @@ var ret = {};

Object.keys(styles).forEach(function (name) {
var style = defineProps(applyStyle, styles);
ret[name] = {
get: function () {
var obj = defineProps(function self() {
var str = [].slice.call(arguments).join(' ');
if (!chalk.enabled) {
return str;
}
return self._styles.reduce(function (str, name) {
var code = ansi[name];
return str ? code.open + str + code.close : '';
}, str);
}, styles);
obj._styles = [];
return obj[name];
style._styles = [];
return style[name];
}
}
};
});

@@ -59,5 +71,6 @@

chalk.styles = ansi;
chalk.styles = ansiStyles;
chalk.hasColor = hasAnsi;
chalk.stripColor = stripAnsi;
chalk.supportsColor = hasColor;
chalk.supportsColor = supportsColor;

@@ -64,0 +77,0 @@ // detect mode if not set manually

{
"name": "chalk",
"version": "0.4.0",
"version": "0.5.0",
"description": "Terminal string styling done right. Created because the `colors` module does some really horrible things.",
"license": "MIT",
"repository": "sindresorhus/chalk",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "http://sindresorhus.com"
},
"maintainers": [
"Sindre Sorhus <sindresorhus@gmail.com> (http://sindresorhus.com)",
"Joshua Appelman <joshua@jbna.nl>"
],
"engines": {
"node": ">=0.8.0"
"node": ">=0.10.0"
},
"scripts": {
"test": "mocha"
"test": "mocha",
"bench": "matcha benchmark.js"
},

@@ -43,9 +43,12 @@ "files": [

"dependencies": {
"has-color": "~0.1.0",
"ansi-styles": "~1.0.0",
"strip-ansi": "~0.1.0"
"ansi-styles": "^1.1.0",
"escape-string-regexp": "^1.0.0",
"has-ansi": "^0.1.0",
"strip-ansi": "^0.3.0",
"supports-color": "^0.2.0"
},
"devDependencies": {
"mocha": "~1.x"
"matcha": "^0.5.0",
"mocha": "*"
}
}

@@ -1,6 +0,7 @@

# <img width="250" src="logo.png" alt="chalk">
# <img width="300" src="https://cdn.rawgit.com/sindresorhus/chalk/77ae94f63ab1ac61389b190e5a59866569d1a376/logo.svg" alt="chalk">
> Terminal string styling done right
[![Build Status](https://secure.travis-ci.org/sindresorhus/chalk.png?branch=master)](http://travis-ci.org/sindresorhus/chalk)
[![Build Status](https://travis-ci.org/sindresorhus/chalk.svg?branch=master)](https://travis-ci.org/sindresorhus/chalk)
![](http://img.shields.io/badge/unicorn-approved-ff69b4.svg)

@@ -11,3 +12,3 @@ [colors.js](https://github.com/Marak/colors.js) is currently the most popular string styling module, but it has serious deficiencies like extending String.prototype which causes all kinds of [problems](https://github.com/yeoman/yo/issues/68). Although there are other ones, they either do too much or not enough.

![screenshot](screenshot.png)
![screenshot](https://github.com/sindresorhus/ansi-styles/raw/master/screenshot.png)

@@ -17,8 +18,10 @@

- **Doesn't extend String.prototype**
- Highly performant
- Doesn't extend String.prototype
- Expressive API
- Ability to nest styles
- Clean and focused
- Auto-detects color support
- Actively maintained
- [Used by 150+ modules](https://npmjs.org/browse/depended/chalk)
- [Used by 1000+ modules](https://npmjs.org/browse/depended/chalk)

@@ -28,6 +31,8 @@

Install with [npm](https://npmjs.org/package/chalk): `npm install --save chalk`
```sh
$ npm install --save chalk
```
## Example
## Usage

@@ -48,10 +53,13 @@ Chalk comes with an easy to use composable API where you just chain and nest the styles you want.

// pass in multiple arguments
console.log( chalk.blue('Hello', 'World!', 'Foo', 'bar', 'biz', 'baz') );
// nest styles
console.log( chalk.red('Hello', chalk.underline.bgBlue('world') + '!') );
// pass in multiple arguments
console.log( chalk.blue('Hello', 'World!', 'Foo', 'bar', 'biz', 'baz') );
// nest styles of the same type even (color, underline, background)
console.log( chalk.green('I am a green line ' + chalk.blue('with a blue substring') + ' that becomes green again!') );
```
You can easily define your own themes.
Easily define your own themes.

@@ -64,3 +72,11 @@ ```js

Take advantage of console.log [string substitution](http://nodejs.org/docs/latest/api/console.html#console_console_log_data).
```js
var name = 'Sindre';
console.log(chalk.green('Hello %s'), name);
//=> Hello Sindre
```
## API

@@ -82,3 +98,3 @@

Detect whether the terminal [supports color](https://github.com/sindresorhus/has-color).
Detect whether the terminal [supports color](https://github.com/sindresorhus/supports-color).

@@ -99,3 +115,3 @@ Can be overridden by the user with the flags `--color` and `--no-color`.

console.log(chalk.styles.red);
//=> {open: '\x1b[31m', close: '\x1b[39m'}
//=> {open: '\u001b[31m', close: '\u001b[39m'}

@@ -105,2 +121,6 @@ console.log(chalk.styles.red.open + 'Hello' + chalk.styles.red.close);

### chalk.hasColor(string)
Check whether a string [has color](https://github.com/sindresorhus/has-ansi).
### chalk.stripColor(string)

@@ -116,6 +136,6 @@

var chalk = require('chalk');
var styledString = fromExternal();
var styledString = getText();
if (!chalk.supportsColor) {
chalk.stripColor(styledString);
styledString = chalk.stripColor(styledString);
}

@@ -129,31 +149,33 @@ ```

- reset
- bold
- italic
- underline
- inverse
- strikethrough
- `reset`
- `bold`
- `dim`
- `italic` *(not widely supported)*
- `underline`
- `inverse`
- `hidden`
- `strikethrough` *(not widely supported)*
### Text colors
- black
- red
- green
- yellow
- blue
- magenta
- cyan
- white
- gray
- `black`
- `red`
- `green`
- `yellow`
- `blue`
- `magenta`
- `cyan`
- `white`
- `gray`
### Background colors
- bgBlack
- bgRed
- bgGreen
- bgYellow
- bgBlue
- bgMagenta
- bgCyan
- bgWhite
- `bgBlack`
- `bgRed`
- `bgGreen`
- `bgYellow`
- `bgBlue`
- `bgMagenta`
- `bgCyan`
- `bgWhite`

@@ -164,6 +186,1 @@

MIT © [Sindre Sorhus](http://sindresorhus.com)
-
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/sindresorhus/chalk/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc