Skip to content

Commit

Permalink
fix(options)!: rename enable option to show
Browse files Browse the repository at this point in the history
The name `show` more accurately describes what the option is controlling, namely whether or not to show certain things in the formatted log.
  • Loading branch information
jdbruijn committed Mar 25, 2022
1 parent 52ebba6 commit 237c6b8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
18 changes: 9 additions & 9 deletions src/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Formatter {
}
});

if (!this._options.enable.extras) {
if (!this._options.show.extras) {
return parsed;
}

Expand Down Expand Up @@ -121,7 +121,7 @@ class Formatter {
}

formatTime(time: ParsedRecord['time']): string {
if (!this._options.enable.time) {
if (!this._options.show.time) {
return '';
}

Expand All @@ -141,41 +141,41 @@ class Formatter {
}

formatLevel(level: ParsedRecord['level']): string {
const prefix = this._options.enable.time ? ' ' : '';
const prefix = this._options.show.time ? ' ' : '';
return `${prefix}${this._levels[level]}`;
}

formatName(name: ParsedRecord['name']): string {
if (!this._options.enable.name) {
if (!this._options.show.name) {
return '';
}

return ` ${name}`;
}

formatPid(pid: ParsedRecord['pid']): string {
if (!this._options.enable.pid) {
if (!this._options.show.pid) {
return '';
}

const prefix = this._options.enable.name ? '/' : ' ';
const prefix = this._options.show.name ? '/' : ' ';
return `${prefix}${pid}`;
}

formatHostname(hostname: ParsedRecord['hostname']): string {
if (!this._options.enable.hostname) {
if (!this._options.show.hostname) {
return '';
}

return [
' ',
this._options.enable.name || this._options.enable.pid ? 'on ' : '',
this._options.show.name || this._options.show.pid ? 'on ' : '',
hostname,
].join('');
}

formatSource(source: ParsedRecord['source']): string {
if (!this._options.enable.source || is.undefined(source)) {
if (!this._options.show.source || is.undefined(source)) {
return '';
}

Expand Down
2 changes: 1 addition & 1 deletion src/formatter.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import stripAnsi from 'strip-ansi';

describe('Formatter', () => {
const options: Readonly<MergedOptions> = {
enable: {
show: {
time: true,
name: false,
hostname: false,
Expand Down
2 changes: 1 addition & 1 deletion src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { z } from 'zod';

const options = z
.object({
enable: z
show: z
.object({
time: z.boolean().default(true),
name: z.boolean().default(false),
Expand Down
14 changes: 7 additions & 7 deletions src/options.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('schema', () => {
options: Options;
}> = {
options: {
enable: {
show: {
time: true,
name: false,
hostname: false,
Expand Down Expand Up @@ -50,12 +50,12 @@ describe('schema', () => {
};

describe.each([
['enable.time', 'boolean', true],
['enable.name', 'boolean', false],
['enable.hostname', 'boolean', false],
['enable.pid', 'boolean', false],
['enable.source', 'boolean', false],
['enable.extras', 'boolean', true],
['show.time', 'boolean', true],
['show.name', 'boolean', false],
['show.hostname', 'boolean', false],
['show.pid', 'boolean', false],
['show.source', 'boolean', false],
['show.extras', 'boolean', true],
['extrasKey', 'string', undefined],
['indent', 'number', 4],
['jsonIndent', 'number', 2],
Expand Down

0 comments on commit 237c6b8

Please sign in to comment.