getCaretPosition = field => {
    // Initialize
    let caretPos = 0;
    if (field.selectionStart || field.selectionStart === 0) {
      // Firefox support
      caretPos = field.selectionDirection === "backward" ? field.selectionStart : field.selectionEnd;
    }
    return caretPos;
  }
Returns the caret (cursor) position of the specified text field (field).
Return value range is 0-field.value.length.