Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supports Emoji version 13.1 (2021) #17

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,17 @@ npm install --save emoji-name-map
yarn add emoji-name-map
```

## :hammer: Build Datasource

If the version of [emoji-datasource](https://www.npmjs.com/package/emoji-datasource) is upgraded, please reimport the data and regenerate the json object.

```sh
# Using npm
npm install && npm run data:build

# Using yarn
yarn && yarn data:build
```



Expand Down
26 changes: 26 additions & 0 deletions data/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const fs = require('fs');
const dataSource = require('emoji-datasource');
const jsonData = {};

dataSource.forEach(source => {
const { unified, short_name} = source;
hexArray = unified.split('-').map(hexStr => parseInt(`0x${hexStr}`, 16));
const codeUnit = String.fromCodePoint(...hexArray);
jsonData[short_name] = codeUnit;
});

function writeFile(path, data) {
const jsonStr = JSON.stringify(data);
fs.writeFile(path, jsonStr, (err) => {
if (err) rej(err);
if (!err) {
console.log('Success output to json!!');
}
});
}

function main(path, input) {
writeFile(path, input);
}

main(`lib/datasource.json`, jsonData);
1 change: 1 addition & 0 deletions lib/datasource.json

Large diffs are not rendered by default.

11 changes: 2 additions & 9 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
"use strict";

const mapO = require("map-o")
, iterateObject = require("iterate-object")
;

let emoji = require("emojilib");
var emojiDatasource = require('./datasource.json');

const nameMap = module.exports = {};
nameMap.emoji = mapO(emoji.lib, value => value.char, true);
iterateObject(nameMap.emoji, (value, name, obj) => !value && delete obj[name] || true);
nameMap.emoji = emojiDatasource;

/**
* get
Expand All @@ -25,5 +20,3 @@ nameMap.get = function (name) {
}
return this.emoji[name];
};

emoji = null;
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"example": "example"
},
"scripts": {
"data:build": "node data/build.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
Expand All @@ -17,12 +18,6 @@
],
"author": "Ionică Bizău <[email protected]> (https://ionicabizau.net)",
"license": "MIT",
"dependencies": {
"emojilib": "^2.0.2",
"iterate-object": "^1.3.1",
"map-o": "^2.0.1"
},
"devDependencies": {},
"repository": {
"type": "git",
"url": "git+https://github.com/IonicaBizau/emoji-name-map.git"
Expand All @@ -31,6 +26,9 @@
"url": "https://github.com/IonicaBizau/emoji-name-map/issues"
},
"homepage": "https://github.com/IonicaBizau/emoji-name-map#readme",
"contributors": [
"yakumomutsuki <[email protected]> (https://yakumomutsuki.github.io/)"
],
"files": [
"bin/",
"app/",
Expand All @@ -45,5 +43,8 @@
"bloggify.js",
"bloggify.json",
"bloggify/"
]
],
"devDependencies": {
"emoji-datasource": "^7.0.2"
}
}