(object)
| 8 | } |
| 9 | |
| 10 | stringify(object) { |
| 11 | let matched = false; |
| 12 | let string = ''; |
| 13 | if (typeof(object) === 'object' && object !== null) { |
| 14 | if (Array.isArray(object)) { |
| 15 | string += '['; |
| 16 | let i = 0; |
| 17 | for (const element of object) { |
| 18 | // separator |
| 19 | if (i++ !== 0) { |
| 20 | string += ', '; |
| 21 | } |
| 22 | |
| 23 | // stringify the element |
| 24 | const result = this.stringify(element); |
| 25 | if (!result) { |
| 26 | return null; |
| 27 | } |
| 28 | string += result.string; |
| 29 | matched = matched || result.matched; |
| 30 | } |
| 31 | string += ']'; |
| 32 | } else { |
| 33 | string += '{'; |
| 34 | let i = 0; |
| 35 | for (const key of Object.keys(object)) { |
| 36 | let result; |
| 37 | |
| 38 | // separator |
| 39 | if (i++ !== 0) { |
| 40 | string += ', '; |
| 41 | } |
| 42 | |
| 43 | // stringify the key |
| 44 | result = this.stringify(key); |
| 45 | if (!result) { |
| 46 | return null; |
| 47 | } |
| 48 | string += result.string; |
| 49 | matched = matched || result.matched; |
| 50 | |
| 51 | // separator |
| 52 | string += ': '; |
| 53 | |
| 54 | // stringify the value |
| 55 | result = this.stringify(object[key]); |
| 56 | if (!result) { |
| 57 | return null; |
| 58 | } |
| 59 | string += result.string; |
| 60 | matched = matched || result.matched; |
| 61 | } |
| 62 | string += '}'; |
| 63 | } |
| 64 | } else { |
| 65 | // non-string objects are just converted, strings are matched and highlighted |
| 66 | if (typeof(object) !== 'string') { |
| 67 | string += String(object); |
no test coverage detected