MCPcopy Create free account
hub / github.com/Effect-TS/effect / lineNumberAt

Function lineNumberAt

packages/tools/doctest/src/Source.ts:32–48  ·  view source on GitHub ↗
(source: string)

Source from the content-addressed store, hash-verified

30const namePattern = /(?:^|\s)name=(?:"([^"]+)"|'([^']+)'|([^\s]+))/
31
32const lineNumberAt = (source: string): (offset: number) => number => {
33 const starts = [0]
34 for (let index = 0; index < source.length; index++) {
35 if (source.charCodeAt(index) === 10) starts.push(index + 1)
36 }
37
38 return (offset) => {
39 let low = 0
40 let high = starts.length
41 while (low < high) {
42 const middle = (low + high) >>> 1
43 if (starts[middle] <= offset) low = middle + 1
44 else high = middle
45 }
46 return low
47 }
48}
49
50const snippets = (
51 text: string,

Callers 1

extractFunction · 0.85

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected