Skip to content

Commit 541383a

Browse files
authored
Issue/58 (#59)
* fix: handle typeof undefined * chore: updated readme * chore: add changeset
1 parent 5aca333 commit 541383a

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

.changeset/many-tigers-deliver.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@heymp/scratchpad": patch
3+
---
4+
5+
Fix: logging undefined breaks log output
6+
7+
fixes: #58

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ log([...set.values()]);
9797
log([...set.entries()]);
9898
log(new Promise(res => res()));
9999
log(function hello() { return 'world' });
100+
log(undefined);
100101
```
101102

102103
## Custom exposed functions

examples/typesCheck.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ log([...set.values()]);
2020
log([...set.entries()]);
2121
log(new Promise(res => res()));
2222
log(function hello() { return 'world' });
23+
log(undefined);

src/browser.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,23 @@ export async function browser(processor: Processor) {
6363
...value.flatMap((i: any) => {
6464
const protoName = Object.prototype.toString.call(i);
6565
const protoNamePrettyPrint = protoName.replace('object ', '').replace(/\[|\]/g, '') + ':';
66+
67+
if (protoName === '[object Undefined]') {
68+
return [i];
69+
}
6670
if (protoName === '[object Array]') {
6771
return [protoNamePrettyPrint, i];
6872
}
6973
if (protoName === '[object Set]') {
7074
return [protoNamePrettyPrint, [...i.values()]];
7175
}
72-
else if (protoName === '[object Map]') {
76+
if (protoName === '[object Map]') {
7377
return [protoNamePrettyPrint, [...i.entries()]];
7478
}
75-
else if (protoName === '[object Generator]') {
79+
if (protoName === '[object Generator]') {
7680
return [protoNamePrettyPrint, i.next()];
7781
}
78-
else if (typeof i[Symbol.iterator] === 'function') {
82+
if (typeof i[Symbol.iterator] === 'function') {
7983
if (!['[object String]', '[object Array]'].includes(protoName)) {
8084
return [protoNamePrettyPrint, [...i]]
8185
}

0 commit comments

Comments
 (0)