src/main/core.js/ensureIndexInText
function ensureIndexInText(text, index, defaultValue) {
  if (
    typeof index !== "number" ||
    isNaN(index) ||
    index < 0 ||
    index > text.length
  ) {
    return defaultValue;
  }

  return index;
}