forked from neighbrum/compose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
languages.ts
34 lines (31 loc) · 895 Bytes
/
languages.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* Defines existing languages for the entire program
* Any language provided by the user needs to be included
* in the languages dictionary
*
*/
import { Language } from './language';
import { python } from './python';
import { javascript } from './javascript';
/**
* Dictionary of languages regestered by the program.
* New languages should be added here.
* The 'key' for each languages should be the simplest name for each language, all lower case
*/
export const languages: { [index: string]: Language } = {
javascript,
python,
};
/**
* Factory to select language with error checking for undefined languages
*
*/
export const languageFactory = (name: string): Language => {
const lang: Language = languages[name];
if (lang === undefined) {
throw new RangeError(
`languageFactory in routes/index.ts has no instance for ${name}`
);
}
return lang;
};