Skip to content

Commit

Permalink
Update emojis /cc #17 -- thanks @yakumomutsuki 🍰
Browse files Browse the repository at this point in the history
  • Loading branch information
IonicaBizau committed Feb 13, 2025
2 parents 0b29558 + 210f0c1 commit 81e4fa6
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 17 deletions.
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;
17 changes: 9 additions & 8 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 <bizauionica@gmail.com> (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 <sakuraapp1988@gmail.com> (https://yakumomutsuki.github.io/)"
],
"files": [
"bin/",
"app/",
Expand All @@ -45,5 +43,8 @@
"bloggify.js",
"bloggify.json",
"bloggify/"
]
}
],
"devDependencies": {
"emoji-datasource": "^7.0.2"
}
}

0 comments on commit 81e4fa6

Please sign in to comment.