Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Commit

Permalink
feat: Add support to render non array iterables (#72)
Browse files Browse the repository at this point in the history
and errors

Adds support to render iterables such as Map and Set
as well as JSON.stringify's Error objects

Breaking Changes: None
  • Loading branch information
JimmayVV authored Oct 10, 2020
1 parent f42db01 commit cb1b217
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/Explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const DefaultRenderer = ({
// path,
subEntries,
subEntryPages,
type,
// depth,
expanded,
toggle,
Expand All @@ -62,7 +63,10 @@ const DefaultRenderer = ({
<>
<Label onClick={() => toggle()}>
<Expander expanded={expanded} /> {label}{' '}
<Info>{subEntries.length} items</Info>
<Info>
{String(type).toLowerCase() === 'iterable' ? '(Iterable) ' : ''}
{subEntries.length} items
</Info>
</Label>
{expanded ? (
subEntryPages.length === 1 ? (
Expand Down Expand Up @@ -100,7 +104,7 @@ const DefaultRenderer = ({
</>
) : (
<>
<Label>{label}:</Label> <Value>{JSON.stringify(value)}</Value>
<Label>{label}:</Label> <Value>{JSON.stringify(value, Object.getOwnPropertyNames(Object(value)))}</Value>
</>
)}
</Entry>
Expand Down Expand Up @@ -149,6 +153,18 @@ export default function Explorer({
value: d,
})
)
} else if (
value !== null &&
typeof value === 'object' &&
typeof value[Symbol.iterator] === 'function'
) {
type = 'Iterable'
subEntries = Array.from(value, (val, i) =>
makeProperty({
label: i,
value: val,
})
)
} else if (typeof value === 'object' && value !== null) {
type = 'object'
subEntries = Object.entries(value).map(([label, value]) =>
Expand Down

0 comments on commit cb1b217

Please sign in to comment.