Skip to content

Commit

Permalink
feat: Relax isLogOptions validation to ignore unknown properties
Browse files Browse the repository at this point in the history
  • Loading branch information
FoxxMD committed Mar 28, 2024
1 parent d38e328 commit 0e24123
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@foxxmd/logging",
"type": "module",
"version": "0.1.13",
"version": "0.1.14",
"repository": "https://github.com/foxxmd/logging",
"description": "A typed, opinionated, batteries-included, Pino-based logging solution for backend TS/JS projects",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/funcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {isAbsolute, resolve} from 'node:path';

export const isLogOptions = (obj: object = {}): obj is LogOptions => {
return Object.entries(obj).every(([key, val]) => {
if (val === undefined) {
if (val === undefined || !['file','console','level'].includes(key)) {
return true;
}
const t = typeof val;
Expand Down
5 changes: 5 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ describe('Config Parsing', function () {
expect(() => parseLogOptions()).to.not.throw;
})

it('does not throw when object contains unknown properties', function () {
// @ts-expect-error
expect(() => parseLogOptions({extraProp: 'test'})).to.not.throw;
})

it('does not throw when a valid level is given', function () {
for (const level of LOG_LEVEL_NAMES) {
expect(() => parseLogOptions({level})).to.not.throw;
Expand Down

0 comments on commit 0e24123

Please sign in to comment.