MCPcopy Create free account
hub / github.com/HiDeoo/YaTA / getWordAtPosition

Function getWordAtPosition

src/utils/string.ts:29–37  ·  view source on GitHub ↗
(str: string, position: number)

Source from the content-addressed store, hash-verified

27 * @return The word at the position and its boundaries.
28 */
29export 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.

Callers 1

InputClass · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected