emoji-hub-api-client
v1.0.0
Published
A lightweight JavaScript and TypeScript client for the EmojiHub API, allowing easy access to emojis by category, group, search, and random selection.
Downloads
109
Maintainers
Readme
Emoji Hub API Client
A lightweight JavaScript/TypeScript client for the EmojiHub API (https://github.com/cheatsnake/emojihub), providing easy access to emojis by category, group, search, and random selection. This package is ESM-only and works in modern browsers and Node.js 18+ environments that support the Fetch API.
📦 Installation
npm install emoji-hub-api-clientNote: If you are using Node.js, ensure your project supports ES modules.
🎲 Features
- Lightweight & fast — minimal abstraction over the EmojiHub API
- Zero dependencies — uses the native fetch API
- JavaScript & TypeScript support — includes type definitions out of the box
- Search emojis by name
- Fetch random emojis
- Filter emojis by category or group
- Retrieve all available categories and groups
📚 API Functions
The emoji-hub-api-client package exposes the following functions:
getAllEmojiCategories(): Retrieve a list of all available emoji categories.getAllEmojiGroups(): Retrieve a list of all available emoji groups.getAllEmojis(): Fetch all emojis available in the EmojiHub API.getRandomEmoji(): Fetch a single random emoji.getRandomEmojiByCategory(): Fetch a random emoji from a specific category.getRandomEmojiByGroup(): Fetch a random emoji from a specific group.searchEmojisByName(): Search emojis by name.searchSimilarEmojisByName(): Retrieve emojis with names similar to the provided emoji name.
🔤 Example Usage
- Get All Emoji Categories
import { getAllEmojiCategories } from "emoji-hub-api-client";
async function run() {
const response = await getAllEmojiCategories();
if (response.code === "api-ok" && response.payload) {
console.log(response.payload.categories);
} else {
console.error("Failed to fetch categories:", response.message);
}
}
run();
// 200:OK
/*
{
"code": "api-ok",
"message": "No error encountered",
"payload": {
"categories": [
"smileys and people",
"animals and nature",
"food and drink",
"travel and places"
...
...
]
}
}
*/
// Error
/*
{
code: "api-fail",
message: "Get All Emoji Categories: Encountered Error!",
payload: null
}
*/- Get All Emoji Groups
import { getAllEmojiGroups } from "emoji-hub-api-client";
async function run() {
const response = await getAllEmojiGroups();
if (response.code === "api-ok" && response.payload) {
console.log(response.payload.groups);
} else {
console.error("Failed to fetch groups:", response.message);
}
}
run();
// 200:OK
/*
{
"code": "api-ok",
"message": "No error encountered",
"payload": {
"groups": [
"face positive",
"face neutral",
"face negative",
"animal mammal",
"animal bird"
...
...
...
]
}
}
*/
// Error
/* { code: "api-fail", message: "Get All Emoji Groups: Encountered Error", payload: null }; */- Get All Emojis
import { getAllEmojis } from "emoji-hub-api-client";
async function run() {
const response = await getAllEmojis();
if (response.code === "api-ok" && response.payload) {
// Log the first emoji as a sample
console.log("Sample emoji:", response.payload[0]);
} else {
console.error("Failed to fetch emojis:", response.message);
}
}
run();
// 200:OK
/*
{
"code": "api-ok",
"message": "No error encountered",
"payload": [
{
"name": "grinning face",
"category": "smileys and people",
"group": "face positive",
"htmlCode": ["😀"],
"unicode": ["U+1F600"]
}
...
...
...
]
}
*/
// Error
/*
{
code: "api-fail",
message: "Get All Emoji: Encountered Error!",
payload: null
}
*/- Get A Random Emoji
import { getRandomEmoji } from "emoji-hub-api-client";
async function run() {
const response = await getRandomEmoji();
if (response.code === "api-ok" && response.payload) {
console.log(response.payload);
} else {
console.error("Failed to fetch random emoji:", response.message);
}
}
run();
// 200:OK
/*
{
"code": "api-ok",
"message": "No error encountered",
"payload": {
"name": "rocket",
"category": "travel and places",
"group": "transport air",
"htmlCode": ["🚀"],
"unicode": ["U+1F680"]
}
}
*/
// Error
/*
{
code: "api-fail",
message: "Get Random Emoji: Encountered Error!",
payload: null
}
*/- Get a Random Emoji by Category
/* Note: To get the type of categories, check the getAllEmojiCategories() function response */
import { getRandomEmojiByCategory } from "emoji-hub-api-client";
async function run() {
const response = await getRandomEmojiByCategory({
category: "smileys-and-people" /* join with hyphen if there are more than 2 words */
});
if (response.code === "api-ok" && response.payload) {
console.log(response.payload);
} else {
console.error("Failed to fetch random emoji by category:", response.message);
}
}
run();
// 200:OK
/*
{
"code": "api-ok",
"message": "No error encountered",
"payload": {
"name": "grinning face",
"category": "smileys and people",
"group": "face positive",
"htmlCode": ["😀"],
"unicode": ["U+1F600"]
}
}
*/
// Error
/*
{
code: "api-fail",
message: "Get Random Emoji By Category: Encountered Error!",
payload: null
}
*/- Get Random Emoji By Group
/* Note: to get the names of the groups, check the getAllEmojiGroups() function response */
import { getRandomEmojiByGroup } from "emoji-hub-api-client";
async function run() {
const response = await getRandomEmojiByGroup({
group: "face-positive" /* join with hyphen if there are more than 2 words*/
});
if (response.code === "api-ok" && response.payload) {
console.log(response.payload);
} else {
console.error("Failed to fetch random emoji by group:", response.message);
}
}
run();
// 200:OK
/*
{
"code": "api-ok",
"message": "No error encountered",
"payload": {
"name": "smiling face with sunglasses",
"category": "smileys and people",
"group": "face positive",
"htmlCode": ["😎"],
"unicode": ["U+1F60E"]
}
}
*/
// Error
/*
{
code: "api-fail",
message: "Get Random Emoji By Group: Encountered Error!",
payload: null
}
*/- Search An Emoji By Name/Query
import { searchEmojisByName } from "emoji-hub-api-client";
async function run() {
const response = await searchEmojisByName({
query: "smile"
});
if (response.code === "api-ok" && response.payload) {
console.log(`Total results: ${response.payload.totalResults}`);
console.log(response.payload.results);
} else {
console.error("Failed to search emojis:", response.message);
}
}
run();
// 200:OK
/*
{
"code": "api-ok",
"message": "No error encountered",
"payload": {
"totalResults": 2,
"results": [
{
"name": "smiling face",
"category": "smileys and people",
"group": "face positive",
"htmlCode": ["😊"],
"unicode": ["U+1F642"]
},
{
"name": "smiling face with sunglasses",
"category": "smileys and people",
"group": "face positive",
"htmlCode": ["😎"],
"unicode": ["U+1F60E"]
}
]
}
}
*/
// Error
/*
{
code: "api-fail",
message: "Search Emoji(s) By Name: Encountered Error!",
payload: null
}
*/- Get Similar Emoji(s) By Name/Query
import { searchSimilarEmojisByName } from "emoji-hub-api-client";
async function run() {
const response = await searchSimilarEmojisByName({
query: "heart"
});
if (response.code === "api-ok" && response.payload) {
console.log(`Total similar emojis found: ${response.payload.totalResults}`);
console.log(response.payload.results);
} else {
console.error("Failed to search similar emojis:", response.message);
}
}
run();
// 200:OK
/*
{
"code": "api-ok",
"message": "No error encountered",
"payload": {
"totalResults": 3,
"results": [
{
"name": "red heart",
"category": "smileys and people",
"group": "emotion",
"htmlCode": ["❤"],
"unicode": ["U+2764"]
},
{
"name": "orange heart",
"category": "smileys and people",
"group": "emotion",
"htmlCode": ["🟧"],
"unicode": ["U+1F9E7"]
},
{
"name": "yellow heart",
"category": "smileys and people",
"group": "emotion",
"htmlCode": ["💛"],
"unicode": ["U+1F49B"]
}
]
}
}
*/
// Error
/*
{
code: "api-fail",
message: "Search Similar Emoji(s) By Name: Encountered Error!",
payload: null
}
*/📘 Contributing
Contributions, suggestions, and improvements are welcome. Feel free to open issues or pull requests.
❤️ Support
Like this project? Support it with a github star, it would mean a lot to me! Cheers and Happy Coding.
