Comparing version 1.1.2 to 1.1.3
47
index.js
'use strict'; | ||
var escapeStringRegexp = require('escape-string-regexp'); | ||
var ansiStyles = require('ansi-styles'); | ||
var stripAnsi = require('strip-ansi'); | ||
var hasAnsi = require('has-ansi'); | ||
var supportsColor = require('supports-color'); | ||
@@ -18,14 +20,18 @@ var defineProps = Object.defineProperties; | ||
var styles = {}; | ||
var styles = (function () { | ||
var ret = {}; | ||
Object.keys(ansiStyles).forEach(function (key) { | ||
ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g'); | ||
Object.keys(ansiStyles).forEach(function (key) { | ||
ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g'); | ||
styles[key] = { | ||
get: function () { | ||
return build.call(this, this._styles ? this._styles.concat(key) : [key]); | ||
} | ||
}; | ||
}); | ||
ret[key] = { | ||
get: function () { | ||
return build.call(this, this._styles.concat(key)); | ||
} | ||
}; | ||
}); | ||
return ret; | ||
})(); | ||
var proto = defineProps(function chalk() {}, styles); | ||
@@ -83,7 +89,2 @@ | ||
str = code.open + str.replace(code.closeRe, code.open) + code.close; | ||
// Close the styling before a linebreak and reopen | ||
// after next line to fix a bleed issue on OS X | ||
// https://github.com/chalk/chalk/pull/92 | ||
str = str.replace(/\r?\n/g, code.close + '$&' + code.open); | ||
} | ||
@@ -97,6 +98,22 @@ | ||
defineProps(Chalk.prototype, styles); | ||
function init() { | ||
var ret = {}; | ||
Object.keys(styles).forEach(function (name) { | ||
ret[name] = { | ||
get: function () { | ||
return build.call(this, [name]); | ||
} | ||
}; | ||
}); | ||
return ret; | ||
} | ||
defineProps(Chalk.prototype, init()); | ||
module.exports = new Chalk(); | ||
module.exports.styles = ansiStyles; | ||
module.exports.hasColor = hasAnsi; | ||
module.exports.stripColor = stripAnsi; | ||
module.exports.supportsColor = supportsColor; |
{ | ||
"name": "chalk", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "Terminal string styling done right. Much color.", | ||
@@ -9,3 +9,3 @@ "license": "MIT", | ||
"Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)", | ||
"Joshua Boy Nicolai Appelman <joshua@jbna.nl> (jbna.nl)", | ||
"Joshua Appelman <jappelman@xebia.com> (jbnicolai.com)", | ||
"JD Ballard <i.am.qix@gmail.com> (github.com/qix-)" | ||
@@ -51,3 +51,5 @@ ], | ||
"escape-string-regexp": "^1.0.2", | ||
"supports-color": "^3.1.2" | ||
"has-ansi": "^2.0.0", | ||
"strip-ansi": "^3.0.0", | ||
"supports-color": "^2.0.0" | ||
}, | ||
@@ -58,6 +60,6 @@ "devDependencies": { | ||
"mocha": "*", | ||
"nyc": "^5.2.0", | ||
"nyc": "^3.0.0", | ||
"require-uncached": "^1.0.2", | ||
"resolve-from": "^2.0.0", | ||
"semver": "^5.1.0", | ||
"resolve-from": "^1.0.0", | ||
"semver": "^4.3.3", | ||
"xo": "*" | ||
@@ -64,0 +66,0 @@ }, |
@@ -14,3 +14,3 @@ <h1 align="center"> | ||
[![Coverage Status](https://coveralls.io/repos/chalk/chalk/badge.svg?branch=master)](https://coveralls.io/r/chalk/chalk?branch=master) | ||
[![](https://img.shields.io/badge/unicorn-approved-ff69b4.svg)](https://www.youtube.com/watch?v=9auOCbH5Ns4) | ||
[![](http://img.shields.io/badge/unicorn-approved-ff69b4.svg)](https://www.youtube.com/watch?v=9auOCbH5Ns4) | ||
@@ -34,3 +34,3 @@ | ||
- Actively maintained | ||
- [Used by ~7700 modules](https://www.npmjs.com/browse/depended/chalk) as of March 15, 2016 | ||
- [Used by ~4500 modules](https://www.npmjs.com/browse/depended/chalk) as of July 15, 2015 | ||
@@ -47,15 +47,10 @@ | ||
```js | ||
const chalk = require('chalk'); | ||
console.log(chalk.blue('Hello world!')); | ||
``` | ||
Chalk comes with an easy to use composable API where you just chain and nest the styles you want. | ||
Here without `console.log` for purity. | ||
```js | ||
const chalk = require('chalk'); | ||
var chalk = require('chalk'); | ||
// style a string | ||
chalk.blue('Hello world!'); | ||
// combine styled and normal strings | ||
@@ -79,9 +74,2 @@ chalk.blue('Hello') + 'World' + chalk.red('!'); | ||
); | ||
// ES2015 template literal | ||
const systemStats = ` | ||
CPU: ${chalk.red('90%')} | ||
RAM: ${chalk.green('40%')} | ||
DISK: ${chalk.yellow('70%')} | ||
`; | ||
``` | ||
@@ -92,4 +80,4 @@ | ||
```js | ||
const chalk = require('chalk'); | ||
const error = chalk.bold.red; | ||
var chalk = require('chalk'); | ||
var error = chalk.bold.red; | ||
console.log(error('Error!')); | ||
@@ -101,5 +89,5 @@ ``` | ||
```js | ||
const name = 'Sindre'; | ||
var name = 'Sindre'; | ||
console.log(chalk.green('Hello %s'), name); | ||
//=> 'Hello Sindre' | ||
//=> Hello Sindre | ||
``` | ||
@@ -125,3 +113,3 @@ | ||
```js | ||
const ctx = new chalk.constructor({enabled: false}); | ||
var ctx = new chalk.constructor({enabled: false}); | ||
``` | ||
@@ -142,3 +130,3 @@ | ||
```js | ||
const chalk = require('chalk'); | ||
var chalk = require('chalk'); | ||
@@ -151,3 +139,24 @@ console.log(chalk.styles.red); | ||
### chalk.hasColor(string) | ||
Check whether a string [has color](https://github.com/chalk/has-ansi). | ||
### chalk.stripColor(string) | ||
[Strip color](https://github.com/chalk/strip-ansi) from a string. | ||
Can be useful in combination with `.supportsColor` to strip color on externally styled text when it's not supported. | ||
Example: | ||
```js | ||
var chalk = require('chalk'); | ||
var styledString = getText(); | ||
if (!chalk.supportsColor) { | ||
styledString = chalk.stripColor(styledString); | ||
} | ||
``` | ||
## Styles | ||
@@ -197,3 +206,3 @@ | ||
If you're on Windows, do yourself a favor and use [`cmder`](http://cmder.net/) instead of `cmd.exe`. | ||
If you're on Windows, do yourself a favor and use [`cmder`](http://bliker.github.io/cmder/) instead of `cmd.exe`. | ||
@@ -210,3 +219,2 @@ | ||
- [wrap-ansi](https://github.com/chalk/wrap-ansi) - Wordwrap a string with ANSI escape codes | ||
- [slice-ansi](https://github.com/chalk/slice-ansi) - Slice a string with ANSI escape codes | ||
@@ -213,0 +221,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
11825
92
0
214
0
5
+ Addedhas-ansi@^2.0.0
+ Addedstrip-ansi@^3.0.0
+ Addedansi-regex@2.1.1(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)
- Removedhas-flag@1.0.0(transitive)
- Removedsupports-color@3.2.3(transitive)
Updatedsupports-color@^2.0.0