github.com/veelenga/emoji.cr

:green_heart: Emoji for Crystal

53 stars
0 dependents
License: MIT

Nothing has been indexed for 0.0.1 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.

Installation

# Add this to your shard.yml
dependencies:
  emoji:
    github: veelenga/emoji.cr
    version: ~> 0.0.1

Then run:

shards install

shard.yml

No shard.yml has been indexed for 0.0.1. You can read it on the repository.

Dependencies

Unknown: the shard.yml for this version has not been read yet.

Documentation

Read the API documentation

Generated from the source of the current release. The first visit to a release that has never been documented starts its build.

README

This README is the one indexed from the repository at its latest ref, not from the tag for this version.

# emoji.cr

[![Crystal CI](https://github.com/veelenga/emoji.cr/actions/workflows/crystal.yml/badge.svg?branch=master)](https://github.com/veelenga/emoji.cr/actions/workflows/crystal.yml)

Emoji library for Crystal. Inspired by [Emoji for Python](https://github.com/carpedm20/emoji)

## Installation

As a dependency in `shard.yml`:

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

## Usage

```crystal
require "emoji"

puts Emoji.emojize("I :heart: :beer: and :football:")
```

Will print the following in console:

![](assets/screen.png)

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

```crystal
str = Emoji.emojize("Girl on :fire:")
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:

```crystal
Emoji.sanitize(str, regex: :generated)
```

### Regex

```crystal
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
```

```console
`๐Ÿ’Ž` - 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:

```console
crystal build bin/emojize
./emojize It will boom: :boom:
```

![](assets/boom.png)

## Resources

- [Unicodeยฎ Technical Standard #51](http://www.unicode.org/reports/tr51/)
- [Emoji Cheat Sheet](http://www.emoji-cheat-sheet.com/)

## 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