index.js
function readSource (source, from, to, offset, delimiter) {
  // fix args
  from = from | 0
  to = to | 0 || from
  delimiter = delimiter || PREVIEW_OPTS.delimiter

  if (typeof offset === 'undefined') {
    offset = PREVIEW_OPTS.offset
  } else {
    offset = offset | 0
  }

  let lastIdx = -1
  let currIdx = lastIdx
  let line = 1
  let reads = []

  from -= offset
  to += offset

  while (currIdx < source.length) {
    currIdx = source.indexOf(delimiter, lastIdx + 1)
    if (currIdx < 0) {
      currIdx = source.length
    }

    if (line > to) {
      break
    } else if (line >= from && line <= to) {
      reads.push({
        number: line,
        source: source.substring(lastIdx + delimiter.length, currIdx)
      })
    }

    lastIdx = currIdx
    line ++
  }

  return reads
}
function readSource (source, from, to, offset, delimiter) {
  // fix args
  from = from | 0
  to = to | 0 || from
  delimiter = delimiter || PREVIEW_OPTS.delimiter

  if (typeof offset === 'undefined') {
    offset = PREVIEW_OPTS.offset
  } else {
    offset = offset | 0
  }

  let lastIdx = -1
  let currIdx = lastIdx
  let line = 1
  let reads = []

  from -= offset
  to += offset

  while (currIdx < source.length) {
    currIdx = source.indexOf(delimiter, lastIdx + 1)
    if (currIdx < 0) {
      currIdx = source.length
    }

    if (line > to) {
      break
    } else if (line >= from && line <= to) {
      reads.push({
        number: line,
        source: source.substring(lastIdx + delimiter.length, currIdx)
      })
    }

    lastIdx = currIdx
    line ++
  }

  return reads
}
function readSource ( source , from , to , offset , delimiter ) { // fix args from = from | 0 to = to | 0 || from delimiter = delimiter || PREVIEW_OPTS . delimiter if ( typeof offset === 'undefined' ) { offset = PREVIEW_OPTS . offset } else { offset = offset | 0 } let lastIdx = - 1 let currIdx = lastIdx let line = 1 let reads = [ ] from -= offset to += offset while ( currIdx < source . length ) { currIdx = source . indexOf ( delimiter , lastIdx + 1 ) if ( currIdx < 0 ) { currIdx = source . length } if ( line > to ) { break } else if ( line >= from && line <= to ) { reads . push ( { number : line , source : source . substring ( lastIdx + delimiter . length , currIdx ) } ) } lastIdx = currIdx line ++ } return reads }
Read source by line number

Return: [
{
number: Number,
source: String
},
...
]

@param  {String} source
@param  {Number} from
@param  {Number} to (optional)
@param  {Number} offset (optional)
@param  {String} delimiter (optional)
@return {Array} Source splitd by line
Read source by line number