Skip to content

Commit 5addd03

Browse files
committed
Format
1 parent 780b78b commit 5addd03

File tree

14 files changed

+394
-5158
lines changed

14 files changed

+394
-5158
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
extension/omnibox/data/hackage/hackageRawData.ts

.prettierrc.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
printWidth = 120

build.ts

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
1-
import * as esbuild from 'esbuild';
1+
import * as esbuild from "esbuild";
22
import * as fs from "fs/promises";
33

4-
type Browser = 'chrome' | 'firefox' | 'edge';
4+
type Browser = "chrome" | "firefox" | "edge";
55

66
class Builder {
7-
private watch: boolean;
8-
private dev: boolean;
9-
private browser: Browser;
10-
private buildFile: string;
11-
private staticFiles: File[];
12-
private staticDirs: string[];
13-
14-
constructor(browser: Browser, watch: boolean, dev: boolean, buildFile: string) {
15-
this.browser = browser;
16-
this.watch = watch;
17-
this.dev = dev;
18-
this.buildFile = buildFile;
19-
this.staticFiles = [];
20-
this.staticDirs = [];
21-
}
22-
23-
getOutDir(): string {
24-
return `./dist-${this.browser}`;
25-
}
26-
27-
build() {
28-
fs.mkdir(this.getOutDir(), { recursive: true });
29-
fs.copyFile('./manifest.json', `${this.getOutDir()}/manifest.json`);
30-
const buildOptions: esbuild.BuildOptions = {
31-
entryPoints: [this.buildFile],
32-
bundle: true,
33-
outdir: this.getOutDir()
34-
};
35-
esbuild.build(buildOptions);
36-
}
7+
private watch: boolean;
8+
private dev: boolean;
9+
private browser: Browser;
10+
private buildFile: string;
11+
private staticFiles: File[];
12+
private staticDirs: string[];
13+
14+
constructor(browser: Browser, watch: boolean, dev: boolean, buildFile: string) {
15+
this.browser = browser;
16+
this.watch = watch;
17+
this.dev = dev;
18+
this.buildFile = buildFile;
19+
this.staticFiles = [];
20+
this.staticDirs = [];
21+
}
22+
23+
getOutDir(): string {
24+
return `./dist-${this.browser}`;
25+
}
26+
27+
build() {
28+
fs.mkdir(this.getOutDir(), { recursive: true });
29+
fs.copyFile("./manifest.json", `${this.getOutDir()}/manifest.json`);
30+
const buildOptions: esbuild.BuildOptions = {
31+
entryPoints: [this.buildFile],
32+
bundle: true,
33+
outdir: this.getOutDir(),
34+
};
35+
esbuild.build(buildOptions);
36+
}
3737
}
3838

39-
const watchFlag = process.argv.includes('--watch');
40-
const devFlag = process.argv.includes('--dev');
41-
const chromeFlag = process.argv.includes('--chrome');
42-
const firefoxFlag = process.argv.includes('--firefox');
43-
const edgeFlag = process.argv.includes('--edge');
39+
const watchFlag = process.argv.includes("--watch");
40+
const devFlag = process.argv.includes("--dev");
41+
const chromeFlag = process.argv.includes("--chrome");
42+
const firefoxFlag = process.argv.includes("--firefox");
43+
const edgeFlag = process.argv.includes("--edge");
4444

45-
const browser: Browser = chromeFlag ? 'chrome' : firefoxFlag ? 'firefox' : edgeFlag ? 'edge' : 'chrome';
45+
const browser: Browser = chromeFlag ? "chrome" : firefoxFlag ? "firefox" : edgeFlag ? "edge" : "chrome";
4646
const builder = new Builder(browser, watchFlag, devFlag, "./extension/main.ts");
4747

48-
builder.build()
48+
builder.build();

extension/Omnibox/Compat.ts

