Created
December 5, 2022 18:49
-
-
Save josefaidt/6e46c0e671c54317c51f4d889f716a67 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
const regex = /<(?<tag>[^>]*)>/; | |
/** | |
* Verifies whether the string is an HTML string | |
* @param str string to check | |
*/ | |
export const isHtmlString = (str: string): boolean => { | |
// <code>hello world</code> -> true | |
// hello <code>world</code> -> true | |
// hello world -> false | |
return regex.test(str); | |
}; | |
/** | |
* Verifies whether the string is an HTML inline code block string | |
* @param str string to check | |
*/ | |
export const isHtmlCodeTagString = (str: string): boolean => { | |
const result = regex.exec(str); | |
return result?.groups?.tag === 'code'; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment