emoji.cr v0.3.1

๐Ÿ’š Emoji for Crystal

Releases:

  • v0.3.1 - February 17, 2019
  • v0.3.0 - February 10, 2019
  • v0.2.1 - June 22, 2018
  • v0.2.0 - November 24, 2016
  • v0.1.0 - September 22, 2015

Dependencies:

Owner:

emoji.cr Build Status

Emoji library for Crystal. Inspired by Emoji for Python

Installation

As a dependency in shard.yml:

dependencies:
  emoji:
    github: veelenga/emoji.cr
    branch: master

Usage

require "emoji"

puts Emoji.emojize("I โค๏ธ ๐Ÿบ and ๐Ÿˆ")

Will print the following in console:

Also it is possible to remove all emoji from the string:

str = Emoji.emojize("Girl on ๐Ÿ”ฅ")
Emoji.sanitize(str) #=> "Girl on "

Sanitizing is based on Emoji regex. There are two options available:

  • :simple emoji regex (default)
  • :generated emoji regex

Simple regex uses unicode ranges to find emojis and may give some incorrect results. Generated regex is quite big, but works correctly in 100% cases. However, it is much slower than a simple regex.

If you need more accuracy sanitizing emojis and don't care about performance, just use generated one:

Emoji.sanitize(str, regex: :generated)

Regex

require "emoji"

string = "String which contains all kinds of emoji:

- Singleton Emoji: (๐Ÿ’Ž)
- Textual singleton Emoji with Emoji variation: (โ–ถ๏ธ)
- Emoji with skin tone modifier: (๐Ÿ–๐Ÿผ)
- Region flag: (๐Ÿ‡บ๐Ÿ‡ฆ)
- Sub-Region flag: (๐Ÿด๓ ง๓ ข๓ ณ๓ ฃ๓ ด๓ ฟ)
- Keycap sequence: (7๏ธโƒฃ)
- Sequence using ZWJ (zero width joiner): (๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ)

"

string.scan(Emoji::GENERATED_EMOJI_REGEX) do |m|
  puts "`#{m[0]}` - #{m[0].size} code points"
end
`๐Ÿ’Ž` - 1 code points
`โ–ถ๏ธ` - 2 code points
`๐Ÿ–๐Ÿผ` - 2 code points
`๐Ÿ‡บ๐Ÿ‡ฆ` - 2 code points
`๐Ÿด๓ ง๓ ข๓ ณ๓ ฃ๓ ด๓ ฟ` - 7 code points
`7๏ธโƒฃ` - 3 code points
`๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ` - 7 code points

Binary

You may also compile and use emojize binary that just prints to console emojized string:

crystal build bin/emojize
./emojize It will boom: ๐Ÿ’ฅ

Resources

Contributing

  1. Fork it ( https://github.com/veelenga/emoji.cr/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request
Github statistic:
  • 25
  • 2
  • 2
  • 0
  • 4 days ago

License:

MIT License

Links: