Skip to content

Commit

Permalink
[Fix] default skin tone bug
Browse files Browse the repository at this point in the history
  • Loading branch information
akxcv committed Feb 17, 2018
1 parent ad89e59 commit 96d4c27
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [1.2.1] - 2018-02-17
### Fixed
- Bug with applying default skin tones to foregrounds / backgrounds consisting of
more than 1 emoji

## [1.2.0] - 2018-02-13
### Added
- Feature: default skin tones
Expand Down
12 changes: 6 additions & 6 deletions krasivo.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,17 @@ function replaceForegroundAndBackground(string, foreground, background, options)
var matches, match // temporary storage for regexp matches

if (options.skinTone) {
while (matches = EMOJI_WITH_SKIN_COLOUR_REGEXP.exec(foreground)) {
while (match = EMOJI_WITH_SKIN_COLOUR_REGEXP.exec(foreground)) {
// if skin tone is not specified AND the emoji supports skin tones
if (matches[2] === undefined && arrayIncludes(emoji.emojiWithSkinVariations, matches[1])) {
foreground += ':skin-tone-' + options.skinTone + ':'
if (match[2] === undefined && arrayIncludes(emoji.emojiWithSkinVariations, match[1])) {
foreground = foreground.replace(match[0], `${match[0]}:skin-tone-${options.skinTone}:`)
}
}

while (matches = EMOJI_WITH_SKIN_COLOUR_REGEXP.exec(background)) {
while (match = EMOJI_WITH_SKIN_COLOUR_REGEXP.exec(background)) {
// if skin tone is not specified AND the emoji supports skin tones
if (matches[2] === undefined && arrayIncludes(emoji.emojiWithSkinVariations, matches[1])) {
background += ':skin-tone-' + options.skinTone + ':'
if (match[2] === undefined && arrayIncludes(emoji.emojiWithSkinVariations, match[1])) {
background = background.replace(match[0], `${match[0]}:skin-tone-${options.skinTone}:`)
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions krasivo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,5 +198,21 @@ describe('krasivo', () => {
].join('\n')
)
})

it('sets default skin tone to all emojis in fg/bg', () => {
expect(
krasivo('1', ':no_good::thumbsup:', ':wave::thumbsdown:', { skinTone: 2 })
).toBe(
[
':wave::skin-tone-2::thumbsdown::skin-tone-2::wave::skin-tone-2::thumbsdown::skin-tone-2::no_good::skin-tone-2::thumbsup::skin-tone-2:',
':wave::skin-tone-2::thumbsdown::skin-tone-2::no_good::skin-tone-2::thumbsup::skin-tone-2::no_good::skin-tone-2::thumbsup::skin-tone-2:',
':no_good::skin-tone-2::thumbsup::skin-tone-2::wave::skin-tone-2::thumbsdown::skin-tone-2::no_good::skin-tone-2::thumbsup::skin-tone-2:',
':wave::skin-tone-2::thumbsdown::skin-tone-2::wave::skin-tone-2::thumbsdown::skin-tone-2::no_good::skin-tone-2::thumbsup::skin-tone-2:',
':wave::skin-tone-2::thumbsdown::skin-tone-2::wave::skin-tone-2::thumbsdown::skin-tone-2::no_good::skin-tone-2::thumbsup::skin-tone-2:',
':wave::skin-tone-2::thumbsdown::skin-tone-2::wave::skin-tone-2::thumbsdown::skin-tone-2::no_good::skin-tone-2::thumbsup::skin-tone-2:',
':wave::skin-tone-2::thumbsdown::skin-tone-2::wave::skin-tone-2::thumbsdown::skin-tone-2::no_good::skin-tone-2::thumbsup::skin-tone-2:'
].join('\n')
)
})
})
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "krasivo",
"version": "1.2.0",
"version": "1.2.1",
"author": "Alexander Komarov <ak@akxcv.com>",
"license": "MIT",
"keywords": [
Expand Down

0 comments on commit 96d4c27

Please sign in to comment.