(obj: unknown, indent: Indent, baseIndent: string)
| 38 | } |
| 39 | |
| 40 | function serialize(obj: unknown, indent: Indent, baseIndent: string): string { |
| 41 | if (typeof obj === 'object' && obj !== null) { |
| 42 | if (Array.isArray(obj)) return serializeArray(obj, indent, baseIndent); |
| 43 | if (obj instanceof Date) return `new Date(${obj.getTime()})`; |
| 44 | if (obj instanceof RegExp) return obj.toString(); |
| 45 | return serializeObject(obj, indent, baseIndent); |
| 46 | } |
| 47 | if (typeof obj === 'number') { |
| 48 | if (obj === Infinity) return 'Infinity'; |
| 49 | if (obj === -Infinity) return '-Infinity'; |
| 50 | if (obj === 0) return 1 / obj === Infinity ? '0' : '-0'; |
| 51 | if (obj !== obj) return 'NaN'; // eslint-disable-line no-self-compare |
| 52 | } |
| 53 | if (typeof obj === 'symbol') { |
| 54 | const key = Symbol.keyFor(obj); |
| 55 | // eslint-disable-next-line no-undefined |
| 56 | if (key !== undefined) return `Symbol.for(${stringify(key)})`; |
| 57 | } |
| 58 | if (typeof obj === 'bigint') return `${obj}n`; |
| 59 | return stringify(obj); |
| 60 | } |
| 61 | |
| 62 | // isWellFormed exists from Node.js 20 |
| 63 | const hasStringIsWellFormed = 'isWellFormed' in String.prototype; |
no test coverage detected