Skip to content

misc.emoji.wren

clsource edited this page Oct 8, 2020 · 4 revisions

Emoji Lib

This simple lib will help you working with emojis in Wren. Is inspired by the Python Emoji Lib.

The entire set of Emoji codes as defined by the unicode consortium is supported in addition to a bunch of aliases.

Example

import "./misc/emoji" for Emoji

// Wren is 👍
System.print(Emoji.emojize('Wren is :thumbs_up:'))

// Wren is 👍
System.print(Emoji.emojize('Wren is :thumbsup:'))

// Wren is :thumbs_up:
System.print(Emoji.demojize('Wren is 👍'))

// Wren is ❤️
System.print("Wren is %(Emoji.random)")

Developing

For generating the emoji codes we use the tools/emoji Python script. This script utilizes the unicode_codes.py file from Python emoji.

The main class is domepunk/misc/emoji/emoji.wren. misc/emoji/codes.wren and misc/emoji.wren are automatically generated by tools/emoji's Makefile.

To generate a new version of the emoji codes, Execute make inside tools/emoji dir. This will generate misc/emojis/codes.wren and merge it with misc/emojis/emoji.wren in a single file called misc/emoji.wren.

Testing

The test file is found in domepunk/test/misc/emoji.test.wren Execute make tests to run all tests.

Links

Thanks

To the folks of Python emoji for its wonderful lib.


Holds the emoji list and methods for working with them.

import "./misc/emoji" for Emoji
  • Since: 1.0.0

API

Will return all the available emoji tags and emojis.

  • Since: 1.0.0
  • Signature: static var emojis: Map

Will return a random emoji.

  • Since: 1.0.0
  • Signature: static func random(seed: Random?) -> String
  • Parameter seed: An optional Random.new() instance.
  • Returns: A random emoji string.

It will return the emoji for the specified name.

  • Since: 1.0.0
  • Signature: static func forName(name:String) -> String
  • Parameter name: The name tag for the emoji.
  • Returns: An emoji string if the tag is found. Empty string if no name tag is found.

Will replace emoji tags to emojis.

E.g. :thumbsup: to 👍

  • Since: 1.0.0
  • Signature: static func emojize(text:String) -> String
  • Parameter string: The string that it will replace tags with emojis.
  • Returns: The same string but with the name tags replaced by emojis.

It the reverse process to emojize. Transform emoji to emoji tags.

E.g. 👍 to :thumbsup:

  • Since: 1.0.0
  • Signature: static func demojize(text:String) -> String
  • Parameter string: The string that it will replace the emojis for name tags.
  • Returns: The same string but with emojis replaced with name tags.