CFML wrapper for emoji-java (identify, sanitize & convert emojis)

A ColdFusion application that we developed a couple years ago worked with Twilio to log incoming text messages. The UTF-8 message payloads were saved in a MSSQL database using the NVARCHAR datatype and could be displayed on webpages without any issue….


This content originally appeared on DEV Community and was authored by James Moberg

A ColdFusion application that we developed a couple years ago worked with Twilio to log incoming text messages. The UTF-8 message payloads were saved in a MSSQL database using the NVARCHAR datatype and could be displayed on webpages without any issue. When importing a CSV file into a third-party Windows program, a random error would cause the import to abort whenever it encountered a high ASCII character. We didn't want to strip out the data, but we also didn't want to convert emojis to HTML entities or decimal values as they would be somewhat meaningless outside of an HTML environment.

That's when we discovered the email-java java library. It bills itself as the "The missing emoji library for Java" and really does add many emoji-specific features that aren't natively available in Java (or ColdFusion).

Here's a cf-email-java wrapper to help identify, sanitize and convert emojis in CFML projects. (NOTE: This my first time I creating a project in Github versus just creating a simple gist.)

For the CSV export, we used the parseToAliases method on the strings and messages like I like 🍕 were converted to I like :pizza:.

Here's some examples of functionality.

emojijava.isEmoji('❤️');       // true
emojijava.isEmoji('I ❤️ 🍕');  // false

emojijava.containsEmoji('I ❤️ 🍕');  // true

emojijava.isOnlyEmojis('I ❤️ 🍕');   // false
emojijava.isOnlyEmojis('👁 ❤️ 🍕');  // true

emojijava.parseToAliases('I like 🍕');   // I like :pizza:

emojijava.parseToHtmlDecimal('I ❤️ 🍕');   // I ❤️ 🍕

emojijava.parseToHtmlHexadecimal('I ❤️ 🍕');   // I ❤️ 🍕

emojijava.removeAllEmojis('I ❤️ 🍕');   // I

emojijava.removeAllEmojisExcept('I ❤️ 🍕', "pizza");   // I  🍕

emojijava.removeEmojis(text, "pizza");  // I ❤️

emojijava.removeEmojis('I ❤️ 🍕', "[emoji]");  // I [emoji] [emoji]

emojijava.extractEmojis('I ❤️ 🍕');  // I ["❤️", "🍕"]
emojijava.extractEmojis('I ❤️ 🍕', true);  // an array of structs w/emoji data

GitHub Project: cf-emoji-java

https://github.com/JamoCA/cf-emoji-java


This content originally appeared on DEV Community and was authored by James Moberg


Print Share Comment Cite Upload Translate Updates
APA

James Moberg | Sciencx (2024-09-12T15:49:11+00:00) CFML wrapper for emoji-java (identify, sanitize & convert emojis). Retrieved from https://www.scien.cx/2024/09/12/cfml-wrapper-for-emoji-java-identify-sanitize-convert-emojis/

MLA
" » CFML wrapper for emoji-java (identify, sanitize & convert emojis)." James Moberg | Sciencx - Thursday September 12, 2024, https://www.scien.cx/2024/09/12/cfml-wrapper-for-emoji-java-identify-sanitize-convert-emojis/
HARVARD
James Moberg | Sciencx Thursday September 12, 2024 » CFML wrapper for emoji-java (identify, sanitize & convert emojis)., viewed ,<https://www.scien.cx/2024/09/12/cfml-wrapper-for-emoji-java-identify-sanitize-convert-emojis/>
VANCOUVER
James Moberg | Sciencx - » CFML wrapper for emoji-java (identify, sanitize & convert emojis). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/09/12/cfml-wrapper-for-emoji-java-identify-sanitize-convert-emojis/
CHICAGO
" » CFML wrapper for emoji-java (identify, sanitize & convert emojis)." James Moberg | Sciencx - Accessed . https://www.scien.cx/2024/09/12/cfml-wrapper-for-emoji-java-identify-sanitize-convert-emojis/
IEEE
" » CFML wrapper for emoji-java (identify, sanitize & convert emojis)." James Moberg | Sciencx [Online]. Available: https://www.scien.cx/2024/09/12/cfml-wrapper-for-emoji-java-identify-sanitize-convert-emojis/. [Accessed: ]
rf:citation
» CFML wrapper for emoji-java (identify, sanitize & convert emojis) | James Moberg | Sciencx | https://www.scien.cx/2024/09/12/cfml-wrapper-for-emoji-java-identify-sanitize-convert-emojis/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.