UNPKG

@mojis/skin-tone

Version:

utilities to work with emoji skin tones

62 lines (60 loc) โ€ข 2.2 kB
type SkinTone = "none" | "light" | "medium-light" | "medium" | "medium-dark" | "dark"; declare const FITZPATRICK_SCALE: Map<SkinTone, string>; /** * Change the skin tone of an emoji. * * @param {string} emoji - The emoji to modify * @param {SkinTone} tone - The new `skin tone` to use for `emoji` * * @returns {string} - The emoji with the new skin tone * * @example * ```ts * const result = setSkinTone("๐Ÿ‘", "dark"); * // result => "๐Ÿ‘๐Ÿฟ" * ``` */ declare function setSkinTone(emoji: string, tone: SkinTone): string; /** * Applies skin tone modifiers to an emoji string. * * @param {string} emoji - The emoji string to modify * @param {SkinTone[]} tones - Array of skin tones to apply. If multiple tones are provided, they will be applied in sequence to modifiable components * @returns {string} The emoji with applied skin tones * * @example * ```ts * setSkinTones("๐Ÿ‘‹", ["light"]) // "๐Ÿ‘‹๐Ÿป" * setSkinTones("๐Ÿซฑ๐Ÿฟโ€๐Ÿซฒ๐Ÿพ", ["light", "dark"]) // "๐Ÿซฑ๐Ÿปโ€๐Ÿซฒ๐Ÿฟ" * setSkinTones("๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ", ["light"]) // "๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ" (family emojis are not modified) * ``` */ declare function setSkinTones(emoji: string, tones: SkinTone[]): string; /** * Gets the skin tone from an emoji string. * * @param {string} emoji - The emoji string to extract the skin tone from * @returns {SkinTone | SkinTone[]} The skin tone value from the Fitzpatrick scale, or "none" if no skin tone is present * * @example * ```ts * getSkinTone("๐Ÿ‘‹๐Ÿฝ") // => "medium" * getSkinTone("๐Ÿ‘‹") // => "none" * * getSkinTone("๐Ÿ‘ฉ๐Ÿผโ€โค๏ธโ€๐Ÿ‘จ๐Ÿฟ") // => ["medium-light", "dark"] * ``` */ declare function getSkinTone(emoji: string): SkinTone | SkinTone[]; /** * Checks if the given emoji contains a skin tone modifier * @param {string} emoji - The emoji to check for skin tone * @returns {boolean} `true` if the emoji contains a skin tone modifier, `false` otherwise * * @example * ```ts * hasSkinTone("๐Ÿ‘‹") // => false * hasSkinTone("๐Ÿ‘‹๐Ÿป") // => true * ``` */ declare function hasSkinTone(emoji: string): boolean; export { FITZPATRICK_SCALE, type SkinTone, getSkinTone, hasSkinTone, setSkinTone, setSkinTones };