Text methods
- Source:
Methods
(static) cleanText(content, filterCharsopt) → {Array.<string>}
Cleans text and strips out unwanted symbols/patterns.
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
content |
string
|
the chunk of text we will be operating on | ||
filterChars |
boolean
|
<optional> |
true | whether or not we want to filter out single characters |
Returns:
- Type:
-
Array.<string>
An array of cleaned text (tokens) we consider to be spell checkable
(static) cleanWord(content) → {string}
A wrapper around cleanText that doesn't filter out characters and returns only the first result
of the cleaned content.
- Source:
- See:
-
- cleanText
Parameters:
Name | Type | Description |
---|---|---|
content |
string
|
the chunk of text to operate i.e. '100 bouncy balls' |
Returns:
- Type:
-
string
The first valid word i.e. 'bouncy'
(static) getCurrentMark(misspeltWord, index, highlights) → {Node}
Gets the exact mark that we will use to insert word suggestions based on a known index. The index
is relative to how many times the misspelt word appears inside the highlighter.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
misspeltWord |
string
|
the misspelt word the mark is positioned over |
index |
number
|
the relative index of the misspelt word if it appears more than once |
highlights |
node
|
the node containing the highlights (child nodes) we will be searching |
Returns:
- Type:
-
Node
The currently focused mark according to a known relative index
(static) getCurrentWordBounds(node) → {Array}
Get current word bounds based on selection (if selection present) or get boundaries based on the
current caret position within a text node
- Source:
Parameters:
Name | Type | Description |
---|---|---|
node |
node
|
the node to operate on |
Returns:
- Type:
-
Array
An array containing the word, start index, and end index i.e. ['boom', 0, 3]
(static) getMatchingMarkIndex(content, word) → {number}
Get the relative index of a Mark by matching the Word boundaries against the chunk of text being
spellchecked. This is needed for when duplicate misspelt words appear inside of a textarea. The
matching mark index is based on the Word boundaries, since a Word always has start and end values
relative to where it appears inside of the content it was created from.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
content |
string
|
the chunk of text we will operate on |
word |
Word
|
the Word we are searching for |
Returns:
- Type:
-
number
An index representing the exact position of a word inside content
(static) getRelativeBounds(word, content, startIndex) → {Array|undefined}
Get the relative boundaries of a word given a specific start index
- Source:
Parameters:
Name | Type | Default | Description |
---|---|---|---|
word |
string
|
the word we are searching for within content | |
content |
string
|
the chunk of text being operated on | |
startIndex |
number
|
0 | the index from where to begin searching content from |
Returns:
- Type:
-
Array
|undefined
An array containing the start and end bounds of a word or undefined
if word or content undefined
(static) getSelectionBounds(node) → {Object}
Get the selection boundaries of a given node. For now only supports textareas.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
node |
Node
|
the node we will operate on |
Returns:
- Type:
-
Object
An object with start and end parameters or an empty object if node is not
supported
(static) getTextContent(node) → {string}
Conditionally return the text content of a node (including line breaks) based on the node type.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
node |
Node
|
the node we will operate on |
Returns:
- Type:
-
string
The text content (including line breaks) of the node
(static) getWordBoundsFromCaret(node, text, startIndex) → {Array}
Gets the currently focused word and it's boundaries based on caret position.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
node |
Node
|
the node we will operate on |
text |
string
|
the text content used to generate a word selection from |
startIndex |
number
|
the index from where we will begin building our word |
Returns:
- Type:
-
Array
An array containing the word, start index, and end index
(static) isWholeWord(word, content, start) → {boolean}
Search content for an exact match of the given word as of start (or elsewhere).
- Source:
Parameters:
Name | Type | Description |
---|---|---|
word |
string
|
the sequence of characters we are testing appears as a whole word |
content |
string
|
text content to be tested with regex |
start |
number
|
mandatory index that represents exactly where word begins inside content |
Returns:
- Type:
-
boolean
True if a word appears at least once as a whole word (as of start)
(static) replaceInText(content, word, replacement) → {string}
Replace a Word inside of content with replacement by using the Word's boundaries
- Source:
Parameters:
Name | Type | Description |
---|---|---|
content |
string
|
the content on which to operate on |
word |
Word
|
the Word we are going to replace |
replacement |
string
|
the string of text used to replace the Word |
Returns:
- Type:
-
string
The modified content that has the replacement in place of the Word
(static) storeSelection(node) → {function}
Used to store and then restore a previous selection/caret position.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
node |
Node
|
a node that has start and end selection values |
Returns:
- Type:
-
function
The function that will be use to later restore the selection