-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ts
78 lines (73 loc) · 2.65 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
76
77
78
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 dataFileContent: LangData[] = [];
export class LangLine {
constructor() {
dataFileContent = new DataFileReader().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
* @example
* ```
* const extension = "js";
* const language = new LangLine().withExtension(extension);
* ```
*/
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
* @example
* ```
* const fileName = "addRepoApi.js"; //file name with extension
* const language = new LangLine().withFileName(fileName);
* ```
*/
public withFileName(fileName: string): LangData | ErrorObject {
return new CheckWithFileName(
fileName,
dataFileContent
).checkWithFileNameHandler();
}
/**
* Method to get the programming language by passing on an actual file
* This function is not supported from front-end as it requires the `fs` module
* @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
).checkWithFileHandler();
}
/**
* Method which accepts a language name from a set of allowed values and returns the respective language data
* @param {LanguageType} languageName
* @returns LangData
* @example
* const language = new LangLine().withLanguageName("javascript");
*/
public withLanguageName(
languageName: LanguageType | string
): LangData | ErrorObject {
return new CheckWithLanguageName(
languageName,
dataFileContent
).checkWithLanguageNameHandler();
}
}