Skip to content

Instantly share code, notes, and snippets.

@sineemore
Created July 31, 2019 21:17
Show Gist options
  • Save sineemore/114435fc32f5194ac0db55126d8b4d79 to your computer and use it in GitHub Desktop.
Save sineemore/114435fc32f5194ac0db55126d8b4d79 to your computer and use it in GitHub Desktop.
class NodeMarkup {
// class...
spanWord({start, end}) {
const space = /\s/
const word = /[^\s]/
while (start < this.text.length - 1 && space.test(this.text[start]))
start++
while (start > 0 && word.test(this.text[start - 1]))
start--
while (end > 0 && space.test(this.text[end]))
end--
while (end < this.text.length - 1 && word.test(this.text[end]))
end++
if (start >= end) {
return false
return {start, end}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment