code: function buildLineToIndex(str) {
    var lines = str.split("\n"),
        lineToIndex = new Array(lines.length),
        index = 0;
  
    for (var i = 0, l = lines.length; i < l; i++) {
      lineToIndex[i] = index;
      index += lines[i].length + /* "\n".length */ 1;
    }
    return lineToIndex;
  }
docs: Build an array of indexes of each line from a string.
  
  @private
  @param   str {string}  An input string.
  @return  {number[]}    Built array of indexes. The key is line number.