node-emojis
Version:
Modern, tree-shakeable emoji library for Node.js with TypeScript, search, skin tones, and aliases 🎉
63 lines • 2.54 kB
TypeScript
import { SkinTone, SkinToneAlias } from '../features/skin-tones';
/**
* Check if a string is a valid emoji character
*
* This function uses a two-step validation approach:
* 1. First checks against the known emoji database for exact matches (O(1) lookup)
* 2. Falls back to regex validation for emojis that might not be in our database
*
* The regex pattern covers Unicode ranges for:
* - Emoticons (U+1F600-U+1F64F)
* - Miscellaneous Symbols and Pictographs (U+1F300-U+1F5FF)
* - Transport and Map Symbols (U+1F680-U+1F6FF)
* - Supplemental Symbols and Pictographs (U+1F900-U+1F9FF, U+1FA00-U+1FAFF)
* - Flags (U+1F1E6-U+1F1FF)
* - Skin tone modifiers (U+1F3FB-U+1F3FF)
* - Zero-width joiner (U+200D) and variation selector (U+FE0F)
*
* Limitations:
* - May not recognize very new emojis not yet in the database
* - Complex emoji sequences with multiple components might not be fully validated
*
* Note: This function will return true for strings containing only emoji characters,
* including multiple emojis like '😀😀' or '🔥💧'. This is intentional as the function
* validates whether the string consists entirely of emoji codepoints.
*
* @param str - The string to validate
* @returns true if the string consists only of emoji characters, false otherwise
*/
export declare function isValidEmoji(str: string): boolean;
/**
* Check if a string is a valid emoji name
*/
export declare function isValidEmojiName(name: string): boolean;
/**
* Check if a string is a valid skin tone
*/
export declare function isValidSkinTone(tone: string): tone is SkinTone | SkinToneAlias;
/**
* Validate and sanitize emoji name
*/
export declare function sanitizeEmojiName(name: string): string;
/**
* Check if a string contains variation selector
*
* Variation selectors (U+FE0F) are used to request an emoji presentation
* of characters that have both text and emoji representations.
*
* @param str - The string to check for variation selectors
* @returns true if the string contains at least one variation selector, false otherwise
*
* @example
* ```typescript
* hasVariationSelector('❤️') // true (heart with emoji presentation)
* hasVariationSelector('❤') // false (heart without variation selector)
* hasVariationSelector('') // false (empty string)
* ```
*/
export declare function hasVariationSelector(str: string): boolean;
/**
* Strip variation selectors from string
*/
export declare function stripVariationSelectors(str: string): string;
//# sourceMappingURL=validators.d.ts.map