Version 1.0.3

main
nxu 3 years ago
parent 5ef0ed9af2
commit d3c4b67557

@ -5,6 +5,7 @@ on:
- main - main
paths-ignore: paths-ignore:
- 'README.md' - 'README.md'
- 'github-emoji.json'
pull_request: pull_request:
branches: branches:
- main - main
@ -34,6 +35,6 @@ jobs:
run: | run: |
git config --global user.name "${{ env.AUTO_COMMIT_AUTHOR }}" git config --global user.name "${{ env.AUTO_COMMIT_AUTHOR }}"
git config --global user.email "${{ env.AUTO_COMMIT_EMAIL }}" git config --global user.email "${{ env.AUTO_COMMIT_EMAIL }}"
git add README.md git add README.md github-emoji.json
git commit -m "${{ env.AUTO_COMMIT_MESSAGE }}" git commit -m "${{ env.AUTO_COMMIT_MESSAGE }}"
git push git push

File diff suppressed because it is too large Load Diff

@ -1,3 +1,10 @@
# Changelog
### Version 1.0.3
- Add GitHub emoji counter
- Add original Unicode
- Add JSON version
### Version 1.0.2 ### Version 1.0.2
- Add GitHub Actions badge - Add GitHub Actions badge
- Fix minor visual bug of the markdown - Fix minor visual bug of the markdown

