@mojis/skin-tone
Version:
utilities to work with emoji skin tones
62 lines (60 loc) โข 2.2 kB
TypeScript
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 };