DEV Community

Cover image for CFML wrapper for emoji-java (identify, sanitize & convert emojis)
James Moberg
James Moberg

Posted on

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. 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

Enter fullscreen mode Exit fullscreen mode

GitHub Project: cf-emoji-java

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

Billboard image

The fastest way to detect downtimes

Join Vercel, CrowdStrike, and thousands of other teams that trust Checkly to streamline monitoring.

Get started now

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free ā†’

šŸ‘‹ Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay