From: David Date: Sun, 26 Jan 2020 18:53:57 +0000 (+0100) Subject: TS func refactoring X-Git-Url: http://these/git/%7B%60%24%7BwebArchiveUrl%7D/%22%7B%7D/%24%7B%60data:application/static/%7B%60https:/%7BmarkdownHelpUrl%7D?a=commitdiff_plain;h=6718e2eb234cd754ac0c3fe05a7193a708bf6d82;p=lemmy.git TS func refactoring --- diff --git a/ui/src/env.ts b/ui/src/env.ts index 82377415..af9aad5d 100644 --- a/ui/src/env.ts +++ b/ui/src/env.ts @@ -1,6 +1,5 @@ -let host = `${window.location.hostname}`; -let port = `${window.location.port == '4444' ? '8536' : window.location.port}`; -let endpoint = `${host}:${port}`; -export let wsUri = `${ - window.location.protocol == 'https:' ? 'wss://' : 'ws://' -}${endpoint}/api/v1/ws`; +const host = `${window.location.hostname}`; +const port = `${window.location.port == '4444' ? '8536' : window.location.port}`; +const endpoint = `${host}:${port}`; + +export const wsUri = `${window.location.protocol == 'https:' ? 'wss://' : 'ws://'}${endpoint}/api/v1/ws`; diff --git a/ui/src/i18next.ts b/ui/src/i18next.ts index 2da3dfbe..a1fda907 100644 --- a/ui/src/i18next.ts +++ b/ui/src/i18next.ts @@ -27,10 +27,7 @@ const resources = { fi, }; -function format(value: any, format: any, lng: any) { - if (format === 'uppercase') return value.toUpperCase(); - return value; -} +const format = (value, format, lng) => format === 'uppercase' ? value.toUpperCase() : value; i18next.init({ debug: false, @@ -40,9 +37,7 @@ i18next.init({ lng: getLanguage(), fallbackLng: 'en', resources, - interpolation: { - format: format, - }, + interpolation: { format }, }); export { i18next as i18n, resources }; diff --git a/ui/src/version.ts b/ui/src/version.ts index 81ff581b..2e0add0f 100644 --- a/ui/src/version.ts +++ b/ui/src/version.ts @@ -1 +1 @@ -export let version: string = 'v0.6.5'; +export const version: string = 'v0.6.5'; diff --git a/ui/translation_report.ts b/ui/translation_report.ts index 19718c7d..fae0359f 100644 --- a/ui/translation_report.ts +++ b/ui/translation_report.ts @@ -11,24 +11,26 @@ import { it } from './src/translations/it'; import { fi } from './src/translations/fi'; import fs from 'fs'; -let readmePath = '../README.md'; +const readmePath = '../README.md'; -let open = ''; -let close = ''; +const open = ''; +const close = ''; -let readmeTxt = fs.readFileSync(readmePath, { encoding: 'utf8' }); +const readmeTxt = fs.readFileSync(readmePath, { encoding: 'utf8' }); -let before = readmeTxt.split(open)[0]; -let after = readmeTxt.split(close)[1]; +const before = readmeTxt.split(open)[0]; +const after = readmeTxt.split(close)[1]; -let report = buildReport(); +const report = buildReport(); -let alteredReadmeTxt = `${before}${open}\n\n${report}\n${close}${after}`; +const alteredReadmeTxt = `${before}${open}\n\n${report}\n${close}${after}`; fs.writeFileSync(readmePath, alteredReadmeTxt); +const difference = (a: Array, b: Array): Array => a.filter(x => !b.includes(x)); + function buildReport(): string { - let files = [ + const files = [ { t: de, n: 'de' }, { t: eo, n: 'eo' }, { t: es, n: 'es' }, @@ -40,21 +42,16 @@ function buildReport(): string { { t: sv, n: 'sv' }, { t: zh, n: 'zh' }, ]; - let masterKeys = Object.keys(en.translation); - - let report = 'lang | done | missing\n'; - report += '--- | --- | ---\n'; + const masterKeys = Object.keys(en.translation); - for (let file of files) { - let keys = Object.keys(file.t.translation); - let pct: number = (keys.length / masterKeys.length) * 100; - let missing = difference(masterKeys, keys); - report += `${file.n} | ${pct.toFixed(0)}% | ${missing} \n`; - } + const report = 'lang | done | missing\n' + + '--- | --- | ---\n' + + files.map(file => { + const keys = Object.keys(file.t.translation); + const pct: number = (keys.length / masterKeys.length) * 100; + const missing = difference(masterKeys, keys); + return `${file.n} | ${pct.toFixed(0)}% | ${missing}`; + }).join("\n"); return report; } - -function difference(a: Array, b: Array): Array { - return a.filter(x => !b.includes(x)); -}