mirror of
https://github.com/ikatyang/emoji-cheat-sheet.git
synced 2025-04-10 17:23:41 +02:00
style: reformat with prettier
This commit is contained in:
parent
9663c4a8b8
commit
e55b50b9da
@ -1,4 +1,4 @@
|
|||||||
import {create_cheat_sheet} from './create-cheat-sheet';
|
import { create_cheat_sheet } from './create-cheat-sheet';
|
||||||
|
|
||||||
test('create-cheat-sheet', async () => {
|
test('create-cheat-sheet', async () => {
|
||||||
const cheat_sheet = await create_cheat_sheet();
|
const cheat_sheet = await create_cheat_sheet();
|
||||||
|
@ -18,7 +18,9 @@ const travis_badge_url = `https://travis-ci.org/${repo_author}/${repo_name}.svg?
|
|||||||
const url_descriptions = [
|
const url_descriptions = [
|
||||||
['GitHub Emoji API', api_url],
|
['GitHub Emoji API', api_url],
|
||||||
['Emoji Cheat Sheet', sheet_url],
|
['Emoji Cheat Sheet', sheet_url],
|
||||||
].map(([site_name, site_url]) => `[${site_name}](${site_url})`).join(' and ');
|
]
|
||||||
|
.map(([site_name, site_url]) => `[${site_name}](${site_url})`)
|
||||||
|
.join(' and ');
|
||||||
|
|
||||||
// tslint:disable-next-line:max-line-length
|
// tslint:disable-next-line:max-line-length
|
||||||
const description = `This cheat sheet is automatically generated from ${url_descriptions}`;
|
const description = `This cheat sheet is automatically generated from ${url_descriptions}`;
|
||||||
@ -51,14 +53,16 @@ export async function create_cheat_sheet() {
|
|||||||
$html.find('h2').each((_outer_index, category_element) => {
|
$html.find('h2').each((_outer_index, category_element) => {
|
||||||
const emojis: string[] = [];
|
const emojis: string[] = [];
|
||||||
const category = $(category_element).text();
|
const category = $(category_element).text();
|
||||||
$html.find(`#emoji-${category.toLowerCase()} li .name`).each((_inner_index, emoji_element) => {
|
$html
|
||||||
const emoji = $(emoji_element).text();
|
.find(`#emoji-${category.toLowerCase()} li .name`)
|
||||||
const index = api_emojis.indexOf(emoji);
|
.each((_inner_index, emoji_element) => {
|
||||||
if (index !== -1) {
|
const emoji = $(emoji_element).text();
|
||||||
api_emojis.splice(index, 1);
|
const index = api_emojis.indexOf(emoji);
|
||||||
emojis.push(emoji);
|
if (index !== -1) {
|
||||||
}
|
api_emojis.splice(index, 1);
|
||||||
});
|
emojis.push(emoji);
|
||||||
|
}
|
||||||
|
});
|
||||||
emoji_table[category] = emojis;
|
emoji_table[category] = emojis;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -82,10 +86,12 @@ function create_table(emoji_table: EmojiTable) {
|
|||||||
|
|
||||||
## ${toc_name}
|
## ${toc_name}
|
||||||
|
|
||||||
${categories.map(category => `- [${category}](#${category.toLowerCase()})`).join('\n')}
|
${categories
|
||||||
|
.map(category => `- [${category}](#${category.toLowerCase()})`)
|
||||||
|
.join('\n')}
|
||||||
|
|
||||||
${
|
${categories
|
||||||
categories.map(category => {
|
.map(category => {
|
||||||
const emojis = emoji_table[category];
|
const emojis = emoji_table[category];
|
||||||
return format(`
|
return format(`
|
||||||
|
|
||||||
@ -95,8 +101,8 @@ function create_table(emoji_table: EmojiTable) {
|
|||||||
${create_table_content(emojis)}
|
${create_table_content(emojis)}
|
||||||
|
|
||||||
`);
|
`);
|
||||||
}).join(('\n').repeat(2))
|
})
|
||||||
}
|
.join('\n'.repeat(2))}
|
||||||
|
|
||||||
`);
|
`);
|
||||||
}
|
}
|
||||||
@ -110,13 +116,11 @@ function create_table_content(emojis: string[]) {
|
|||||||
}
|
}
|
||||||
table_content += `${format(`
|
table_content += `${format(`
|
||||||
|
|
||||||
| [${top_name}](${top_href}) |${
|
| [${top_name}](${top_href}) |${row_emojis
|
||||||
row_emojis.map(
|
.map(
|
||||||
emoji => emoji.length !== 0
|
emoji => (emoji.length !== 0 ? ` :${emoji}: | \`:${emoji}:\` ` : ' | '),
|
||||||
? ` :${emoji}: | \`:${emoji}:\` `
|
)
|
||||||
: ' | ',
|
.join(' | ')}|
|
||||||
).join(' | ')
|
|
||||||
}|
|
|
||||||
|
|
||||||
`)}\n`;
|
`)}\n`;
|
||||||
}
|
}
|
||||||
@ -126,26 +130,29 @@ function create_table_content(emojis: string[]) {
|
|||||||
function create_table_head() {
|
function create_table_head() {
|
||||||
return format(`
|
return format(`
|
||||||
|
|
||||||
| |${(' ico | emoji |').repeat(column_divisions)}
|
| |${' ico | emoji |'.repeat(column_divisions)}
|
||||||
| - |${(' --- | ----- |').repeat(column_divisions)}
|
| - |${' --- | ----- |'.repeat(column_divisions)}
|
||||||
|
|
||||||
`);
|
`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function format(str: string) {
|
function format(str: string) {
|
||||||
return str.trim().replace(/^ +/mg, '');
|
return str.trim().replace(/^ +/gm, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function get_html(url: string) {
|
async function get_html(url: string) {
|
||||||
return new Promise<string>((resolve, reject) => {
|
return new Promise<string>((resolve, reject) => {
|
||||||
const options = {url};
|
const options = { url };
|
||||||
if (url === api_url) {
|
if (url === api_url) {
|
||||||
Object.assign(options, {
|
Object.assign(options, {
|
||||||
headers: {'User-Agent': 'https://github.com/ikatyang/emoji-cheat-sheet'},
|
headers: {
|
||||||
|
'User-Agent': 'https://github.com/ikatyang/emoji-cheat-sheet',
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
request.get(options, (error, response, html) => {
|
request.get(options, (error, response, html) => {
|
||||||
// istanbul ignore next
|
// istanbul ignore next
|
||||||
|
// tslint:disable-next-line:early-exit
|
||||||
if (!error && response.statusCode === 200) {
|
if (!error && response.statusCode === 200) {
|
||||||
resolve(html);
|
resolve(html);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user