fix(client): console output for sets and maps (#44966)

Co-authored-by: IsmailTlemcani <ismail.tlemcani@gmail.com>
This commit is contained in:
Ismail Tlemcani
2022-02-02 12:53:49 +01:00
committed by GitHub
parent 634a39eebf
commit 09d30d2d14

View File

@ -3,5 +3,13 @@ import { inspect } from 'util';
export function format(x) {
// we're trying to mimic console.log, so we avoid wrapping strings in quotes:
if (typeof x === 'string') return x;
else if (x instanceof Set) {
return `Set(${x.size}) {${Array.from(x).join(', ')}}`;
} else if (x instanceof Map) {
return `Map(${x.size}) {${Array.from(
x.entries(),
([k, v]) => `${k} => ${v}`
).join(', ')}})`;
}
return inspect(x);
}