Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
let fs = require("fs").promises | ||
let {promisify} = require("util") | ||
let getAverageColor = promisify(require("image-average-color")) | ||
let resolvePath = require("path").resolve | ||
let {EOL} = require("os") | ||
|
||
function convertHexCodeToEmoji(code) { | ||
return String.fromCodePoint(parseInt(code, 16)) | ||
} | ||
|
||
function getCodeFromFilename(path) { | ||
let match = path.match(/emoji_([a-f0-9]+)\.png/) | ||
if (!match || !match[1]) { | ||
throw new Error(`${path} doesn't look like an emoji filename`) | ||
} | ||
let [, code] = match | ||
return code | ||
} | ||
|
||
;(async function() { | ||
/* | ||
this is a directory full of emoji extracted by Devon Govett's emoji | ||
extractor | ||
*/ | ||
let emojiDirName = "emoji" | ||
let dir = await fs.readdir(emojiDirName) | ||
for (let path of dir) { | ||
let [red, green, blue, alpha] = await getAverageColor( | ||
resolvePath(emojiDirName, path) | ||
) | ||
let emoji = convertHexCodeToEmoji(getCodeFromFilename(path)) | ||
process.stdout.write([emoji, red, green, blue, alpha].join("\t") + EOL) | ||
} | ||
})() |