Add base function to check for valid lucide icon

Use case or problem

I have a text property that contains either a link to an image, an emoji or a lucide icon name. This is handled well by the pretty properties plugin, showing it visually as an icon next to the note title in all 3 cases. To do the same in a base wasn’t as straight forward, as there is currently no function to differentiate these types easily.

I can easily distinguish an image link or file from the other types by using the isType function and checking for “link” or “url” types and then use the image function if both are true:
if(image.isType("link") || image.isType("url"), image(image), "-")

That still leaves the distinction between lucide icon names and emoji, which I couldn’t get working with low effort. I would have expected a formula like this to work, but it doesn’t:
if(image.isType("link") || image.isType("url"), image(image), if(icon(image).isType("icon") == icon(image), icon))

According to the docs the icon function is supposed to return an object of type icon:


…but when I test the returned type it seems to always be a string, no matter if it is valid or not.
icon(image).isType("icon") → always false
icon(image).isType("string") → always true

Proposed solution

Add a function for detecting whether or not a string is a valid lucide icon, or have the icon function actually return an object of type “icon” if valid and return null when no match is found.

Current workaround

Instead of detecting whether or not the string is a valid lucide icon, I check whether or not it is an emoji using the regex from here.

My current formula to create a visual from an image file or link, a lucide icon name or an emoji:
if(image.isType("link") || image.isType("url"), image(image), if(/(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])/g.matches(image), image, icon(image)))

Related feature requests (optional)