Lines changed: 57 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,72 @@
11
export class Compat {
2-
public static browserType(): "firefox" | "edge" | "chrome" | "unknown" {
3-
let userAgent = navigator.userAgent.toLowerCase()
2+
public static browserType(): "firefox" | "edge" | "chrome" | "unknown" {
3+
let userAgent = navigator.userAgent.toLowerCase();
44

5-
if (userAgent.indexOf("firefox") !== -1)
6-
return "firefox"
7-
if (userAgent.indexOf("edg") !== -1)
8-
return "edge"
9-
if (userAgent.indexOf("chrome") !== -1)
10-
return "chrome"
5+
if (userAgent.indexOf("firefox") !== -1) return "firefox";
6+
if (userAgent.indexOf("edg") !== -1) return "edge";
7+
if (userAgent.indexOf("chrome") !== -1) return "chrome";
118

12-
return "unknown"
13-
}
9+
return "unknown";
10+
}
1411

15-
public static omniboxPageSize(): number {
16-
return {
17-
"firefox": 6,
18-
"edge": 7,
19-
"chrome": 8,
20-
"unknown": 6
21-
}[this.browserType()]
22-
}
12+
public static omniboxPageSize(): number {
13+
return {
14+
firefox: 6,
15+
edge: 7,
16+
chrome: 8,
17+
unknown: 6,
18+
}[this.browserType()];
19+
}
2320

24-
/**
25-
* Escape the five predefined entities to display them as text.
26-
* @param str
27-
*/
28-
public static escape(str?: string): string {
29-
str = str || ""
30-
return this.browserType() === "firefox"
31-
? str
32-
: str.replace(/&/g, "&")
33-
.replace(/</g, "&lt;")
34-
.replace(/>/g, "&gt;")
35-
.replace(/"/g, "&quot;")
36-
.replace(/'/g, "&#039;")
37-
}
21+
/**
22+
* Escape the five predefined entities to display them as text.
23+
* @param str
24+
*/
25+
public static escape(str?: string): string {
26+
str = str || "";
27+
return this.browserType() === "firefox"
28+
? str
29+
: str
30+
.replace(/&/g, "&amp;")
31+
.replace(/</g, "&lt;")
32+
.replace(/>/g, "&gt;")
33+
.replace(/"/g, "&quot;")
34+
.replace(/'/g, "&#039;");
35+
}
3836

39-
public static normalizedDateString(date: Date): string {
40-
let month = (date.getMonth() + 1).toString() // FIXME: why plus one here?
41-
let day = date.getDate().toString()
42-
let year = date.getFullYear().toString()
43-
return [year, month.padStart(2, "0"), day.padStart(2, "0")].join("-")
44-
}
37+
public static normalizedDateString(date: Date): string {
38+
let month = (date.getMonth() + 1).toString(); // FIXME: why plus one here?
39+
let day = date.getDate().toString();
40+
let year = date.getFullYear().toString();
41+
return [year, month.padStart(2, "0"), day.padStart(2, "0")].join("-");
42+
}
4543

46-
public static capitalize(s?: string): string {
47-
if (!s || s.length === 0) {
48-
return ""
49-
}
50-
return s.charAt(0).toUpperCase() + s.slice(1)
44+
public static capitalize(s?: string): string {
45+
if (!s || s.length === 0) {
46+
return "";
5147
}
48+
return s.charAt(0).toUpperCase() + s.slice(1);
49+
}
5250

53-
public static eliminateTags(value?: string): string {
54-
if (!value) {
55-
return ""
56-
}
57-
return value.replace(/<\/?(match|dim|code|em|strong)>/g, "")
51+
public static eliminateTags(value?: string): string {
52+
if (!value) {
53+
return "";
5854
}
55+
return value.replace(/<\/?(match|dim|code|em|strong)>/g, "");
56+
}
5957

60-
public static tagged(tag: string, s: string): string {
61-
if (this.browserType() !== "firefox") {
62-
return `<${tag}>${s}</${tag}>`
63-
}
64-
return s
58+
public static tagged(tag: string, s: string): string {
59+
if (this.browserType() !== "firefox") {
60+
return `<${tag}>${s}</${tag}>`;
6561
}
62+
return s;
63+
}
6664

67-
public static taggedMatch(s: string): string {
68-
return this.tagged("match", s)
69-
}
65+
public static taggedMatch(s: string): string {
66+
return this.tagged("match", s);
67+
}
7068

71-
public static taggedDim(s: string): string {
72-
return this.tagged("dim", s)
73-
}
69+
public static taggedDim(s: string): string {
70+
return this.tagged("dim", s);
71+
}
7472
}
Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
import { CommandHandler, SearchCache } from "./type";
22

33
export default class ExtensionHandler extends CommandHandler {
4-
private static EXTENSION_BASE_URL: string = "https://downloads.haskell.org/ghc/latest/docs/users_guide/";
4+
private static EXTENSION_BASE_URL: string = "https://downloads.haskell.org/ghc/latest/docs/users_guide/";
55

6-
private static TRIGGER_PREFIXES: string[] = [
7-
":ext", ":extension", ":lan", ":lang", ":language"
8-
];
6+
private static TRIGGER_PREFIXES: string[] = [":ext", ":extension", ":lan", ":lang", ":language"];
97

10-
public static isExtensionMode(input: string): boolean {
11-
return this.hasTriggerPrefix(input, ...ExtensionHandler.TRIGGER_PREFIXES);
12-
}
8+
public static isExtensionMode(input: string): boolean {
9+
return this.hasTriggerPrefix(input, ...ExtensionHandler.TRIGGER_PREFIXES);
10+
}
1311

14-
handleChange(input: string, cache: SearchCache): chrome.omnibox.SuggestResult[] {
15-
const query = this.removeExtensionPrefix(input);
12+
handleChange(input: string, cache: SearchCache): chrome.omnibox.SuggestResult[] {
13+
const query = this.removeExtensionPrefix(input);
1614

17-
throw new Error("Method not implemented.");
18-
}
19-
handleEnter(input: string, cache: SearchCache): string {
20-
throw new Error("Method not implemented.");
21-
}
15+
throw new Error("Method not implemented.");
16+
}
17+
handleEnter(input: string, cache: SearchCache): string {
18+
throw new Error("Method not implemented.");
19+
}
2220

23-
removeExtensionPrefix(input: string): string {
24-
return this.removeTriggerPrefix(input, ...ExtensionHandler.TRIGGER_PREFIXES);
25-
}
21+
removeExtensionPrefix(input: string): string {
22+
return this.removeTriggerPrefix(input, ...ExtensionHandler.TRIGGER_PREFIXES);
23+
}
2624
}

extension/Omnibox/command/hoogle.ts

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,46 @@
11
import { CommandHandler, SearchCache } from "./type";
22

33
export default class HoogleHandler extends CommandHandler {
4-
private static HOOGLE_BASE_URL: string = "https://hoogle.haskell.org/?hoogle=";
5-
6-
private static TRIGGER_PREFIXES: string[] = [":hoogle", "hg"];
7-
8-
9-
public static isHoogleMode(input: string): boolean {
10-
return this.hasTriggerPrefix(input, ...this.TRIGGER_PREFIXES);
11-
}
12-
13-
public static isHoogleUrl(input: string): boolean {
14-
return input.startsWith(HoogleHandler.HOOGLE_BASE_URL);
15-
}
16-
17-
/**
18-
* Generate a hoogle search suggestion by user input, note that the
19-
* input is not prefixed with `:hoogle` or `:hg`.
20-
* @param query
21-
* @returns
22-
*/
23-
public static buildHoogleSuggestResult(query: string): chrome.omnibox.SuggestResult {
24-
return {
25-
content: HoogleHandler.HOOGLE_BASE_URL + query,
26-
description: `Search ${query} on [hoogle.haskell.org]`
27-
};
28-
}
29-
30-
handleChange(input: string, _cache: SearchCache): chrome.omnibox.SuggestResult[] {
31-
const query = this.removeHooglePrefix(input);
32-
const result = HoogleHandler.buildHoogleSuggestResult(query);
33-
chrome.omnibox.setDefaultSuggestion({ description: result.description });
34-
35-
// We don't need to show any suggestions in the dropdown list,
36-
// since we have added a default suggestion.
37-
return [];
38-
}
39-
40-
handleEnter(input: string, _cache: SearchCache): string {
41-
return HoogleHandler.HOOGLE_BASE_URL + this.removeHooglePrefix(input);
42-
}
43-
44-
removeHooglePrefix(input: string): string {
45-
return this.removeTriggerPrefix(input, ...HoogleHandler.TRIGGER_PREFIXES);
46-
}
4+
private static HOOGLE_BASE_URL: string = "https://hoogle.haskell.org/?hoogle=";
5+
6+
private static TRIGGER_PREFIXES: string[] = [":hoogle", "hg"];
7+
8+
public static isHoogleMode(input: string): boolean {
9+
return this.hasTriggerPrefix(input, ...this.TRIGGER_PREFIXES);
10+
}
11+
12+
public static isHoogleUrl(input: string): boolean {
13+
return input.startsWith(HoogleHandler.HOOGLE_BASE_URL);
14+
}
15+
16+
/**
17+
* Generate a hoogle search suggestion by user input, note that the
18+
* input is not prefixed with `:hoogle` or `:hg`.
19+
* @param query
20+
* @returns
21+
*/
22+
public static buildHoogleSuggestResult(query: string): chrome.omnibox.SuggestResult {
23+
return {
24+
content: HoogleHandler.HOOGLE_BASE_URL + query,
25+
description: `Search ${query} on [hoogle.haskell.org]`,
26+
};
27+
}
28+
29+
handleChange(input: string, _cache: SearchCache): chrome.omnibox.SuggestResult[] {
30+
const query = this.removeHooglePrefix(input);
31+
const result = HoogleHandler.buildHoogleSuggestResult(query);
32+
chrome.omnibox.setDefaultSuggestion({ description: result.description });
33+
34+
// We don't need to show any suggestions in the dropdown list,
35+
// since we have added a default suggestion.
36+
return [];
37+
}
38+
39+
handleEnter(input: string, _cache: SearchCache): string {
40+
return HoogleHandler.HOOGLE_BASE_URL + this.removeHooglePrefix(input);
41+
}
42+
43+
removeHooglePrefix(input: string): string {
44+
return this.removeTriggerPrefix(input, ...HoogleHandler.TRIGGER_PREFIXES);
45+
}
4746
}

0 commit comments

Comments
 (0)