-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "eslint:recommended" and "plugin:@typescript-eslint/recommended" …
…eslint configurations (#118) - Add `eslint:recommended` and `plugin:@typescript-eslint/recommended` to `extends` for `eslint`. - Fix issue with TOC in `README.md`. - Fix lint errors. - Remove `;` from some files.
- Loading branch information
Showing
11 changed files
with
63 additions
and
56 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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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 |
---|---|---|
@@ -1,26 +1,27 @@ | ||
import itParam from 'mocha-param'; | ||
import MyMemoryProvider from '../../providers/MyMemoryProvider'; | ||
import ProviderBase from '../../providers/ProviderBase'; | ||
import itParam from 'mocha-param' | ||
import MyMemoryProvider from '../../providers/MyMemoryProvider' | ||
import ProviderBase from '../../providers/ProviderBase' | ||
import { config } from 'dotenv' | ||
|
||
require('dotenv').config(); | ||
config() | ||
|
||
describe('MyMemoryProvider', () => { | ||
itParam<string | undefined>('should get correct translation', | ||
[undefined, process.env.MYMEMORY_API_KEY], async (apiKey) => { | ||
const provider: ProviderBase = new MyMemoryProvider(apiKey); | ||
const translations = await provider.translate('Evening', 'en|pt'); | ||
expect(translations.length).toBeGreaterThan(0); | ||
expect(translations[0]).toEqual('NOITE'); | ||
}); | ||
const provider: ProviderBase = new MyMemoryProvider(apiKey) | ||
const translations = await provider.translate('Evening', 'en|pt') | ||
expect(translations.length).toBeGreaterThan(0) | ||
expect(translations[0]).toEqual('NOITE') | ||
}) | ||
|
||
test('should fail because of invalid lang', async () => { | ||
const provider: ProviderBase = new MyMemoryProvider(); | ||
const provider: ProviderBase = new MyMemoryProvider() | ||
try { | ||
await provider.translate('Evening', 'abc123'); | ||
await provider.translate('Evening', 'abc123') | ||
} catch (e) { | ||
expect(e).toBeTruthy(); | ||
return; | ||
expect(e).toBeTruthy() | ||
return | ||
} | ||
fail(); | ||
}); | ||
}); | ||
fail() | ||
}) | ||
}) |
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 |
---|---|---|
@@ -1,23 +1,23 @@ | ||
import ProviderBase from './ProviderBase'; | ||
import ProviderBase from './ProviderBase' | ||
|
||
type FunTranslationsResponse = | ||
{ success: { total: number } | undefined, contents: { translated: string } }; | ||
{ success: { total: number } | undefined, contents: { translated: string } } | ||
|
||
export default class FunTranslationsProvider extends ProviderBase { | ||
constructor() { | ||
super('https://api.funtranslations.com'); | ||
super('https://api.funtranslations.com') | ||
} | ||
|
||
async translate(text: string, lang: string): Promise<string[]> { | ||
const url = `/translate/${lang}.json?text=${text}`; | ||
const url = `/translate/${lang}.json?text=${text}` | ||
return this.api<FunTranslationsResponse>({ url, method: 'GET' }) | ||
.then(({ success, contents }) => { | ||
if (success && success.total > 0) { | ||
return [contents.translated]; | ||
return [contents.translated] | ||
} | ||
console.warn( | ||
'Result is either not success or doesn\'t have any translations'); | ||
return [text]; | ||
}); | ||
}; | ||
'Result is either not success or doesn\'t have any translations') | ||
return [text] | ||
}) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,19 +1,20 @@ | ||
/* eslint-disable camelcase */ | ||
import ProviderBase from './ProviderBase'; | ||
|
||
type LinguaToolsResponse = { freq: number, l1_text: string }[]; | ||
/* eslint-disable camelcase */ | ||
type LinguaToolsResponse = { freq: number, l1_text: string }[] | ||
|
||
export default class LinguaToolsProvider extends ProviderBase { | ||
constructor() { | ||
super('https://lt-translate-test.herokuapp.com'); | ||
super('https://lt-translate-test.herokuapp.com') | ||
} | ||
|
||
translate(text: string, lang: string): Promise<string[]> { | ||
const url: string = `/?langpair=${lang}&query=${text}`; | ||
const url = `/?langpair=${lang}&query=${text}` | ||
return this.api<LinguaToolsResponse>({ url, method: 'GET' }) | ||
.then((translations) => { | ||
translations.sort((a, b) => a.freq > b.freq ? 1 : -1); | ||
return translations.map(({ l1_text }) => l1_text); | ||
}); | ||
translations.sort((a, b) => a.freq > b.freq ? 1 : -1) | ||
return translations.map(({ l1_text }) => l1_text) | ||
}) | ||
} | ||
} | ||
/* eslint-enable camelcase */ |
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
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