| 16 | // returns the name in the badge. This is used when a FlightClient replays inside |
| 17 | // a FlightServer and we capture those replays. |
| 18 | export function unbadgeConsole( |
| 19 | methodName: string, |
| 20 | args: Array<any>, |
| 21 | ): null | string { |
| 22 | let offset = 0; |
| 23 | switch (methodName) { |
| 24 | case 'dir': |
| 25 | case 'dirxml': |
| 26 | case 'groupEnd': |
| 27 | case 'table': { |
| 28 | // These methods cannot be colorized because they don't take a formatting string. |
| 29 | // So we wouldn't have added any badge in the first place. |
| 30 | // $FlowFixMe |
| 31 | return null; |
| 32 | } |
| 33 | case 'assert': { |
| 34 | // assert takes formatting options as the second argument. |
| 35 | offset = 1; |
| 36 | } |
| 37 | } |
| 38 | const format = args[offset]; |
| 39 | const badge = args[offset + 1]; |
| 40 | if ( |
| 41 | typeof format === 'string' && |
| 42 | format.startsWith(badgeFormat) && |
| 43 | typeof badge === 'string' && |
| 44 | badge.startsWith(pad) && |
| 45 | badge.endsWith(pad) |
| 46 | ) { |
| 47 | // Remove our badging from the arguments. |
| 48 | let unbadgedFormat = format.slice(badgeFormat.length); |
| 49 | if (unbadgedFormat[0] === ' ') { |
| 50 | // Spacing added on the Client if the original argument was a string. |
| 51 | unbadgedFormat = unbadgedFormat.slice(1); |
| 52 | } |
| 53 | args.splice(offset, 4, unbadgedFormat); |
| 54 | return badge.slice(padLength, badge.length - padLength); |
| 55 | } |
| 56 | return null; |
| 57 | } |