mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-12 13:05:41 +03:00
improved word extractor
This commit is contained in:
parent
ae34c14870
commit
17046be05e
@ -45,18 +45,23 @@ export const generatePermlink = (title, random = false) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const extractWordAtIndex = (text:string, index:number) => {
|
export const extractWordAtIndex = (text:string, index:number) => {
|
||||||
|
const END_REGEX = /[\s,]/
|
||||||
let word = '';
|
let word = '';
|
||||||
for(let i = index; i >= 0 && text[i] !== ' '; i--){
|
for(let i = index; i >= 0 && (!END_REGEX.test(text[i]) || i === index); i--){
|
||||||
if(text[i]){
|
if(text[i]){
|
||||||
word += text[i];
|
word += text[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
word = word.split('').reverse().join('');
|
word = word.split('').reverse().join('');
|
||||||
for(let i = index + 1; i < text.length && text[i] !== ' '; i++){
|
|
||||||
|
if(!END_REGEX.test(text[index])){
|
||||||
|
for(let i = index + 1; i < text.length && !END_REGEX.test(text[i]); i++){
|
||||||
if(text[i]){
|
if(text[i]){
|
||||||
word += text[i];
|
word += text[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return word;
|
return word;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user