forked from neel1996/langline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
75 lines (64 loc) · 2.33 KB
/
index.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import path from "path";
import { CheckWithExtension } from "./lib/CheckWithExtension";
import { CheckWithFile } from "./lib/CheckWithFile";
import { CheckWithFileName } from "./lib/CheckWithFileName";
import { CheckWithLanguageName } from "./lib/CheckWithLanguageName";
import { ErrorObject } from "./lib/interface/ErrorInterface";
import { LangData } from "./lib/interface/LangDataInterface";
import { LanguageType } from "./lib/types/LanguageType";
import { DataFileReader } from "./utils/readFromDataFile";
var dataFilePath: string = path.join(
__dirname,
"..",
"data/linguistDataSet.json"
);
var dataFileContent: LangData[] = [];
export class LangLine {
constructor() {
dataFileContent = new DataFileReader(dataFilePath).readFromFile();
}
/**
* Method to lookup a language using extension. Pass a valid file extension to get the respective programming language
* @param {string} extension
* @returns LangData - Language object with name, extensions and prismjs component name if exists
*/
public withExtension(extension: string): LangData | ErrorObject {
return new CheckWithExtension(
extension,
dataFileContent
).checkWithExtensionHandler();
}
/**
* Method to get the programming language based on a supplied file name
* @param {string} fileName
* @returns LangData - Language object with name, extensions and prismjs component name if exists
*/
public withFileName(fileName: string): LangData | ErrorObject {
return new CheckWithFileName(
fileName,
dataFileContent
).checkWithFileNameHandler();
}
/**
* Method to get the programming language by passing on an actual file
* @param {string} fileName - Actual file
* @returns Promise - resolves a promise with the language data
*/
public async withFile(fileName: string): Promise<LangData | ErrorObject> {
return await new CheckWithFile(
fileName,
dataFileContent
).chechWithFileHandler();
}
/**
* Method which accepts a language name from a set of allowed values and returns the respective language data
* @param {LanguageType} languageName
* @returns LangData
*/
public withLanguageName(languageName: LanguageType): LangData | ErrorObject {
return new CheckWithLanguageName(
languageName,
dataFileContent
).checkWithLanguageNameHandler();
}
}