Skip to content

Commit

Permalink
[Feature] Default skin tones + local config file (#7)
Browse files Browse the repository at this point in the history
* [Feature] Default skin tones + local config file

* default-skin-tone -> skin-tone

* fix
  • Loading branch information
akxcv authored Feb 13, 2018
1 parent ff86dc9 commit ad89e59
Show file tree
Hide file tree
Showing 16 changed files with 6,389 additions and 5,883 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ 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.0] - 2018-02-13
### Added
- Feature: default skin tones
- Feature: local CLI config via ~/.krasivorc
- Support for "-" (minus) sign - ([@nesaulov][])
### Fixed
- Non-string arguments passed as foreground or background behaved incorrectly - ([@nesaulov][])

## [1.1.0] - 2018-01-23
### Added
- Feature: convert emoji names to Unicode emoji symbols
Expand All @@ -17,3 +25,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
Initial release.

[@past-one]: https://github.com/past-one
[@nesaulov]: https://github.com/nesaulov
38 changes: 35 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ krasivo --help

### Available options:

#### - `shortEmoji` (default: true)
#### - `shortEmoji` (default: `true`)
When true, emoji names like `:no_good:` are converted to Unicode emoji symbols.

**CLI usage**:
Expand All @@ -53,9 +53,9 @@ krasivo hello :no_good: ' ' --no-short-emoji

**JS usage**:
```js
krasivo('hello', ':no_good', ' ', { shortEmoji: true })
krasivo('hello', ':no_good:', ' ', { shortEmoji: true })
// To disable:
krasivo('hello', ':no_good', ' ', { shortEmoji: false })
krasivo('hello', ':no_good:', ' ', { shortEmoji: false })
```

> Slack limits message length, and after the limit is broken, the only way to send the
Expand All @@ -65,6 +65,26 @@ separate character. `shortEmoji` feature allows you to use any emoji in your mes
converting emoji names to actual Unicode emoji symbols, which are all 1 character long in
Slack.

#### - `skinTone` (default: `undefined`)
When given a number (typically from 2 to 6), adds a skin tone to emoji that support skin tone
variations. You can always specify a skin tone yourself (`:no_good::skin-tone-6:`), this will
override the value specified in `skinTone`. It's best to configure this option in a [local
config file](#local-config-file).

**CLI usage**:
```sh
krasivo hello :no_good: ' ' --skin-tone=2
# or:
krasivo hello :no_good: ' ' -s 2
```

**JS usage**:
```js
krasivo('hello', ':no_good:', ' ', { skinTone: 2 })
```

### Skin colours

Skin colours are supported in Slack style:

`":no_good:"` => 🙅
Expand All @@ -79,6 +99,18 @@ Skin colours are supported in Slack style:

`":no_good::skin-tone-6:"` => 🙅🏿

## Local config file

Krasivo CLI looks for a `.krasivorc` YAML file in your home directory. For example, to configure
a default skin tone, and to disable emoji replacement, create the following file:

```yaml
# ~/.krasivorc
options:
skinTone: 2
shortEmoji: false
```
## License
MIT
12 changes: 12 additions & 0 deletions __fixtures__/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const fs = require('fs')
const path = require('path')

function loadFixture (name) {
return fs.readFileSync(path.join(__dirname, `krasivorc.${name}.yml`))
}

module.exports = {
withSkinTone: loadFixture('withSkinTone'),
withAllOptions: loadFixture('withAllOptions'),
invalid: loadFixture('invalid')
}
1 change: 1 addition & 0 deletions __fixtures__/krasivorc.invalid.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fasdfas: dsfa: fasdf : :::
3 changes: 3 additions & 0 deletions __fixtures__/krasivorc.withAllOptions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
options:
skinTone: 2
shortEmoji: false
2 changes: 2 additions & 0 deletions __fixtures__/krasivorc.withSkinTone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
options:
skinTone: 2
9 changes: 8 additions & 1 deletion bin/build_emoji_data
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ function unifiedToCodePoints (unified) {
* Build a map from each emoji short name to its corresponding code points.
*/
const map = {}
const emojiWithSkinVariations = []
emojiData.forEach(function (anEmoji) {
anEmoji.short_names.forEach(function (shortName) {
map[shortName] = unifiedToCodePoints(anEmoji.unified)
})
if (anEmoji.hasOwnProperty('skin_variations')) {
emojiWithSkinVariations.push(...anEmoji.short_names)
}
})

const skinTones = ['1f3fb', '1f3fc', '1f3fd', '1f3fe', '1f3ff']
Expand All @@ -25,5 +29,8 @@ skinTones.forEach(function (skinTone, index) {

fs.writeFileSync(
path.join(__dirname, '../build/emoji.json'),
JSON.stringify(map, null, 2)
JSON.stringify({
emojiCodePoints: map,
emojiWithSkinVariations,
}, null, 2)
)
Loading

0 comments on commit ad89e59

Please sign in to comment.