Skip to content

Commit

Permalink
Close #95 PR: tweak defining proto.
Browse files Browse the repository at this point in the history
  • Loading branch information
stevemao authored and sindresorhus committed Jan 9, 2016
1 parent a301cbf commit 8417f17
Showing 1 changed file with 10 additions and 28 deletions.
38 changes: 10 additions & 28 deletions index.js
Expand Up @@ -15,21 +15,17 @@ if (isSimpleWindowsTerm) {
ansiStyles.blue.open = '\u001b[94m';
}

var styles = (function () {
var ret = {};
var styles = {};

Object.keys(ansiStyles).forEach(function (key) {
ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
Object.keys(ansiStyles).forEach(function (key) {
ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');

ret[key] = {
get: function () {
return build.call(this, this._styles.concat(key));
}
};
});

return ret;
})();
styles[key] = {
get: function () {
return build.call(this, this._styles ? this._styles.concat(key) : [key]);
}
};
});

var proto = defineProps(function chalk() {}, styles);

Expand Down Expand Up @@ -91,21 +87,7 @@ function applyStyle() {
return str;
}

function init() {
var ret = {};

Object.keys(styles).forEach(function (name) {
ret[name] = {
get: function () {
return build.call(this, [name]);
}
};
});

return ret;
}

defineProps(Chalk.prototype, init());
defineProps(Chalk.prototype, styles);

module.exports = new Chalk();
module.exports.styles = ansiStyles;
Expand Down

0 comments on commit 8417f17

Please sign in to comment.