import { getGapMap } from "./getGapMap";

/**
 * this function is used to calculate the number of spaces that come before or inside a range
 */
export var getGaps = function getGaps() {
  return {
    gapsBefore: 0,
    gapsInside: 0
  };
};
getGaps = function getGaps(rangeOrCaretPosition, sequence) {
  var gapMap = getGapMap(sequence);
  if (typeof rangeOrCaretPosition !== "object") {
    return {
      gapsBefore: gapMap[Math.min(rangeOrCaretPosition, gapMap.length - 1)]
    };
  }
  //otherwise it is a range!
  var start = rangeOrCaretPosition.start,
    end = rangeOrCaretPosition.end;
  var toReturn = {
    gapsBefore: gapMap[start],
    gapsInside: gapMap[Math.min(end, gapMap.length - 1)] - gapMap[Math.min(start, gapMap.length - 1)]
  };
  return toReturn;
};