Default languages with env & langcodes typed (#94)

This commit is contained in:
David
2022-02-24 19:53:31 +01:00
committed by GitHub
parent 5e4db73a9f
commit 5856776785
15 changed files with 89 additions and 50 deletions

View File

@@ -1,10 +1,10 @@
import UserAgent from "user-agents";
import cheerio from "cheerio";
import { replaceBoth } from "./language";
import { replaceBoth, LangCode } from "./language";
export async function googleScrape(
source: string,
target: string,
source: LangCode,
target: LangCode,
query: string
): Promise<{
translationRes: string
@@ -57,8 +57,8 @@ export function extractSlug(slug: string[]): {
}
}
export async function textToSpeechScrape(lang: string, text: string) {
const { target: parsedLang } = replaceBoth("mapping", { source: "", target: lang });
export async function textToSpeechScrape(lang: LangCode, text: string) {
const { target: parsedLang } = replaceBoth("mapping", { source: "auto", target: lang });
const lastSpace = text.lastIndexOf(" ", 200);
const slicedText = text.slice(0, text.length > 200 && lastSpace !== -1 ? lastSpace : 200);