Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return style.reduce((result, name) => {
switch (true) {
case name in styles.color:
result.color = styles.color[name].open;
break;
case name in styles.bgColor:
result.bgColor = styles.bgColor[name].open;
break;
case name === 'reset':
result.color = '\u001B[39m';
result.bgColor = '\u001B[49m';
break;
// default:
// console.error('Unknown modifier:', name);
}
chalk.sprint = function(s, hex) {
const color = chalk.use16m ? style.color.ansi16m.hex(hex)
: chalk.use256 ? style.color.ansi256.hex(hex)
: style.color.ansi.hex(hex);
return color + s + style.color.close;
};
styles[key] = {
get() {
const codes = ansiStyles[key];
return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, key);
}
};
}
styles.visible = {
get() {
return build.call(this, this._styles || [], true, 'visible');
}
};
ansiStyles.color.closeRe = new RegExp(escapeStringRegexp(ansiStyles.color.close), 'g');
for (const model of Object.keys(ansiStyles.color.ansi)) {
if (skipModels.has(model)) {
continue;
}
styles[model] = {
get() {
const level = this.level;
return function () {
const open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments);
const codes = {
open,
close: ansiStyles.color.close,
closeRe: ansiStyles.color.closeRe
};
return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
styles[key] = {
get() {
const codes = ansiStyles[key];
return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, key);
}
};
}
styles.visible = {
get() {
return build.call(this, this._styles || [], true, 'visible');
}
};
ansiStyles.color.closeRe = new RegExp(escapeStringRegexp(ansiStyles.color.close), 'g');
for (const model of Object.keys(ansiStyles.color.ansi)) {
if (skipModels.has(model)) {
continue;
}
styles[model] = {
get() {
const level = this.level;
return function () {
const open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments);
const codes = {
open,
close: ansiStyles.color.close,
closeRe: ansiStyles.color.closeRe
};
return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
styles[key] = {
get() {
const codes = ansiStyles[key];
return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, key);
}
};
}
styles.visible = {
get() {
return build.call(this, this._styles || [], true, 'visible');
}
};
ansiStyles.color.closeRe = new RegExp(escapeStringRegexp(ansiStyles.color.close), 'g');
for (const model of Object.keys(ansiStyles.color.ansi)) {
if (skipModels.has(model)) {
continue;
}
styles[model] = {
get() {
const level = this.level;
return function () {
const open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments);
const codes = {
open,
close: ansiStyles.color.close,
closeRe: ansiStyles.color.closeRe
};
return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
const color = (v, c) => `${ansi.color[c].open}${v}${ansi.color.close}`;
return function () {
const open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments);
const codes = {
open,
close: ansiStyles.color.close,
closeRe: ansiStyles.color.closeRe
};
return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
};
}
return function () {
const open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments);
const codes = {
open,
close: ansiStyles.color.close,
closeRe: ansiStyles.color.closeRe
};
return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
};
}
for (let f of file.listCodeDir('colors')) {
const theme = {};
const data = _.extendOwn({}, DEFAULT, f.data);
for (let x of _.pairs(data)) {
const k = x[0];
const v = x[1];
const bgK = bgName(k);
if (chalk.use16m) {
theme[k] = style.color.ansi16m.hex(v);
theme[bgK] = style.bgColor.ansi16m.hex(v);
} else if (chalk.use256) {
theme[k] = style.color.ansi256.hex(v);
theme[bgK] = style.bgColor.ansi256.hex(v);
} else {
theme[k] = style.color.ansi.hex(v);
theme[bgK] = style.bgColor.ansi.hex(v);
}
}
chalk.themes.set(f.name, theme);
}
for (let color of ['black', 'blue', 'cyan', 'gray', 'green', 'magenta', 'red', 'white', 'yellow']) {
Object.defineProperty(chalk, color, {
get: () => chalk.wrap(chalk.theme[color], style.color.close),
configurable: true
});
const bgcolor = bgName(color);
Object.defineProperty(chalk, bgcolor, {
get: () => chalk.wrap(chalk.theme[bgcolor], style.bgColor.close),
configurable: true
});