Skelleton extended.
This commit is contained in:
+63
@@ -0,0 +1,63 @@
|
||||
'use strict';
|
||||
var ansi = require('ansi-styles');
|
||||
var stripAnsi = require('strip-ansi');
|
||||
var hasColor = require('has-color');
|
||||
var defineProps = Object.defineProperties;
|
||||
var chalk = module.exports;
|
||||
|
||||
var styles = (function () {
|
||||
var ret = {};
|
||||
|
||||
ansi.grey = ansi.gray;
|
||||
|
||||
Object.keys(ansi).forEach(function (key) {
|
||||
ret[key] = {
|
||||
get: function () {
|
||||
this._styles.push(key);
|
||||
return this;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
return ret;
|
||||
})();
|
||||
|
||||
function init() {
|
||||
var ret = {};
|
||||
|
||||
Object.keys(styles).forEach(function (name) {
|
||||
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];
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
defineProps(chalk, init());
|
||||
|
||||
chalk.styles = ansi;
|
||||
chalk.stripColor = stripAnsi;
|
||||
chalk.supportsColor = hasColor;
|
||||
|
||||
// detect mode if not set manually
|
||||
if (chalk.enabled === undefined) {
|
||||
chalk.enabled = chalk.supportsColor;
|
||||
}
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
{
|
||||
"raw": "chalk@~0.4.0",
|
||||
"scope": null,
|
||||
"escapedName": "chalk",
|
||||
"name": "chalk",
|
||||
"rawSpec": "~0.4.0",
|
||||
"spec": ">=0.4.0 <0.5.0",
|
||||
"type": "range"
|
||||
},
|
||||
"/Users/gerrit/Documents/dev/nodejs/rentfor.camp/html/RentForCamp/node_modules/nomnom"
|
||||
]
|
||||
],
|
||||
"_from": "chalk@>=0.4.0 <0.5.0",
|
||||
"_id": "chalk@0.4.0",
|
||||
"_inCache": true,
|
||||
"_location": "/chalk",
|
||||
"_npmUser": {
|
||||
"name": "sindresorhus",
|
||||
"email": "sindresorhus@gmail.com"
|
||||
},
|
||||
"_npmVersion": "1.3.17",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"raw": "chalk@~0.4.0",
|
||||
"scope": null,
|
||||
"escapedName": "chalk",
|
||||
"name": "chalk",
|
||||
"rawSpec": "~0.4.0",
|
||||
"spec": ">=0.4.0 <0.5.0",
|
||||
"type": "range"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/nomnom"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/chalk/-/chalk-0.4.0.tgz",
|
||||
"_shasum": "5199a3ddcd0c1efe23bc08c1b027b06176e0c64f",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "chalk@~0.4.0",
|
||||
"_where": "/Users/gerrit/Documents/dev/nodejs/rentfor.camp/html/RentForCamp/node_modules/nomnom",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "http://sindresorhus.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/sindresorhus/chalk/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"ansi-styles": "~1.0.0",
|
||||
"has-color": "~0.1.0",
|
||||
"strip-ansi": "~0.1.0"
|
||||
},
|
||||
"description": "Terminal string styling done right. Created because the `colors` module does some really horrible things.",
|
||||
"devDependencies": {
|
||||
"mocha": "~1.x"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "5199a3ddcd0c1efe23bc08c1b027b06176e0c64f",
|
||||
"tarball": "https://registry.npmjs.org/chalk/-/chalk-0.4.0.tgz"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.8.0"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"homepage": "https://github.com/sindresorhus/chalk",
|
||||
"keywords": [
|
||||
"color",
|
||||
"colour",
|
||||
"colors",
|
||||
"terminal",
|
||||
"console",
|
||||
"cli",
|
||||
"string",
|
||||
"ansi",
|
||||
"styles",
|
||||
"tty",
|
||||
"formatting",
|
||||
"rgb",
|
||||
"256",
|
||||
"shell",
|
||||
"xterm",
|
||||
"log",
|
||||
"logging",
|
||||
"command-line",
|
||||
"text"
|
||||
],
|
||||
"license": "MIT",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "sindresorhus",
|
||||
"email": "sindresorhus@gmail.com"
|
||||
}
|
||||
],
|
||||
"name": "chalk",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/sindresorhus/chalk.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha"
|
||||
},
|
||||
"version": "0.4.0"
|
||||
}
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
# <img width="250" src="logo.png" alt="chalk">
|
||||
|
||||
> Terminal string styling done right
|
||||
|
||||
[](http://travis-ci.org/sindresorhus/chalk)
|
||||
|
||||
[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.
|
||||
|
||||
**Chalk is a clean and focused alternative.**
|
||||
|
||||

|
||||
|
||||
|
||||
## Why
|
||||
|
||||
- **Doesn't extend String.prototype**
|
||||
- Expressive API
|
||||
- Clean and focused
|
||||
- Auto-detects color support
|
||||
- Actively maintained
|
||||
- [Used by 150+ modules](https://npmjs.org/browse/depended/chalk)
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
Install with [npm](https://npmjs.org/package/chalk): `npm install --save chalk`
|
||||
|
||||
|
||||
## Example
|
||||
|
||||
Chalk comes with an easy to use composable API where you just chain and nest the styles you want.
|
||||
|
||||
```js
|
||||
var chalk = require('chalk');
|
||||
|
||||
// style a string
|
||||
console.log( chalk.blue('Hello world!') );
|
||||
|
||||
// combine styled and normal strings
|
||||
console.log( chalk.blue('Hello'), 'World' + chalk.red('!') );
|
||||
|
||||
// compose multiple styles using the chainable API
|
||||
console.log( chalk.blue.bgRed.bold('Hello world!') );
|
||||
|
||||
// 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') );
|
||||
```
|
||||
|
||||
You can easily define your own themes.
|
||||
|
||||
```js
|
||||
var chalk = require('chalk');
|
||||
var error = chalk.bold.red;
|
||||
console.log(error('Error!'));
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### chalk.`<style>[.<style>...](string, [string...])`
|
||||
|
||||
Example: `chalk.red.bold.underline('Hello', 'world');`
|
||||
|
||||
Chain [styles](#styles) and call the last one as a method with a string argument. Order doesn't matter.
|
||||
|
||||
Multiple arguments will be separated by space.
|
||||
|
||||
### chalk.enabled
|
||||
|
||||
Color support is automatically detected, but you can override it.
|
||||
|
||||
### chalk.supportsColor
|
||||
|
||||
Detect whether the terminal [supports color](https://github.com/sindresorhus/has-color).
|
||||
|
||||
Can be overridden by the user with the flags `--color` and `--no-color`.
|
||||
|
||||
Used internally and handled for you, but exposed for convenience.
|
||||
|
||||
### chalk.styles
|
||||
|
||||
Exposes the styles as [ANSI escape codes](https://github.com/sindresorhus/ansi-styles).
|
||||
|
||||
Generally not useful, but you might need just the `.open` or `.close` escape code if you're mixing externally styled strings with yours.
|
||||
|
||||
```js
|
||||
var chalk = require('chalk');
|
||||
|
||||
console.log(chalk.styles.red);
|
||||
//=> {open: '\x1b[31m', close: '\x1b[39m'}
|
||||
|
||||
console.log(chalk.styles.red.open + 'Hello' + chalk.styles.red.close);
|
||||
```
|
||||
|
||||
### chalk.stripColor(string)
|
||||
|
||||
[Strip color](https://github.com/sindresorhus/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 = fromExternal();
|
||||
|
||||
if (!chalk.supportsColor) {
|
||||
chalk.stripColor(styledString);
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## Styles
|
||||
|
||||
### General
|
||||
|
||||
- reset
|
||||
- bold
|
||||
- italic
|
||||
- underline
|
||||
- inverse
|
||||
- strikethrough
|
||||
|
||||
### Text colors
|
||||
|
||||
- black
|
||||
- red
|
||||
- green
|
||||
- yellow
|
||||
- blue
|
||||
- magenta
|
||||
- cyan
|
||||
- white
|
||||
- gray
|
||||
|
||||
### Background colors
|
||||
|
||||
- bgBlack
|
||||
- bgRed
|
||||
- bgGreen
|
||||
- bgYellow
|
||||
- bgBlue
|
||||
- bgMagenta
|
||||
- bgCyan
|
||||
- bgWhite
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Sindre Sorhus](http://sindresorhus.com)
|
||||
|
||||
|
||||
-
|
||||
|
||||
[](https://bitdeli.com/free "Bitdeli Badge")
|
||||
Reference in New Issue
Block a user