Skip to content

Commit

Permalink
Fix(Log): undefined for keeping tree structure
Browse files Browse the repository at this point in the history
  • Loading branch information
1aron committed Feb 22, 2023
1 parent dd6eb13 commit c681465
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
5 changes: 1 addition & 4 deletions packages/log/src/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ const tree = (object: JSON | object) => {
}

function removeEmpty(data) {
//transform properties into key-values pairs and filter all the empty-values
const entries = Object.entries(data).filter(([, value]) => value != null)
//map through all the remaining properties and check if the value is an object.
//if value is object, use recursion to remove empty properties
const entries = Object.entries(data).filter(([, value]) => value !== null)
const clean = entries
.map(([key, v]) => {
const value = typeof v == 'object' ? removeEmpty(v) : v
Expand Down
2 changes: 1 addition & 1 deletion packages/log/tests/tree.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import log from '@techor/log'

it('prevent outputting items with empty value', () => {
expect(log.tree({ a: 1, b: null, c: { c1: null, c2: 1 }, d: { d1: null } }))
expect(log.tree({ a: 1, b: null, c: { c1: null, c2: 1 }, d: { d1: undefined } }))
.not.toContain('c1')
})

0 comments on commit c681465

Please sign in to comment.