-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix bbcode auto transform logic #196
- Loading branch information
1 parent
5cf5bb7
commit 5f81459
Showing
3 changed files
with
35 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { emojiData } from './const'; | ||
|
||
export function isEmojiCode(code: string): boolean { | ||
return Object.keys(emojiData.emojis).includes(code); | ||
} | ||
|
||
/** | ||
* Removes colons on either side | ||
* of the string if present | ||
*/ | ||
export function stripColons(str: string): string { | ||
const colonIndex = str.indexOf(':'); | ||
if (colonIndex > -1) { | ||
// :emoji: (http://www.emoji-cheat-sheet.com/) | ||
if (colonIndex === str.length - 1) { | ||
str = str.substring(0, colonIndex); | ||
return stripColons(str); | ||
} else { | ||
str = str.substr(colonIndex + 1); | ||
return stripColons(str); | ||
} | ||
} | ||
|
||
return str; | ||
} |