Add language endpoint to developer APIs (#41)
* Added languages endpoint and its tests
This commit is contained in:
@@ -33,11 +33,16 @@ export function replaceBoth(
|
||||
return { source, target };
|
||||
}
|
||||
|
||||
export function retrieveFiltered() {
|
||||
const [sourceLangs, targetLangs] = langTypes.map(type => (
|
||||
Object.entries(languages).filter(([code]) => (
|
||||
!Object.keys(exceptions[type]).includes(code)
|
||||
))
|
||||
export function retrieveFromType(type?: LangType): [string, string][] {
|
||||
const langEntries = Object.entries(languages);
|
||||
|
||||
if (!type)
|
||||
return langEntries;
|
||||
return langEntries.filter(([code]) => (
|
||||
!Object.keys(exceptions[type]).includes(code)
|
||||
));
|
||||
return { sourceLangs, targetLangs };
|
||||
}
|
||||
|
||||
export function getName(code: string): string | null {
|
||||
return isKeyOf(languages)(code) ? languages[code] : null;
|
||||
}
|
||||
|
||||
@@ -7,8 +7,9 @@ export async function googleScrape(
|
||||
target: string,
|
||||
query: string
|
||||
): Promise<{
|
||||
translationRes?: string,
|
||||
errorMsg?: string
|
||||
translationRes: string
|
||||
} | {
|
||||
errorMsg: string
|
||||
}> {
|
||||
const parsed = replaceBoth("mapping", { source, target });
|
||||
const res = await fetch(
|
||||
@@ -56,10 +57,7 @@ export function extractSlug(slug: string[]): {
|
||||
}
|
||||
}
|
||||
|
||||
export async function textToSpeechScrape(lang: string, text?: string) {
|
||||
if (!text)
|
||||
return null;
|
||||
|
||||
export async function textToSpeechScrape(lang: string, text: string) {
|
||||
const { target: parsedLang } = replaceBoth("mapping", { source: "", target: lang });
|
||||
|
||||
const lastSpace = text.lastIndexOf(" ", 200);
|
||||
|
||||
Reference in New Issue
Block a user