@ -1,6 +1,6 @@
/** /**
* GitHub Emoji Icon Markdown Generator * GitHub Emoji Icon List Markdown Generator
* - Version: 1.0.2 * - Version: 1.0.3
* - Developer: NXU (GitHub: @jasonfoknxu) * - Developer: NXU (GitHub: @jasonfoknxu)
* - https://github.com/jasonfoknxu/github-emoji-icon-list * - https://github.com/jasonfoknxu/github-emoji-icon-list
*/ */
@ -21,10 +21,14 @@ import * as Utils from './utilities';
process.exit(1); process.exit(1);
} }
// Count number of GitHub emoji
let numberOfEmoji = 0;
// Handle the GitHub emoji from the GitHub Emoji Icon List // Handle the GitHub emoji from the GitHub Emoji Icon List
let githubEmojis: IGithubEmoji = {}; let githubEmojis: IGithubEmoji = {};
for (const [shortcode, url] of Object.entries(githubEmojisData)) { for (const [shortcode, url] of Object.entries(githubEmojisData)) {
githubEmojis[shortcode] = Utils.base(url).toUpperCase(); githubEmojis[shortcode] = Utils.base(url).toUpperCase();
numberOfEmoji++;
} }
// Process the Unicode emoji data from the Unicode Emoji Data text // Process the Unicode emoji data from the Unicode Emoji Data text
@ -46,7 +50,8 @@ import * as Utils from './utilities';
name: parseResult.name, name: parseResult.name,
group: group ?? '', group: group ?? '',
subgroup: subgroup ?? '', subgroup: subgroup ?? '',
order: emojiCount++ order: emojiCount++,
origUnicode: parseResult.original
}; };
} }
} }
@ -65,10 +70,10 @@ import * as Utils from './utilities';
if (!emojis[emojiData.group][emojiData.subgroup]) { if (!emojis[emojiData.group][emojiData.subgroup]) {
emojis[emojiData.group][emojiData.subgroup] = []; emojis[emojiData.group][emojiData.subgroup] = [];
} }
const emojiToAdd = {unicode: unicode, shortcode: shortcode, name: emojiData.name, order: emojiData.order}; const emojiToAdd = {unicode: unicode, shortcode: shortcode, name: emojiData.name, order: emojiData.order, origUnicode: emojiData.origUnicode };
// Ordering the emoji within the subgroup // Ordering the emoji within the subgroup
const index = emojis[emojiData.group][emojiData.subgroup].findIndex((emoji) => { const index = emojis[emojiData.group][emojiData.subgroup].findIndex((emoji) => {
return emoji.order > emojiToAdd.order; return (emoji.order ?? 0) > emojiToAdd.order;
}); });
if (index > -1) { if (index > -1) {
emojis[emojiData.group][emojiData.subgroup].splice(index, 0, emojiToAdd); emojis[emojiData.group][emojiData.subgroup].splice(index, 0, emojiToAdd);
@ -78,6 +83,23 @@ import * as Utils from './utilities';
} }
} }
// Export the emoji list to format the JSON
let exportEmoji: IEmojiGroup = {};
for (const group in emojis) {
exportEmoji[group] = {};
for (const subgroup in emojis[group]) {
exportEmoji[group][Utils.title(subgroup)] = emojis[group][subgroup].map((e) => ({
unicode: Utils.toUnicode(e.origUnicode ?? e.unicode),
shortcode: `:${e.shortcode}:` ?? '',
name: e.name,
emoji: Utils.toEmoji(e.origUnicode ?? e.unicode)
}));
}
}
// Write to a JSON file
await Utils.writeFile('github-emoji.json',JSON.stringify(exportEmoji));
// Sort the emoji from group and subgroup // Sort the emoji from group and subgroup
let organizedEmoji: EmojiGroup[] = []; let organizedEmoji: EmojiGroup[] = [];
for (const group in emojis) { for (const group in emojis) {
@ -141,7 +163,7 @@ import * as Utils from './utilities';
// Add GitHub Custom Emoji // Add GitHub Custom Emoji
tableOfContents += `\n- ${Utils.anchor('GitHub Custom Emoji')}\n\n`; tableOfContents += `\n- ${Utils.anchor('GitHub Custom Emoji')}\n\n`;
markdown += `### GitHub Custom Emoji\n\n`; markdown += `## GitHub Custom Emoji\n\n`;
markdown += `|Emoji|Shortcode|\n`; markdown += `|Emoji|Shortcode|\n`;
markdown += `|:---:|:-----:|\n`; markdown += `|:---:|:-----:|\n`;
for (let x = 0; x < customGroup.length; x++) { for (let x = 0; x < customGroup.length; x++) {
@ -155,11 +177,20 @@ import * as Utils from './utilities';
// Add Table of Contents // Add Table of Contents
markdown = tableOfContents + '\n\n' + markdown; markdown = tableOfContents + '\n\n' + markdown;
// icon divider
markdown = ':red_circle: :orange_circle: :yellow_circle: :green_circle: :large_blue_circle: :purple_circle: :brown_circle: :black_circle: :white_circle: :red_square: :orange_square: :yellow_square: :green_square: :large_blue_square: :purple_square: :brown_square: :black_large_square: :white_large_square: \n\n' + markdown;
// Add GitHub Actions badge (Auto Update) // Add GitHub Actions badge (Auto Update)
markdown = `![Auto Update by GitHub Actions](https://github.com/jasonfoknxu/github-emoji-icon-list/actions/workflows/auto-update.yml/badge.svg)\n\n` + markdown; markdown = `[![Auto Update by GitHub Actions](https://github.com/jasonfoknxu/github-emoji-icon-list/actions/workflows/auto-update.yml/badge.svg)](https://github.com/jasonfoknxu/github-emoji-icon-list/actions/workflows/auto-update.yml) :robot: Auto update by GitHub Actions every week.\n\n` + markdown;
// Add the Json version info
markdown = `[:floppy_disk: JSON version](https://github.com/jasonfoknxu/github-emoji-icon-list/blob/main/github-emoji.json) is available. Feel free to use it for further development.\n\n` + markdown;
// Add the Json version info
markdown = `:bar_chart: Number of GitHub Emoji Icon: ${Utils.numberIcon(numberOfEmoji)}\n\n` + markdown;
// Introduction // Introduction
markdown = `This list includes all the usable Emoji icon shortcodes in GitHub Markdown. The list is automatically generated from [GitHub Emoji API](${config.GitHub_Emojis_List}) with the information from [Unicode Emoji data file](${config.Unicode_Emojis_Data}).\n\nThe first column is the emoji icon, second column is the shortcode for Markdown, third column is the name of the emoji from the Unicode data.\n\n*The emoji may be displayed in different result on various system*\n\n` + markdown; markdown = `This list includes all the usable Emoji icon shortcodes in GitHub Markdown. The list is automatically generated from [:octocat: GitHub Emoji API](${config.GitHub_Emojis_List}) with the information from [Unicode Emoji data file](${config.Unicode_Emojis_Data}).\n\n> :information_source: *The emoji may be displayed in different result on various system or browser*\n\n` + markdown;
// Heading // Heading
markdown = `# GitHub Emoji Icon List\n\n` + markdown; markdown = `# GitHub Emoji Icon List\n\n` + markdown;

@ -2,7 +2,9 @@ interface IEmoji {
unicode: string, unicode: string,
shortcode?: string, shortcode?: string,
name: string, name: string,
order: number order?: number,
emoji?: string,
origUnicode?: string
} }
interface IEmojiGroup { interface IEmojiGroup {

@ -1,7 +1,8 @@
interface IUnicode { interface IUnicode {
type: string, type: string,
name: string, name: string,
unicode?: string unicode?: string,
original?: string
} }
interface IUnicodeEmojiData { interface IUnicodeEmojiData {
@ -12,5 +13,6 @@ interface IUnicodeEmoji {
name: string, name: string,
group: string, group: string,
subgroup: string, subgroup: string,
order: number order: number,
origUnicode?: string
} }

@ -63,9 +63,11 @@ const parse = (text: string): IUnicode | null => {
const dataRegex = /^(.+)\s+;.+#.+E[\d.]+\s+(.+)$/i; const dataRegex = /^(.+)\s+;.+#.+E[\d.]+\s+(.+)$/i;
const dataMatch = text.match(dataRegex); const dataMatch = text.match(dataRegex);
if (dataMatch !== null) { if (dataMatch !== null) {
let unicode = dataMatch[1].trim();
// \u200d is the joiner unicode which is not used in GitHub icon file naming // \u200d is the joiner unicode which is not used in GitHub icon file naming
const unicode = dataMatch[1].trim().replace(/\s200D/g, '').replace(/\s/g, '-').toUpperCase(); const originalUnicode = (unicode.includes(' 200D')) ? unicode.replace(/\s/g, '-').toUpperCase() : undefined;
return {type: 'emoji', name: dataMatch[2].trim(), unicode: unicode}; unicode = unicode.replace(/\s200D/g, '').replace(/\s/g, '-').toUpperCase();
return {type: 'emoji', name: dataMatch[2].trim(), unicode: unicode, original: originalUnicode };
} }
const subgroupRegex = /^#\s+subgroup:\s+(.+)$/i; const subgroupRegex = /^#\s+subgroup:\s+(.+)$/i;
const subgroupMatch = text.match(subgroupRegex); const subgroupMatch = text.match(subgroupRegex);
@ -115,6 +117,39 @@ const toEmoji = (unicode: string): string => {
return String.fromCodePoint(parseInt(unicode, 16)); return String.fromCodePoint(parseInt(unicode, 16));
}; };
/**
* Convert the unicode text to Unicode
*
* @param unicodeText - The text of the Unicode
*
* @returns The Unicode formatted unicode
*/
const toUnicode = (unicodeText: string): string => {
if (unicodeText.includes('-')) {
const codes = unicodeText.split('-');
return codes.map((u) => {
return ` U+${u}`;
}).join('').trim();
}
return `U+${unicodeText}`;
};
/**
* Convert the number to icon
*
* @param num - The number text
*
* @returns The shortcodes of the number icon
*/
const numberIcon = (num: number | string): string => {
const mapping = ['zero','one','two','three','four','five','six','seven','eight','nine'];
let result = '';
for (const n of num.toString()) {
result += `:${mapping[parseInt(n)]}:`;
}
return result;
};
/** /**
* Create a Markdown Anchor * Create a Markdown Anchor
* *
@ -177,4 +212,4 @@ const timeNow = (): string => {
}; };
export {getConfig, get, base, parse, title, toEmoji, anchor, writeFile, log, timeNow}; export {getConfig, get, base, parse, title, toEmoji, toUnicode, numberIcon, anchor, writeFile, log, timeNow};

Loading…
Cancel
Save