(options: {}, wordwrap?: number, spaces?: number, level = 0)
| 577 | } |
| 578 | |
| 579 | protected serializeObject(options: {}, wordwrap?: number, spaces?: number, level = 0): string { |
| 580 | if (typeof wordwrap === 'number' && !Object.hasOwn(options, Config)) { |
| 581 | const res = this.serializeObject(options, undefined, undefined, level); |
| 582 | if (res.length <= wordwrap) { |
| 583 | return res; |
| 584 | } |
| 585 | } |
| 586 | const nextWordwrap = typeof wordwrap === 'number' ? 80 - (spaces ?? 0) - level * 2 : undefined; |
| 587 | const sep = typeof spaces === 'undefined' ? ', ' : `,\n${' '.repeat(spaces)}`; |
| 588 | const doIndent = typeof spaces !== 'undefined'; |
| 589 | if (Array.isArray(options)) { |
| 590 | return `[${doIndent ? `\n${' '.repeat(spaces)}` : ''}${options.map(val => `${doIndent ? ' '.repeat(level * 2 + (spaces + 2)) : ''}${this.serializeValue(val, typeof nextWordwrap === 'number' ? nextWordwrap : undefined, doIndent ? spaces : undefined, level + 1)}`).join(sep)}${doIndent ? `${options.length > 0 ? ',\n' : ''}${' '.repeat(spaces + level * 2)}` : ''}]`; |
| 591 | } |
| 592 | const entries = Object.entries(options); |
| 593 | return `{${doIndent ? `\n${' '.repeat(spaces)}` : ' '}${entries |
| 594 | .map(([opt, val]) => { |
| 595 | const key = identifierRegex.test(opt) ? opt : this.quote(opt); |
| 596 | return `${doIndent ? ' '.repeat(level * 2 + (spaces + 2)) : ''}${key}: ${this.serializeValue(val, typeof nextWordwrap === 'number' ? nextWordwrap - key.length - 2 /* ': '.length*/ : undefined, doIndent ? spaces : undefined, level + 1)}`; |
| 597 | }) |
| 598 | .join(sep)}${doIndent ? `${entries.length > 0 ? ',\n' : ''}${' '.repeat(spaces + level * 2)}` : ' '}}`; |
| 599 | } |
| 600 | |
| 601 | protected serializeValue(val: unknown, wordwrap?: number, spaces?: number, level = 1) { |
| 602 | if (typeof val === 'object' && val !== null) { |
no test coverage detected