code style
This commit is contained in:
parent
c8e08f5e79
commit
c63e95c58b
1 changed files with 18 additions and 14 deletions
32
index.js
32
index.js
|
|
@ -16,18 +16,6 @@ if (process.platform === 'win32' && !/^xterm/i.test(process.env.TERM || '')) {
|
||||||
ansiStyles.blue.open = '\u001b[94m';
|
ansiStyles.blue.open = '\u001b[94m';
|
||||||
}
|
}
|
||||||
|
|
||||||
function build(_styles) {
|
|
||||||
var builder = function builder() {
|
|
||||||
return applyStyle.apply(builder, arguments);
|
|
||||||
};
|
|
||||||
builder._styles = _styles;
|
|
||||||
builder.enabled = this.enabled;
|
|
||||||
// __proto__ is used because we must return a function, but there is
|
|
||||||
// no way to create a function with a different prototype.
|
|
||||||
builder.__proto__ = proto;
|
|
||||||
return builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
var styles = (function () {
|
var styles = (function () {
|
||||||
var ret = {};
|
var ret = {};
|
||||||
|
|
||||||
|
|
@ -46,11 +34,27 @@ var styles = (function () {
|
||||||
|
|
||||||
var proto = defineProps(function chalk() {}, styles);
|
var proto = defineProps(function chalk() {}, styles);
|
||||||
|
|
||||||
|
function build(_styles) {
|
||||||
|
var builder = function builder() {
|
||||||
|
return applyStyle.apply(builder, arguments);
|
||||||
|
};
|
||||||
|
|
||||||
|
builder._styles = _styles;
|
||||||
|
builder.enabled = this.enabled;
|
||||||
|
// __proto__ is used because we must return a function, but there is
|
||||||
|
// no way to create a function with a different prototype.
|
||||||
|
/*eslint no-proto: 0 */
|
||||||
|
builder.__proto__ = proto;
|
||||||
|
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
function applyStyle() {
|
function applyStyle() {
|
||||||
// support varags, but simply cast to string in case there's only one arg
|
// support varags, but simply cast to string in case there's only one arg
|
||||||
var args = arguments;
|
var args = arguments;
|
||||||
var argsLen = args.length;
|
var argsLen = args.length;
|
||||||
var str = argsLen !== 0 && String(arguments[0]);
|
var str = argsLen !== 0 && String(arguments[0]);
|
||||||
|
|
||||||
if (argsLen > 1) {
|
if (argsLen > 1) {
|
||||||
// don't slice `arguments`, it prevents v8 optimizations
|
// don't slice `arguments`, it prevents v8 optimizations
|
||||||
for (var a = 1; a < argsLen; a++) {
|
for (var a = 1; a < argsLen; a++) {
|
||||||
|
|
@ -62,12 +66,12 @@ function applyStyle() {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*jshint validthis: true */
|
|
||||||
var nestedStyles = this._styles;
|
var nestedStyles = this._styles;
|
||||||
|
|
||||||
var i = nestedStyles.length;
|
var i = nestedStyles.length;
|
||||||
|
|
||||||
while (i--) {
|
while (i--) {
|
||||||
var code = ansiStyles[nestedStyles[i]];
|
var code = ansiStyles[nestedStyles[i]];
|
||||||
|
|
||||||
// Replace any instances already present with a re-opening code
|
// Replace any instances already present with a re-opening code
|
||||||
// otherwise only the part of the string until said closing code
|
// otherwise only the part of the string until said closing code
|
||||||
// will be colored, and the rest will simply be 'plain'.
|
// will be colored, and the rest will simply be 'plain'.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue