|
- import * as KanjidicImpl from './sources/kanjidic';
- import * as JmdictImpl from './sources/jmdict';
-
- const SUPPORTED_SOURCES = [
- KanjidicImpl,
- JmdictImpl,
- ] as const;
-
- export type CreateDownloaderParams = (
- KanjidicImpl.CreateDownloaderParams
- | JmdictImpl.CreateDownloaderParams
- );
-
- export * as Kanjidic from './sources/kanjidic';
- export * as Jmdict from './sources/jmdict';
- export * from './streams';
-
- export const createDownloader = (params: CreateDownloaderParams) => {
- const { type: sourceType, ...etcParams } = params;
-
- const theSourceModule = SUPPORTED_SOURCES
- .find((videoTypeModule) => videoTypeModule.SOURCE_ID === sourceType);
-
- if (!theSourceModule) {
- const validSourceTypes = SUPPORTED_SOURCES.map((videoTypeModule) => videoTypeModule.SOURCE_ID).join(', ');
- throw new TypeError(`Invalid source type: "${sourceType}". Valid values are: ${validSourceTypes}`);
- }
-
- return theSourceModule.createDownloader(etcParams);
- };
|