Close #95 PR: tweak defining proto.
This commit is contained in:
parent
a301cbf3d1
commit
8417f175ab
1 changed files with 10 additions and 28 deletions
38
index.js
38
index.js
|
|
@ -15,21 +15,17 @@ if (isSimpleWindowsTerm) {
|
||||||
ansiStyles.blue.open = '\u001b[94m';
|
ansiStyles.blue.open = '\u001b[94m';
|
||||||
}
|
}
|
||||||
|
|
||||||
var styles = (function () {
|
var styles = {};
|
||||||
var ret = {};
|
|
||||||
|
|
||||||
Object.keys(ansiStyles).forEach(function (key) {
|
Object.keys(ansiStyles).forEach(function (key) {
|
||||||
ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
|
ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
|
||||||
|
|
||||||
ret[key] = {
|
styles[key] = {
|
||||||
get: function () {
|
get: function () {
|
||||||
return build.call(this, this._styles.concat(key));
|
return build.call(this, this._styles ? this._styles.concat(key) : [key]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
return ret;
|
|
||||||
})();
|
|
||||||
|
|
||||||
var proto = defineProps(function chalk() {}, styles);
|
var proto = defineProps(function chalk() {}, styles);
|
||||||
|
|
||||||
|
|
@ -91,21 +87,7 @@ function applyStyle() {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
defineProps(Chalk.prototype, styles);
|
||||||
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 = new Chalk();
|
||||||
module.exports.styles = ansiStyles;
|
module.exports.styles = ansiStyles;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue