extractWord = (text, offset) => {
  if (!text || text.length === 0) {
    return null
  } else if (offset < 0) {
    offset = 0
  } else if (offset >= text.length) {
    offset = text.length - 1
  }

  // Matches all words starting at a good position.
  WORD_DEFINITION.lastIndex = text.lastIndexOf(' ', offset - 1) + 1
  let match = null
  let left = -1
  while (match = WORD_DEFINITION.exec(text)) { // eslint-disable-line
    if (match && match.index <= offset) {
      if (WORD_DEFINITION.lastIndex > offset) {
        left = match.index
      }
    } else {
      break
    }
  }
  WORD_DEFINITION.lastIndex = 0

  // Cursor is between two word separators (e.g "*<cursor>*" or " <cursor>*")
  if (left <= -1) {
    return null
  }

  // Find word ending.
  WORD_SEPARATORS.lastIndex = offset
  match = WORD_SEPARATORS.exec(text)
  let right = -1
  if (match) {
    right = match.index
  }
  WORD_SEPARATORS.lastIndex = 0

  // The last word in the string is a special case.
  if (right < 0) {
    return {
      left,
      right: text.length,
      word: text.slice(left)
    }
  }
  return {
    left,
    right: right,
    word: text.slice(left, right)
  }
}
Extract the word at the given offset from the text.

@param {string} text Text
@param {number} offset Normalized cursor offset (e.g. ab<cursor>c def --> 2)