Git Product home page Git Product logo

typesafe-emoji's Introduction

Typesafe Emoji

Typesafe Emoji is a wrapper around Java's Unicode Character handling.

Installation

Add to build.sbt

libraryDependencies += "com.typesafe" % "emoji" % "1.0.0"

Usage

$ sbt console
scala> import com.typesafe.emoji._
scala> import com.typesafe.emoji.Emoji.Implicits._

You can map Emoji directly from a Unicode character:

scala> Emoji(0x1f603)
res0: comp.typesafe.emoji.Emoji = ๐Ÿ˜ƒ

Or you can map the implicit from Int or String:

scala> 0x1f603.emoji
res1: comp.typesafe.emoji.Emoji = ๐Ÿ˜ƒ
scala> "0x1f603".codePointEmoji
res2: com.typesafe.emoji.Emoji = ๐Ÿ˜ƒ

Once you have an emoji, you can ask it for codePoint (Int) or hexidecimal value:

scala> res2.hex
res3: String = 0x1f603
scala> res2.codePoint
res4: Int = 128515

Unicode codepoints are not very convenient, so there's a ShortCodes class which is designed to be used as an implicit parameter for emoji mapping.

There is a default mapping available, which allows you to map from a string directly to an emoji:

scala> import com.typesafe.emoji.ShortCodes.Implicits._
scala> import com.typesafe.emoji.ShortCodes.Defaults._
scala> "smiley".emoji
res5: com.typesafe.emoji.Emoji = ๐Ÿ˜ƒ

You can query the current mapping for short codes:

scala> ShortCodes.current.shortCodes.filter(_.startsWith("heart"))
res6: scala.collection.Set[String] = Set(heart_decoration, heart_eyes_cat, hearts, heart_eyes, heartpulse, heart, heartbeat)

Finally, you can also use your own short codes mapping:

scala> implicit val mycodes = new ShortCodes()
mycodes: com.typesafe.emoji.ShortCodes = com.typesafe.emoji.ShortCodes@49fd69f5
scala> mycodes.entry(Emoji(0x1f603), "yay")
scala> "yay".emoji
res1: com.typesafe.emoji.Emoji = ๐Ÿ˜ƒ

Bugs

Sadly, there is no direct mapping to emoji-cheat-sheet or emoji searcher, because some emoji are mapped directly to glyphs, without Unicode involvement, e.g. :neckbeard:.

typesafe-emoji's People

Contributors

wsargent avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.