Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #605

Closed
wants to merge 3 commits into from
Closed

Dev #605

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 10 additions & 10 deletions source/index.js
Expand Up @@ -19,8 +19,6 @@ const levelMapping = [
'ansi16m',
];

const styles = Object.create(null);

const applyOptions = (object, options = {}) => {
if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
throw new Error('The `level` option should be an integer from 0 to 3');
Expand All @@ -31,13 +29,6 @@ const applyOptions = (object, options = {}) => {
object.level = options.level === undefined ? colorLevel : options.level;
};

export class Chalk {
constructor(options) {
// eslint-disable-next-line no-constructor-return
return chalkFactory(options);
}
}

const chalkFactory = options => {
const chalk = (...strings) => strings.join(' ');
applyOptions(chalk, options);
Expand All @@ -51,7 +42,7 @@ function createChalk(options) {
return chalkFactory(options);
}

Object.setPrototypeOf(createChalk.prototype, Function.prototype);
const styles = Object.create(null);

for (const [styleName, style] of Object.entries(ansiStyles)) {
styles[styleName] = {
Expand Down Expand Up @@ -199,9 +190,18 @@ const applyStyle = (self, string) => {
return openAll + string + closeAll;
};

Object.setPrototypeOf(createChalk.prototype, Function.prototype);
Object.defineProperties(createChalk.prototype, styles);

const chalk = createChalk();

export class Chalk {
constructor(options) {
// eslint-disable-next-line no-constructor-return
return chalkFactory(options);
}
}

export const chalkStderr = createChalk({level: stderrColor ? stderrColor.level : 0});

export {
Expand Down