Skip to content

Commit

Permalink
fix(options)!: move indent and jsonIndent to an object, indent
Browse files Browse the repository at this point in the history
…becoming `indent.details`

This nicely groups the options together and for `indent.details` it more accurately describes what the indentation will affect in the formatted log.
  • Loading branch information
jdbruijn committed Mar 25, 2022
1 parent 237c6b8 commit 6c6aad0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class Formatter {
chalk.cyan(
this.indent(
`${key}: ${stringify(value, {
indent: this._options.jsonIndent,
indent: this._options.indent.json,
maxLength: 80,
})}`,
true,
Expand Down Expand Up @@ -271,7 +271,7 @@ class Formatter {
}

indent(input: string, leading = false): string {
const indentation = ' '.repeat(this._options.indent);
const indentation = ' '.repeat(this._options.indent.details);
const prefix = leading ? indentation : '';
const formatted = input
.split(this._regex.newLine)
Expand Down
6 changes: 4 additions & 2 deletions src/formatter.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ describe('Formatter', () => {
extras: false,
},
extrasKey: '',
indent: 4,
jsonIndent: 2,
indent: {
details: 4,
json: 2,
},
basePath: '/',
newLineCharacter: '\n',
extrasMaxValueLength: 50,
Expand Down
9 changes: 7 additions & 2 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ const options = z
.min(1)
.regex(new RegExp(`^((?!(${bunyanCoreFields().join('|')})).)*$`))
.optional(), // Exlcude bunyan core fields.
indent: z.number().int().nonnegative().default(4),
jsonIndent: z.number().int().nonnegative().default(2),
indent: z
.object({
details: z.number().int().nonnegative().default(4),
json: z.number().int().nonnegative().default(2),
})
.strict()
.default({}),
basePath: z.string().min(1).default('/'),
newLineCharacter: z.enum(['\r', '\n', '\r\n']).default('\n'),
time: z
Expand Down
14 changes: 8 additions & 6 deletions src/options.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ describe('schema', () => {
extras: false,
},
extrasKey: 'extras',
indent: 4,
jsonIndent: 2,
indent: {
details: 4,
json: 2,
},
basePath: '/',
newLineCharacter: '\n',
time: {
Expand Down Expand Up @@ -57,8 +59,8 @@ describe('schema', () => {
['show.source', 'boolean', false],
['show.extras', 'boolean', true],
['extrasKey', 'string', undefined],
['indent', 'number', 4],
['jsonIndent', 'number', 2],
['indent.details', 'number', 4],
['indent.json', 'number', 2],
['basePath', 'string', '/'],
['newLineCharacter', '\r | \n | \r\n', '\n'],
['extrasMaxValueLength', 'number', 50],
Expand Down Expand Up @@ -113,8 +115,8 @@ describe('schema', () => {
});

describe.each([
['indent', 'greater than or equal to 0'],
['jsonIndent', 'greater than or equal to 0'],
['indent.details', 'greater than or equal to 0'],
['indent.json', 'greater than or equal to 0'],
['extrasMaxValueLength', 'a positive number'],
])('%s', (path: string, type: string) => {
it('MUST be an integer', () => {
Expand Down

0 comments on commit 6c6aad0

Please sign in to comment.