From e55b50b9daa16547965f04c797d998f7a5da727d Mon Sep 17 00:00:00 2001 From: ikatyang Date: Mon, 24 Jul 2017 12:25:33 +0800 Subject: [PATCH] style: reformat with prettier --- src/create-cheat-sheet.test.ts | 2 +- src/create-cheat-sheet.ts | 59 +++++++++++++++++++--------------- 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/src/create-cheat-sheet.test.ts b/src/create-cheat-sheet.test.ts index b265e17..2306164 100644 --- a/src/create-cheat-sheet.test.ts +++ b/src/create-cheat-sheet.test.ts @@ -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 () => { const cheat_sheet = await create_cheat_sheet(); diff --git a/src/create-cheat-sheet.ts b/src/create-cheat-sheet.ts index 0e4ab1e..4a6e695 100644 --- a/src/create-cheat-sheet.ts +++ b/src/create-cheat-sheet.ts @@ -18,7 +18,9 @@ const travis_badge_url = `https://travis-ci.org/${repo_author}/${repo_name}.svg? const url_descriptions = [ ['GitHub Emoji API', api_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 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) => { const emojis: string[] = []; const category = $(category_element).text(); - $html.find(`#emoji-${category.toLowerCase()} li .name`).each((_inner_index, emoji_element) => { - const emoji = $(emoji_element).text(); - const index = api_emojis.indexOf(emoji); - if (index !== -1) { - api_emojis.splice(index, 1); - emojis.push(emoji); - } - }); + $html + .find(`#emoji-${category.toLowerCase()} li .name`) + .each((_inner_index, emoji_element) => { + const emoji = $(emoji_element).text(); + const index = api_emojis.indexOf(emoji); + if (index !== -1) { + api_emojis.splice(index, 1); + emojis.push(emoji); + } + }); emoji_table[category] = emojis; }); @@ -82,10 +86,12 @@ function create_table(emoji_table: EmojiTable) { ## ${toc_name} - ${categories.map(category => `- [${category}](#${category.toLowerCase()})`).join('\n')} + ${categories + .map(category => `- [${category}](#${category.toLowerCase()})`) + .join('\n')} - ${ - categories.map(category => { + ${categories + .map(category => { const emojis = emoji_table[category]; return format(` @@ -95,8 +101,8 @@ function create_table(emoji_table: EmojiTable) { ${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(` - | [${top_name}](${top_href}) |${ - row_emojis.map( - emoji => emoji.length !== 0 - ? ` :${emoji}: | \`:${emoji}:\` ` - : ' | ', - ).join(' | ') - }| + | [${top_name}](${top_href}) |${row_emojis + .map( + emoji => (emoji.length !== 0 ? ` :${emoji}: | \`:${emoji}:\` ` : ' | '), + ) + .join(' | ')}| `)}\n`; } @@ -126,26 +130,29 @@ function create_table_content(emojis: string[]) { function create_table_head() { return format(` - | |${(' ico | emoji |').repeat(column_divisions)} - | - |${(' --- | ----- |').repeat(column_divisions)} + | |${' ico | emoji |'.repeat(column_divisions)} + | - |${' --- | ----- |'.repeat(column_divisions)} `); } function format(str: string) { - return str.trim().replace(/^ +/mg, ''); + return str.trim().replace(/^ +/gm, ''); } async function get_html(url: string) { return new Promise((resolve, reject) => { - const options = {url}; + const options = { url }; if (url === api_url) { 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) => { // istanbul ignore next + // tslint:disable-next-line:early-exit if (!error && response.statusCode === 200) { resolve(html); } else {