MCPcopy
hub / github.com/postcss/postcss / fromOffset

Method fromOffset

lib/input.js:170–196  ·  view source on GitHub ↗
(offset)

Source from the content-addressed store, hash-verified

168 }
169
170 fromOffset(offset) {
171 let lineToIndex = getLineToIndex(this)
172 let lastLine = lineToIndex[lineToIndex.length - 1]
173
174 let min = 0
175 if (offset >= lastLine) {
176 min = lineToIndex.length - 1
177 } else {
178 let max = lineToIndex.length - 2
179 let mid
180 while (min < max) {
181 mid = min + ((max - min) >> 1)
182 if (offset < lineToIndex[mid]) {
183 max = mid - 1
184 } else if (offset >= lineToIndex[mid + 1]) {
185 min = mid + 1
186 } else {
187 min = mid
188 break
189 }
190 }
191 }
192 return {
193 col: offset - lineToIndex[min] + 1,
194 line: min + 1
195 }
196 }
197
198 mapResolve(file) {
199 if (/^\w+:\/\//.test(file)) {

Callers 3

errorMethod · 0.95
getPositionMethod · 0.80
input.test.tsFile · 0.80

Calls 1

getLineToIndexFunction · 0.85

Tested by

no test coverage detected