Skip to content

Commit

Permalink
style: prefer object spread instead of Object.assign
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Apr 10, 2023
1 parent 1a4b893 commit c03268a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 28 deletions.
26 changes: 11 additions & 15 deletions src/consola.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,21 @@ export class Consola {
}

create(options: ConsolaOptions): ConsolaInstance {
return new Consola(
Object.assign(
{
reporters: this._reporters,
level: this.level,
types: this._types,
defaults: this._defaults,
stdout: this._stdout,
stderr: this._stderr,
mockFn: this._mockFn,
},
options
)
) as ConsolaInstance;
return new Consola({
reporters: this._reporters,
level: this.level,
types: this._types,
defaults: this._defaults,
stdout: this._stdout,
stderr: this._stderr,
mockFn: this._mockFn,
...options,
}) as ConsolaInstance;
}

withDefaults(defaults: ConsolaLogObject): ConsolaInstance {
return this.create({
defaults: Object.assign({}, this._defaults, defaults),
defaults: { ...this._defaults, ...defaults },
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/reporters/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class BasicReporter {
options: typeof DEFAULTS;

constructor(options: Partial<typeof DEFAULTS>) {
this.options = Object.assign({}, DEFAULTS, options);
this.options = { ...DEFAULTS, ...options };
}

formatStack(stack: string) {
Expand Down
2 changes: 1 addition & 1 deletion src/reporters/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default class BrowserReporter {
typeColorMap: Record<string, string>;

constructor(options: any) {
this.options = Object.assign({}, options);
this.options = { ...options };

this.defaultColor = "#7f8c8d"; // Gray
this.levelColorMap = {
Expand Down
2 changes: 1 addition & 1 deletion src/reporters/fancy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const TYPE_ICONS = {

export default class FancyReporter extends BasicReporter {
constructor(options: Partial<typeof DEFAULTS>) {
super(Object.assign({}, DEFAULTS, options));
super({ ...DEFAULTS, ...options });
}

formatStack(stack: string) {
Expand Down
16 changes: 6 additions & 10 deletions src/reporters/winston.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,12 @@ export default class WinstonReporter {
this.logger =
logger && logger.log
? logger
: winston.createLogger(
Object.assign(
{
level: "info",
format: winston.format.simple(),
transports: [new winston.transports.Console()],
},
logger
)
);
: winston.createLogger({
level: "info",
format: winston.format.simple(),
transports: [new winston.transports.Console()],
...logger,
});
}

log(logObj: ConsolaReporterLogObject) {
Expand Down

0 comments on commit c03268a

Please sign in to comment.