Emoshi (Emoshi v0.1.1)

View Source

Library for accessing the emoji data set.

Only fully qualified emojis (see https://www.unicode.org/reports/tr51/#def_fully_qualified_emoji) are included.

See https://www.unicode.org/reports/tr51/ for information about emojis.

Summary

Functions

Returns the closest emojis by slug.

Returns the codepoints for an emoji.

Returns the Emoshi.t/0 struct from the emoji character.

Returns all emojis for the given group.

Returns all emojis for the given groups.

Returns all emojis for the given group and subgroup(s).

Returns whether the input is an emoji group, case sensiive and exact match.

Returns all the emojis' groups

Returns all Emoshi.t/0 where the slug matches the input argument. The function is case insensitive and normalizes whitespaces, tabs, etc. to hyphens.

Returns all the subgroups for a group, or nil if the group does not exist.

Returns the unicode spec version used to generate the module.

Types

emoji_status()

@type emoji_status() ::
  :unqualified | :fully_qualified | :minimally_qualified | :component

t()

@type t() :: %Emoshi{
  emoji: String.t(),
  group: String.t(),
  name: String.t(),
  slug: String.t(),
  status: emoji_status(),
  subgroup: String.t()
}

Functions

closest(search_slug, opts \\ [])

@spec closest(String.t(), Keyword.t()) :: [t()]

Returns the closest emojis by slug.

Uses String.jaro_distance/2 internally to find the closest emojis.

Options

  • :ignore_variations - boolean/0. Whether to ignore variations such as skin color. Defaults to true.
  • :take- pos_integer/0. The number of emojis to retrieve. Defaults to 5

Examples

iex> Emoshi.closest("tumbs up", take: 2)
[
  %Emoshi{
    slug: "thumbs-up",
    name: "thumbs up",
    status: :fully_qualified,
    emoji: "👍",
    group: "People & Body",
    subgroup: "hand-fingers-closed"
  },
  %Emoshi{
    slug: "thumbs-down",
    name: "thumbs down",
    status: :fully_qualified,
    emoji: "👎",
    group: "People & Body",
    subgroup: "hand-fingers-closed"
  }
]

codepoints(emoji)

@spec codepoints(String.t()) :: String.t()

Returns the codepoints for an emoji.

Examples

iex> Emoshi.codepoints("*️⃣")
"002A FE0F 20E3"

iex> Emoshi.codepoints("😌")
"1F60C"

find_by_emoji(emoji)

@spec find_by_emoji(String.t()) :: t() | nil

Returns the Emoshi.t/0 struct from the emoji character.

Examples

iex> Emoshi.find_by_emoji("🥶")
%Emoshi{
  name: "cold face",
  status: :fully_qualified,
  group: "Smileys & Emotion",
  slug: "cold-face",
  emoji: "🥶",
  subgroup: "face-unwell"
}

iex> Emoshi.find_by_emoji("not an emoji")
nil

for_group(group)

@spec for_group(String.t()) :: [t()]

Returns all emojis for the given group.

for_groups(groups)

@spec for_groups([String.t(), ...]) :: [t()]

Returns all emojis for the given groups.

for_subgroups(group, subgroups)

@spec for_subgroups(String.t(), String.t() | [String.t(), ...]) :: [t()]

Returns all emojis for the given group and subgroup(s).

Accepts both a single subgroup and a list of subgroups.

Examples

iex> Emoshi.for_subgroups("Smileys & Emotion", "face-hat") |> Enum.map(& &1.emoji)
["🤠", "🥳", "🥸"]

iex> Emoshi.for_subgroups("Smileys & Emotion", ["face-hat", "face-glasses"]) |> Enum.map(& &1.emoji)
["🤠", "🥳", "🥸", "😎", "🤓", "🧐"]

group?(group_name)

@spec group?(String.t()) :: boolean()

Returns whether the input is an emoji group, case sensiive and exact match.

Examples

iex> Emoshi.group?("Animals & Nature")
true

iex> Emoshi.group?("animals and nature")
false

groups()

@spec groups() :: [String.t()]

Returns all the emojis' groups

search(search_slug, opts \\ [])

@spec search(String.t(), Keyword.t()) :: [t()]

Returns all Emoshi.t/0 where the slug matches the input argument. The function is case insensitive and normalizes whitespaces, tabs, etc. to hyphens.

Unlike closest/2, it does not match emojis when there are spelling mistakes.

Options

  • :ignore_variations - boolean/0. Whether to ignore variations such as skin color. Defaults to true.
  • :take - pos_integer/0. The maximum number of emojis to retrieve. Keep in mind that unlike closest/2 which always returns the specified :take number, this function may return fewer results if there are not enough matches. Defaults to 5

Examples

iex> Emoshi.search("thumbs up", take: 1)
[
  %Emoshi{
    slug: "thumbs-up",
    name: "thumbs up",
    status: :fully_qualified,
    emoji: "👍",
    group: "People & Body",
    subgroup: "hand-fingers-closed"
  }
]

iex> Emoshi.search("THUMBS-UP")
[
  %Emoshi{
    slug: "thumbs-up",
    name: "thumbs up",
    status: :fully_qualified,
    emoji: "👍",
    group: "People & Body",
    subgroup: "hand-fingers-closed"
  }
]

iex> Emoshi.search("tumbs-up")
[]

subgroups(group)

@spec subgroups(String.t()) :: [String.t()] | nil

Returns all the subgroups for a group, or nil if the group does not exist.

Examples

iex> Emoshi.subgroups("Flags")
["flag", "country-flag", "subdivision-flag"]

iex> Emoshi.subgroups("flags")
nil

version()

@spec version() :: String.t()

Returns the unicode spec version used to generate the module.