UNPKG

illyria-scraper

Version:

Google Translate scraper for Illyria Translate

91 lines (90 loc) 3.52 kB
import type { Data } from './types.js'; import type { TranslationInfo } from './interfaces.js'; /** * Extracts the detected source language from translation data * * Attempts to find the language code from multiple possible locations in the data structure, * then maps it to the internal language code format. * * @param data - Raw translation data from Google Translate API * @returns The detected source language code or undefined if not found */ export declare const detected: ([source, target, detected, extra]: Data) => TranslationInfo["detectedSource"]; /** * Extracts typo correction information from translation data * * @param data - Raw translation data from Google Translate API * @returns The typo correction text or undefined if no typo correction exists */ export declare const typo: ([source]: Data) => TranslationInfo["typo"]; /** * Functions for extracting pronunciation information from translation data */ export declare const pronunciation: { /** * Extracts the pronunciation for the query text * * @param data - Raw translation data from Google Translate API * @returns The query pronunciation or undefined if not available */ query: ([source]: Data) => TranslationInfo["pronunciation"]["query"]; /** * Extracts the pronunciation for the translated text * * @param data - Raw translation data from Google Translate API * @returns The translation pronunciation or undefined if not available */ translation: ([, target]: Data) => TranslationInfo["pronunciation"]["translation"]; }; /** * Collection of functions for extracting different types of lists from translation data */ export declare const list: { /** * Extracts word definitions grouped by type (e.g., noun, verb) * * @param data - Raw translation data from Google Translate API * @returns Array of definition groups with their types and definition lists */ definitions: ({ 3: extra }: Data) => TranslationInfo["definitions"]; /** * Extracts example sentences using the translated term * * @param data - Raw translation data from Google Translate API * @returns Array of example sentences */ examples: ({ 3: extra }: Data) => TranslationInfo["examples"]; /** * Extracts words with similar meaning to the query * * @param data - Raw translation data from Google Translate API * @returns Array of similar words */ similar: ({ 3: extra }: Data) => TranslationInfo["similar"]; /** * Extracts additional translations grouped by type (e.g., noun, verb) * * Includes word frequency information where 1 is most frequent and 4 is least frequent. * * @param data - Raw translation data from Google Translate API * @returns Array of translation groups with their types and word lists */ translations: ({ 3: extra }: Data) => TranslationInfo["extraTranslations"]; }; /** * Type for objects that can be filtered for undefined values */ type GenericObject<T> = { [k: string]: T; } | Array<T>; /** * Recursively filters out undefined values from an object or array * * This function helps create cleaner output data by removing all undefined * fields that would otherwise clutter the result. * * @param obj - Object or array to process * @returns A new object or array with all undefined values removed */ export declare const undefinedFields: <T extends GenericObject<V | undefined>, V>(obj: T) => T; export {};