123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- '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;
- }
|