Skip to content

Commit

Permalink
Support :colons: syntax
Browse files Browse the repository at this point in the history
i.e. 👍, 👍:skin-tone-3:
  • Loading branch information
EtienneLem committed Nov 1, 2016
1 parent 97b20ac commit c460474
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -100,7 +100,8 @@ Sheets are served from [unpkg](https://unpkg.com), a global CDN that serves file
import { Emoji } from 'emoji-mart'

<Emoji emoji={{ id: 'santa', skin: 3 }} />
<Emoji set='emojione' emoji='santa' />
<Emoji emoji=':santa::skin-tone-3:' />
<Emoji emoji='santa' set='emojione' />
```

| Prop | Required | Default | Description |
Expand Down
11 changes: 11 additions & 0 deletions src/utils/index.js
@@ -1,5 +1,6 @@
import data from '../../data'

const COLONS_REGEX = /^(?:\:([^\:]+)\:)(?:\:skin-tone-(\d)\:)?$/
const SKINS = [
'1F3FA', '1F3FB', '1F3FC',
'1F3FD', '1F3FE', '1F3FF',
Expand Down Expand Up @@ -39,6 +40,16 @@ function getData(emoji, skin, set) {
var emojiData = {}

if (typeof emoji == 'string') {
let matches = emoji.match(COLONS_REGEX)

if (matches) {
emoji = matches[1]

if (matches[2]) {
skin = parseInt(matches[2])
}
}

if (data.short_names.hasOwnProperty(emoji)) {
emoji = data.short_names[emoji]
}
Expand Down

0 comments on commit c460474

Please sign in to comment.