(_key: string, val: unknown)
| 36 | } |
| 37 | |
| 38 | const replacer = (_key: string, val: unknown): any => { |
| 39 | if (isRef(val)) { |
| 40 | return replacer(_key, val.value) |
| 41 | } else if (isMap(val)) { |
| 42 | return { |
| 43 | [`Map(${val.size})`]: [...val.entries()].reduce( |
| 44 | (entries, [key, val], i) => { |
| 45 | entries[stringifySymbol(key, i) + ' =>'] = val |
| 46 | return entries |
| 47 | }, |
| 48 | {} as Record<string, any>, |
| 49 | ), |
| 50 | } |
| 51 | } else if (isSet(val)) { |
| 52 | return { |
| 53 | [`Set(${val.size})`]: [...val.values()].map(v => stringifySymbol(v)), |
| 54 | } |
| 55 | } else if (isSymbol(val)) { |
| 56 | return stringifySymbol(val) |
| 57 | } else if (isObject(val) && !isArray(val) && !isPlainObject(val)) { |
| 58 | // native elements |
| 59 | return String(val) |
| 60 | } |
| 61 | return val |
| 62 | } |
| 63 | |
| 64 | const stringifySymbol = (v: unknown, i: number | string = ''): any => |
| 65 | // Symbol.description in es2019+ so we need to cast here to pass |
nothing calls this directly
no test coverage detected