(line: string, colno: number)
| 26 | * @returns string Encoded |
| 27 | */ |
| 28 | export function snipLine(line: string, colno: number): string { |
| 29 | let newLine = line; |
| 30 | const lineLength = newLine.length; |
| 31 | if (lineLength <= 150) { |
| 32 | return newLine; |
| 33 | } |
| 34 | if (colno > lineLength) { |
| 35 | // eslint-disable-next-line no-param-reassign |
| 36 | colno = lineLength; |
| 37 | } |
| 38 | |
| 39 | let start = Math.max(colno - 60, 0); |
| 40 | if (start < 5) { |
| 41 | start = 0; |
| 42 | } |
| 43 | |
| 44 | let end = Math.min(start + 140, lineLength); |
| 45 | if (end > lineLength - 5) { |
| 46 | end = lineLength; |
| 47 | } |
| 48 | if (end === lineLength) { |
| 49 | start = Math.max(end - 140, 0); |
| 50 | } |
| 51 | |
| 52 | newLine = newLine.slice(start, end); |
| 53 | if (start > 0) { |
| 54 | newLine = `'{snip} ${newLine}`; |
| 55 | } |
| 56 | if (end < lineLength) { |
| 57 | newLine += ' {snip}'; |
| 58 | } |
| 59 | |
| 60 | return newLine; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Join values in array |
no test coverage detected