Emoji
Emoji for chat and comments: :shortcodes: turned into emoji and back, emoji found with their names, stripped from subjects, and searched by name for a picker.
Version 1.0.0 · 5 functions · 2 crates
Functions
What use emoji.qwer gives a program, with the types Quillo sees. To take only some, or under other names: use emoji_from_shortcodes, emoji_to_shortcodes from emoji (Quillo 0.6).
emoji_from_shortcodes(text: str) → stror an errortext with GitHub and Slack shortcodes as emoji: "Shipped :tada: :+1:" is "Shipped 🎉 👍". Unknown ones such as ":nope:" stay as they are.
emoji_to_shortcodes(text: str) → stror an errortext with each emoji as its shortcode: "Shipped 🎉" is "Shipped :tada:", for plain-text logs and systems without emoji. One without a shortcode stays.
emoji_find(text: str) → listor an errorThe emoji in text, in order, as [{ emoji, name, shortcode }]: "👍🏽" is one, with its skin tone, and flags and families count as one.
emoji_strip(text: str) → stror an errortext without its emoji, the spaces around them tidied: for subjects, slugs and SMS.
emoji_search(query: str, limit: int) → listEmoji whose name or shortcode holds query, as [{ emoji, name, shortcode }], at most limit (up to 200): "heart" finds ❤️, 💔, 😍... for an emoji picker.
Get it
$ quillo install emoji # emoji.qwer into this folder$ quillo install emoji --example # and its example, emoji.qweOr with curl:
$ curl -O https://quillolang.org/plugins/files/emoji.qwer$ curl -O https://quillolang.org/plugins/files/emoji.qweThen, in your program, all of it or only what you call:
use emoji.qweruse emoji_from_shortcodes, emoji_to_shortcodes from emoji // Quillo 0.6: only theseIt uses these crates, which cargo fetches the first time the plugin is built:
emojis = "0.9"unicode-segmentation = "1.12"Example
// Chat messages with :shortcodes:, and a picker that searches emoji by name.//// quillo run emoji.qwe then open http://localhost:8080/message?text=Shipped%20it%20:tada:%20:+1:use "emoji.qwer"route GET /message ? { text: str } { let shown = emoji_from_shortcodes(text)? { shown, emoji: emoji_find(shown)?, log: emoji_to_shortcodes(shown)?, subject: emoji_strip(shown)? }}route GET /picker ? { q: str = "heart" } = emoji_search(q, 8)route GET /find = emoji_find("Thanks 👍🏽 from 🇫🇷 👨👩👧")?$ quillo run emoji.qwe$ curl 'localhost:8080/message?text=Shipped%20it%20:tada:%20:%2B1:%20at%2010:30'$ curl 'localhost:8080/find'Source
//! Emoji for chat and comments: shortcodes such as :tada: turned into 🎉 and back, emoji found, named and stripped, and searched by name for a picker.//! version: 1.0.0//!//! [dependencies]//! emojis = "0.9"//! unicode-segmentation = "1.12"use serde_json::{json, Value};use unicode_segmentation::UnicodeSegmentation;const MAX: usize = 1_000_000;fn check(text: &str) -> Result<(), String> { if text.len() > MAX { Err("text up to 1 MB".into()) } else { Ok(()) }}fn info(e: &emojis::Emoji) -> Value { json!({ "emoji": e.as_str(), "name": e.name(), "shortcode": e.shortcode() })}/// `text` with GitHub and Slack shortcodes as emoji: "Shipped :tada: :+1:" is "Shipped 🎉 👍". Unknown ones such as ":nope:" stay as they are.pub fn emoji_from_shortcodes(text: &str) -> Result<String, String> { check(text)?; let mut out = String::with_capacity(text.len()); let mut rest = text; while let Some(i) = rest.find(':') { out.push_str(&rest[..i]); let after = &rest[i + 1..]; match after.find(':') { Some(j) if j > 0 && after[..j].chars().all(|c| c.is_ascii_alphanumeric() || "_+-".contains(c)) => { if let Some(e) = emojis::get_by_shortcode(&after[..j]) { out.push_str(e.as_str()); rest = &after[j + 1..]; continue; } out.push(':'); rest = after; } _ => { out.push(':'); rest = after; } } } out.push_str(rest); Ok(out)}/// `text` with each emoji as its shortcode: "Shipped 🎉" is "Shipped :tada:", for plain-text logs and systems without emoji. One without a shortcode stays.pub fn emoji_to_shortcodes(text: &str) -> Result<String, String> { check(text)?; Ok(text.graphemes(true).map(|g| match emojis::get(g).and_then(|e| e.shortcode()) { Some(s) => format!(":{}:", s), None => g.to_string(), }).collect())}/// The emoji in `text`, in order, as `[{ emoji, name, shortcode }]`: "👍🏽" is one, with its skin tone, and flags and families count as one.pub fn emoji_find(text: &str) -> Result<Vec<Value>, String> { check(text)?; Ok(text.graphemes(true).filter_map(emojis::get).map(info).collect())}/// `text` without its emoji, the spaces around them tidied: for subjects, slugs and SMS.pub fn emoji_strip(text: &str) -> Result<String, String> { check(text)?; let s: String = text.graphemes(true).filter(|g| emojis::get(g).is_none()).collect(); Ok(s.split(' ').filter(|w| !w.is_empty()).collect::<Vec<_>>().join(" "))}/// Emoji whose name or shortcode holds `query`, as `[{ emoji, name, shortcode }]`, at most `limit` (up to 200): "heart" finds ❤️, 💔, 😍... for an emoji picker.pub fn emoji_search(query: &str, limit: i64) -> Vec<Value> { let q = query.trim().to_lowercase(); emojis::iter() .filter(|e| e.skin_tone().map_or(true, |t| t == emojis::SkinTone::Default)) .filter(|e| e.name().contains(&q) || e.shortcodes().any(|s| s.contains(&q))) .take(limit.clamp(0, 200) as usize) .map(info) .collect()}Related
kana.qwer · 1.0.0Japanese kana: romaji typed as hiragana or katakana, kana written in Hepburn romaji, hiragana and katakana each to the other, half-width katakana from bank and till systems made full-width, and which scripts a text uses.6 views · 10 downloadsSlugs slug.qwer · 1.0.0Slugs for addresses from titles in any script, unique ones for a blog, and text transliterated to ASCII.7 views · 8 downloadsUnicode unicode.qwer · 1.0.0Unicode text made comparable and measured: NFC and NFKC forms, accents removed, characters counted as people see them, safe truncation and terminal width.5 views · 8 downloadsBraille braille.qwer · 1.0.0Unicode braille from English text: grade 1 letter by letter, and Unified English Braille grade 2 with its wordsigns, groupsigns, positional rules and shortforms; read back cell by cell where the cells allow it; dot numbers and the Braille ASCII of `.brf` files both ways.3 views · 6 downloadsCase case.qwer · 1.0.0Text in snake_case, camelCase, PascalCase, kebab-case, CONSTANT_CASE, Title Case and Sentence case: column names as API keys and labels.7 views · 8 downloadsChinese words chinese_segment.qwer · 1.0.0Chinese text split into words for search indexes and counts, with parts of speech, and written in pinyin with tones, tone numbers or initials for sorting and finding names.7 views · 7 downloadsThread 0 posts
On Emoji: questions, tips, corrections, and code that uses it.
No posts yet. The first one opens the thread.