| 27 | * @return The word at the position and its boundaries. |
| 28 | */ |
| 29 | export function getWordAtPosition(str: string, position: number) { |
| 30 | const start = WordStartRegExp.exec(str.substr(0, position)) |
| 31 | const wordStart = _.isNil(start) ? position : start.index |
| 32 | |
| 33 | const end = WordEndRegExp.exec(str.substr(position)) |
| 34 | const wordEnd = position + (_.isNil(end) ? 0 : end[0].length) |
| 35 | |
| 36 | return { word: str.substring(wordStart, wordEnd), start: wordStart, end: wordEnd } |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Checks if a string starts with a whitespace character. |