Created
June 16, 2023 17:51
-
-
Save marlondenisck/d0e5ee28a98bcd5af7bf905cb616d89f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let users = ourStore.users; | |
| let stringWithUsername = "Hello @efog, how do you feel today?"; | |
| let processed = processString([{ | |
| regex: /\@([a-z0-9_\-]+?)( |\,|$|\.)/gim, //regex to match a username | |
| fn: (key, result) => { | |
| let username = result[1]; | |
| let foundUsers = users.filter(user => user.username === username); | |
| if (!foundUsers.length) | |
| return result[0]; //@username | |
| return <a key={key} href={`/user/${username}`}>@{username}</a>; | |
| } | |
| }]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment