aboutsummaryrefslogtreecommitdiff
path: root/src/shared/settings
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/settings')
-rw-r--r--src/shared/settings/Blacklist.ts39
-rw-r--r--src/shared/settings/Key.ts20
-rw-r--r--src/shared/settings/Keymaps.ts21
-rw-r--r--src/shared/settings/Properties.ts47
-rw-r--r--src/shared/settings/Search.ts10
-rw-r--r--src/shared/settings/Settings.ts31
6 files changed, 81 insertions, 87 deletions
diff --git a/src/shared/settings/Blacklist.ts b/src/shared/settings/Blacklist.ts
index 6c54d73..278dbd6 100644
--- a/src/shared/settings/Blacklist.ts
+++ b/src/shared/settings/Blacklist.ts
@@ -1,14 +1,16 @@
-import Key from './Key';
+import Key from "./Key";
-export type BlacklistItemJSON = string | {
- url: string,
- keys: string[],
-};
+export type BlacklistItemJSON =
+ | string
+ | {
+ url: string;
+ keys: string[];
+ };
export type BlacklistJSON = BlacklistItemJSON[];
const regexFromWildcard = (pattern: string): RegExp => {
- const regexStr = '^' + pattern.replace(/\*/g, '.*') + '$';
+ const regexStr = "^" + pattern.replace(/\*/g, ".*") + "$";
return new RegExp(regexStr);
};
@@ -23,11 +25,7 @@ export class BlacklistItem {
private readonly keyEntities: Key[];
- constructor(
- pattern: string,
- partial: boolean,
- keys: string[]
- ) {
+ constructor(pattern: string, partial: boolean, keys: string[]) {
this.pattern = pattern;
this.regex = regexFromWildcard(pattern);
this.partial = partial;
@@ -36,7 +34,7 @@ export class BlacklistItem {
}
static fromJSON(json: BlacklistItemJSON): BlacklistItem {
- return typeof json === 'string'
+ return typeof json === "string"
? new BlacklistItem(json, false, [])
: new BlacklistItem(json.url, true, json.keys);
}
@@ -49,7 +47,7 @@ export class BlacklistItem {
}
matches(url: URL): boolean {
- return this.pattern.includes('/')
+ return this.pattern.includes("/")
? this.regex.test(url.host + url.pathname)
: this.regex.test(url.host);
}
@@ -58,30 +56,27 @@ export class BlacklistItem {
if (!this.matches(url) || !this.partial) {
return false;
}
- return this.keyEntities.some(k => k.equals(key));
+ return this.keyEntities.some((k) => k.equals(key));
}
}
export default class Blacklist {
- constructor(
- public readonly items: BlacklistItem[],
- ) {
- }
+ constructor(public readonly items: BlacklistItem[]) {}
static fromJSON(json: BlacklistJSON): Blacklist {
- const items = json.map(o => BlacklistItem.fromJSON(o));
+ const items = json.map((o) => BlacklistItem.fromJSON(o));
return new Blacklist(items);
}
toJSON(): BlacklistJSON {
- return this.items.map(item => item.toJSON());
+ return this.items.map((item) => item.toJSON());
}
includesEntireBlacklist(url: URL): boolean {
- return this.items.some(item => !item.partial && item.matches(url));
+ return this.items.some((item) => !item.partial && item.matches(url));
}
includeKey(url: URL, key: Key) {
- return this.items.some(item => item.includeKey(url, key));
+ return this.items.some((item) => item.includeKey(url, key));
}
}
diff --git a/src/shared/settings/Key.ts b/src/shared/settings/Key.ts
index 1464e57..2f47aff 100644
--- a/src/shared/settings/Key.ts
+++ b/src/shared/settings/Key.ts
@@ -1,4 +1,4 @@
-const digits = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
+const digits = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
export default class Key {
public readonly key: string;
@@ -32,10 +32,10 @@ export default class Key {
}
static fromMapKey(str: string): Key {
- if (str.startsWith('<') && str.endsWith('>')) {
+ if (str.startsWith("<") && str.endsWith(">")) {
const inner = str.slice(1, -1);
- const shift = inner.includes('S-');
- let base = inner.slice(inner.lastIndexOf('-') + 1);
+ const shift = inner.includes("S-");
+ let base = inner.slice(inner.lastIndexOf("-") + 1);
if (shift && base.length === 1) {
base = base.toUpperCase();
} else if (!shift && base.length === 1) {
@@ -44,9 +44,9 @@ export default class Key {
return new Key({
key: base,
shift: shift,
- ctrl: inner.includes('C-'),
- alt: inner.includes('A-'),
- meta: inner.includes('M-'),
+ ctrl: inner.includes("C-"),
+ alt: inner.includes("A-"),
+ meta: inner.includes("M-"),
});
}
@@ -64,10 +64,12 @@ export default class Key {
}
equals(key: Key) {
- return this.key === key.key &&
+ return (
+ this.key === key.key &&
this.ctrl === key.ctrl &&
this.meta === key.meta &&
this.alt === key.alt &&
- this.shift === key.shift;
+ this.shift === key.shift
+ );
}
}
diff --git a/src/shared/settings/Keymaps.ts b/src/shared/settings/Keymaps.ts
index 3880654..718427e 100644
--- a/src/shared/settings/Keymaps.ts
+++ b/src/shared/settings/Keymaps.ts
@@ -1,18 +1,17 @@
-import * as operations from '../operations';
+import * as operations from "../operations";
-type OperationJson = {
- type: string
-} | {
- type: string;
- [prop: string]: string | number | boolean;
-};
+type OperationJson =
+ | {
+ type: string;
+ }
+ | {
+ type: string;
+ [prop: string]: string | number | boolean;
+ };
export type KeymapsJSON = { [key: string]: OperationJson };
export default class Keymaps {
- constructor(
- private readonly data: { [key: string]: operations.Operation },
- ) {
- }
+ constructor(private readonly data: { [key: string]: operations.Operation }) {}
static fromJSON(json: KeymapsJSON): Keymaps {
const entries: { [key: string]: operations.Operation } = {};
diff --git a/src/shared/settings/Properties.ts b/src/shared/settings/Properties.ts
index 27fb62e..cf10d61 100644
--- a/src/shared/settings/Properties.ts
+++ b/src/shared/settings/Properties.ts
@@ -1,4 +1,3 @@
-
export type PropertiesJSON = {
hintchars?: string;
smoothscroll?: boolean;
@@ -11,38 +10,40 @@ export type PropertyTypes = {
complete: string;
};
-type PropertyName = 'hintchars' | 'smoothscroll' | 'complete';
+type PropertyName = "hintchars" | "smoothscroll" | "complete";
type PropertyDef = {
name: PropertyName;
description: string;
defaultValue: string | number | boolean;
- type: 'string' | 'number' | 'boolean';
+ type: "string" | "number" | "boolean";
};
const defs: PropertyDef[] = [
{
- name: 'hintchars',
- description: 'hint characters on follow mode',
- defaultValue: 'abcdefghijklmnopqrstuvwxyz',
- type: 'string',
- }, {
- name: 'smoothscroll',
- description: 'smooth scroll',
+ name: "hintchars",
+ description: "hint characters on follow mode",
+ defaultValue: "abcdefghijklmnopqrstuvwxyz",
+ type: "string",
+ },
+ {
+ name: "smoothscroll",
+ description: "smooth scroll",
defaultValue: false,
- type: 'boolean',
- }, {
- name: 'complete',
- description: 'which are completed at the open page',
- defaultValue: 'sbh',
- type: 'string',
- }
+ type: "boolean",
+ },
+ {
+ name: "complete",
+ description: "which are completed at the open page",
+ defaultValue: "sbh",
+ type: "string",
+ },
];
const defaultValues = {
- hintchars: 'abcdefghijklmnopqrstuvwxyz',
+ hintchars: "abcdefghijklmnopqrstuvwxyz",
smoothscroll: false,
- complete: 'sbh',
+ complete: "sbh",
};
export default class Properties {
@@ -72,14 +73,14 @@ export default class Properties {
static types(): PropertyTypes {
return {
- hintchars: 'string',
- smoothscroll: 'boolean',
- complete: 'string',
+ hintchars: "string",
+ smoothscroll: "boolean",
+ complete: "string",
};
}
static def(name: string): PropertyDef | undefined {
- return defs.find(p => p.name === name);
+ return defs.find((p) => p.name === name);
}
static defs(): PropertyDef[] {
diff --git a/src/shared/settings/Search.ts b/src/shared/settings/Search.ts
index 7de03de..b25aa78 100644
--- a/src/shared/settings/Search.ts
+++ b/src/shared/settings/Search.ts
@@ -6,16 +6,12 @@ export type SearchJSON = {
};
export default class Search {
- constructor(
- public defaultEngine: string,
- public engines: Entries,
- ) {
- }
+ constructor(public defaultEngine: string, public engines: Entries) {}
static fromJSON(json: SearchJSON): Search {
for (const [name, url] of Object.entries(json.engines)) {
- if (!(/^[a-zA-Z0-9]+$/).test(name)) {
- throw new TypeError('Search engine\'s name must be [a-zA-Z0-9]+');
+ if (!/^[a-zA-Z0-9]+$/.test(name)) {
+ throw new TypeError("Search engine's name must be [a-zA-Z0-9]+");
}
const matches = url.match(/{}/g);
if (matches === null) {
diff --git a/src/shared/settings/Settings.ts b/src/shared/settings/Settings.ts
index add5389..1bb9249 100644
--- a/src/shared/settings/Settings.ts
+++ b/src/shared/settings/Settings.ts
@@ -1,16 +1,16 @@
-import Ajv from 'ajv';
+import Ajv from "ajv";
-import Keymaps, { KeymapsJSON } from './Keymaps';
-import Search, { SearchJSON } from './Search';
-import Properties, { PropertiesJSON } from './Properties';
-import Blacklist, { BlacklistJSON } from './Blacklist';
-import validate from './validate';
+import Keymaps, { KeymapsJSON } from "./Keymaps";
+import Search, { SearchJSON } from "./Search";
+import Properties, { PropertiesJSON } from "./Properties";
+import Blacklist, { BlacklistJSON } from "./Blacklist";
+import validate from "./validate";
export type SettingsJSON = {
- keymaps?: KeymapsJSON,
- search?: SearchJSON,
- properties?: PropertiesJSON,
- blacklist?: BlacklistJSON,
+ keymaps?: KeymapsJSON;
+ search?: SearchJSON;
+ properties?: PropertiesJSON;
+ blacklist?: BlacklistJSON;
};
export default class Settings {
@@ -42,11 +42,11 @@ export default class Settings {
static fromJSON(json: unknown): Settings {
const valid = validate(json);
if (!valid) {
- const message = (validate as any).errors!!
- .map((err: Ajv.ErrorObject) => {
+ const message = (validate as any)
+ .errors!!.map((err: Ajv.ErrorObject) => {
return `'${err.dataPath}' ${err.message}`;
})
- .join('; ');
+ .join("; ");
throw new TypeError(message);
}
@@ -162,5 +162,6 @@ export const DefaultSettingJSONText = `{
]
}`;
-export const DefaultSetting: Settings =
- Settings.fromJSON(JSON.parse(DefaultSettingJSONText));
+export const DefaultSetting: Settings = Settings.fromJSON(
+ JSON.parse(DefaultSettingJSONText)
+);