MCPcopy
hub / github.com/postcss/postcss / rangeBy

Method rangeBy

lib/node.js:262–337  ·  view source on GitHub ↗
(opts = {})

Source from the content-addressed store, hash-verified

260 }
261
262 rangeBy(opts = {}) {
263 let inputString =
264 'document' in this.source.input
265 ? this.source.input.document
266 : this.source.input.css
267 let start = {
268 column: this.source.start.column,
269 line: this.source.start.line,
270 offset: sourceOffset(inputString, this.source.start)
271 }
272 let end = this.source.end
273 ? {
274 column: this.source.end.column + 1,
275 line: this.source.end.line,
276 offset:
277 typeof this.source.end.offset === 'number'
278 ? // `source.end.offset` is exclusive, so we don't need to add 1
279 this.source.end.offset
280 : // Since line/column in this.source.end is inclusive,
281 // the `sourceOffset(... , this.source.end)` returns an inclusive offset.
282 // So, we add 1 to convert it to exclusive.
283 sourceOffset(inputString, this.source.end) + 1
284 }
285 : {
286 column: start.column + 1,
287 line: start.line,
288 offset: start.offset + 1
289 }
290
291 if (opts.word) {
292 let stringRepresentation = inputString.slice(
293 sourceOffset(inputString, this.source.start),
294 sourceOffset(inputString, this.source.end)
295 )
296 let index = stringRepresentation.indexOf(opts.word)
297 if (index !== -1) {
298 start = this.positionInside(index)
299 end = this.positionInside(index + opts.word.length)
300 }
301 } else {
302 if (opts.start) {
303 start = {
304 column: opts.start.column,
305 line: opts.start.line,
306 offset: sourceOffset(inputString, opts.start)
307 }
308 } else if (typeof opts.index === 'number') {
309 start = this.positionInside(opts.index)
310 }
311
312 if (opts.end) {
313 end = {
314 column: opts.end.column,
315 line: opts.end.line,
316 offset: sourceOffset(inputString, opts.end)
317 }
318 } else if (typeof opts.endIndex === 'number') {
319 end = this.positionInside(opts.endIndex)

Callers 3

errorMethod · 0.95
constructorMethod · 0.80
node.test.tsFile · 0.80

Calls 2

positionInsideMethod · 0.95
sourceOffsetFunction · 0.85

Tested by

no test coverage detected