MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / snipLine

Function snipLine

packages/core/src/utils/string.ts:28–61  ·  view source on GitHub ↗
(line: string, colno: number)

Source from the content-addressed store, hash-verified

26 * @returns string Encoded
27 */
28export 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

Callers 2

addContextToFrameFunction · 0.90
getContextLinesFromFileFunction · 0.90

Calls 1

sliceMethod · 0.80

Tested by

no test coverage detected