Skip to content

Commit

Permalink
add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Millloy authored and Kyle Millloy committed Jun 17, 2022
1 parent 0ee8d82 commit 39c24d6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Adds support for inserting and converting emojis into unicode in PHP. Uses enums

## Usage

Below you will find some usage examples.

```php
use Emoji\Emoji;
use Emoji\SkinTone;
Expand All @@ -31,5 +33,28 @@ Emoji::wavingHand()
->skinTone(fn() => $user->preferred_skin_tone)
->toString();

// You may also reset
// You may also remove tone from a given emoji as well.
$emoji = Emoji::wavingHand(SkinTone::medium);
$emoji->skinTone(); // get the skin tone, returns SkinTone::medium
$emoji->toneless()->skinTone(); // returns null

// Finally, you may replace emojis in a string where they match within
// two colons and align to an allowed emoji character. If invalid characters
// are used it just returns them without converting
Emoji::parse('Hello world :waving_hand: how are you :invalid_character:'); // returns "Hello world 👋" how are you :invalid_character:"

// You can set the skin tone for the parser globally with...
Emoji::setDefaultSkinTone(Emoji::light);
Emoji::parse('Hello world :waving_hand:'); // returns "Hello world 👋🏻"
```

For a full list of supported emojis and those that support adding skin tones view: [Character](/src/Enums/Character.php)

For a full list of skin tones view: [SkinTone](/src/Enums/SkinTone.php)

## Todo

- [x] Allow a user to select emojis
- [x] Allow a user to set skin tones
- [ ] Add support for all emoji skin tones
- [ ] Add support for changing skin tone when replacing a string
2 changes: 1 addition & 1 deletion src/Emoji.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static function get(string $name, $skinTone = null): ?Factory
* @param string $haystack
* @return string
*/
public static function replace(string $haystack): string
public static function parse(string $haystack): string
{
return preg_replace_callback(
'/:[\s\S]*?:/i',
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/EmojiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@
"Lorem :$1: ipsum :$2: dolor :$3: sit :$4: amet",
);

expect(Emoji::replace($string))->not->toBe($string);
expect(Emoji::parse($string))->not->toBe($string);
});

it('does not replace invalid :emoji_names: if there is no valid match', function () {
$string = 'This string will contain :invalid_emojis: which will not be replaced.';

expect(Emoji::replace($string))->toBe($string);
expect(Emoji::parse($string))->toBe($string);
});

it('can convert camel case requests for a method and match with the snake case version', function () {
Expand Down

0 comments on commit 39c24d6

Please sign in to comment.