Skip to content

Commit

Permalink
*BREAKING* Update to Twemoji 12 (Unicode 12)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsevillamartin committed Jul 8, 2019
1 parent b6b93a5 commit cac5344
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 50 deletions.
14 changes: 7 additions & 7 deletions README.md
Expand Up @@ -4,7 +4,7 @@ A simple emoji map package that builds its data whenever it's installed.

This package maps the emoji codes (`2049`) and sets them equal to its shortnames (`["interrobang","exclamation_question"]`).

### Usage
## Usage

```js
const emojis = require('simple-emoji-map');
Expand All @@ -16,7 +16,7 @@ Or using ES6 imports:
import emojis from 'simple-emoji-map';
```

### Rebuilding
## Rebuilding

The JSON file is automatically generated on install.

Expand All @@ -29,7 +29,7 @@ const build = require('simple-emoji-map/build');
build();
```

### Config
## Config

To customize the build process, you will need either a `.simple-emoji-map` file or a `simple-emoji-map` property in package.json.

Expand All @@ -41,17 +41,17 @@ To customize the build process, you will need either a `.simple-emoji-map` file
}
```

#### Shortnames
### Shortnames

This is also the way to add custom shortnames to the map file.

For example, if you want `car` to show the emoji for `red_car` (`1f697`), the file or property would look something like this:

```json
{
"shortnames": {
"1f697": ["car"]
},
"shortnames": {
"1f697": ["car"]
}
}
```

Expand Down
22 changes: 4 additions & 18 deletions build.js
Expand Up @@ -13,12 +13,11 @@

const fs = require('fs');
const path = require('path');
const twemoji = require('twemoji/2/twemoji.npm');
const appRoot = require('app-root-path');
const twemoji = require('twemoji');
const getConfig = require('./src/config');

const outputPath = path.resolve(__dirname, 'generated/emojis.json');
const data = require('emojibase-data/en/data.json');
const data = require('emojibase-data/en/compact.json');

const alternative = {
'👁️‍🗨️': '👁‍🗨',
Expand All @@ -31,18 +30,14 @@ const TYPES = {
module.exports = async () => {
const config = await getConfig();
const type = TYPES[config.type.toUpperCase()] || TYPES.EMOJI;
let shortnames = config.shortnames;

const twemojiFileNames = fs
.readdirSync(appRoot + '/node_modules/twemoji/2/svg')
.map(name => path.basename(name, '.svg'));
const shortnames = config.shortnames;

const emojis = {};
const used = [];
const ignored = [];

for (let e of data) {
const emoji = alternative[e.emoji] || e.emoji;
const emoji = alternative[e.unicode] || e.unicode;
const emojiCode = getEmojiIconCode(emoji);

if (
Expand All @@ -54,11 +49,6 @@ module.exports = async () => {
continue;
}

if (!checkExistanceInTwemoji(emojiCode)) {
console.error('Can not find', emoji, emojiCode);
continue;
}

const key = type === TYPES.EMOJI ? emoji : emojiCode;

emojis[key] = e.shortcodes.concat(shortnames[emojiCode] || []);
Expand All @@ -75,10 +65,6 @@ module.exports = async () => {

return { ignored, used };

function checkExistanceInTwemoji(code) {
return twemojiFileNames.includes(code);
}

function getEmojiIconCode(emoji) {
const U200D = String.fromCharCode(0x200d);
return twemoji.convert.toCodePoint(
Expand Down
2 changes: 1 addition & 1 deletion generated/emojis.json

Large diffs are not rendered by default.

124 changes: 105 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions package.json
Expand Up @@ -12,13 +12,12 @@
"lint": "prettier --single-quote --trailing-comma es5 --print-width 80 --tab-width 4 --write bin/* *.js *.mjs *.md"
},
"dependencies": {
"app-root-path": "^2.1.0",
"cosmiconfig": "^5.0.6",
"emojibase-data": "^3.1.0",
"twemoji": "^11.0.1"
"cosmiconfig": "^5.2.1",
"emojibase-data": "^4.0.0",
"twemoji": "^12.1.2"
},
"devDependencies": {
"prettier": "^1.14.2"
"prettier": "^1.18.2"
},
"bin": {
"simple-emoji-map": "build.js"
Expand Down

0 comments on commit cac5344

Please sign in to comment.