aboutsummaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/SettingData.ts34
-rw-r--r--src/shared/operations.ts2
-rw-r--r--src/shared/settings/Blacklist.ts4
-rw-r--r--src/shared/settings/Key.ts4
-rw-r--r--src/shared/settings/Keymaps.ts4
-rw-r--r--src/shared/settings/Search.ts4
-rw-r--r--src/shared/settings/Settings.ts8
-rw-r--r--src/shared/urls.ts10
-rw-r--r--src/shared/utils/dom.ts26
9 files changed, 48 insertions, 48 deletions
diff --git a/src/shared/SettingData.ts b/src/shared/SettingData.ts
index 532570e..5ad360e 100644
--- a/src/shared/SettingData.ts
+++ b/src/shared/SettingData.ts
@@ -13,14 +13,14 @@ export class FormKeymaps {
}
toKeymaps(): Keymaps {
- let keymaps: { [key: string]: operations.Operation } = {};
- for (let name of Object.keys(this.data)) {
- let [type, argStr] = name.split('?');
+ const keymaps: { [key: string]: operations.Operation } = {};
+ for (const name of Object.keys(this.data)) {
+ const [type, argStr] = name.split('?');
let args = {};
if (argStr) {
args = JSON.parse(argStr);
}
- let key = this.data[name];
+ const key = this.data[name];
keymaps[key] = operations.valueOf({ type, ...args });
}
return Keymaps.fromJSON(keymaps);
@@ -31,7 +31,7 @@ export class FormKeymaps {
}
buildWithOverride(op: string, keys: string): FormKeymaps {
- let newData = {
+ const newData = {
...this.data,
[op]: keys,
};
@@ -39,19 +39,19 @@ export class FormKeymaps {
}
static fromJSON(o: ReturnType<FormKeymaps['toJSON']>): FormKeymaps {
- let data: {[op: string]: string} = {};
- for (let op of Object.keys(o)) {
+ const data: {[op: string]: string} = {};
+ for (const op of Object.keys(o)) {
data[op] = o[op] as string;
}
return new FormKeymaps(data);
}
static fromKeymaps(keymaps: Keymaps): FormKeymaps {
- let json = keymaps.toJSON();
- let data: {[op: string]: string} = {};
- for (let key of Object.keys(json)) {
- let op = json[key];
- let args = { ...op };
+ const json = keymaps.toJSON();
+ const data: {[op: string]: string} = {};
+ for (const key of Object.keys(json)) {
+ const op = json[key];
+ const args = { ...op };
delete args.type;
let name = op.type;
@@ -75,8 +75,8 @@ export class FormSearch {
}
toSearchSettings(): Search {
- let engines: { [name: string]: string } = {};
- for (let entry of this.engines) {
+ const engines: { [name: string]: string } = {};
+ for (const entry of this.engines) {
engines[entry[0]] = entry[1];
}
return new Search(this.default, engines);
@@ -103,7 +103,7 @@ export class FormSearch {
}
static fromSearch(search: Search): FormSearch {
- let engines = Object.entries(search.engines).reduce(
+ const engines = Object.entries(search.engines).reduce(
(o: string[][], [name, url]) => {
return o.concat([[name, url]]);
}, []);
@@ -130,7 +130,7 @@ export class JSONTextSettings {
}
static fromSettings(data: Settings): JSONTextSettings {
- let json = {
+ const json = {
keymaps: data.keymaps.toJSON(),
search: data.search,
properties: data.properties,
@@ -221,7 +221,7 @@ export class FormSettings {
}
static fromJSON(o: ReturnType<FormSettings['toJSON']>): FormSettings {
- for (let name of ['keymaps', 'search', 'properties', 'blacklist']) {
+ for (const name of ['keymaps', 'search', 'properties', 'blacklist']) {
if (!Object.prototype.hasOwnProperty.call(o, name)) {
throw new Error(`"${name}" field not set`);
}
diff --git a/src/shared/operations.ts b/src/shared/operations.ts
index 67c5ca8..beca7b9 100644
--- a/src/shared/operations.ts
+++ b/src/shared/operations.ts
@@ -376,7 +376,7 @@ const assertOptionalBoolean = (obj: any, name: string) => {
const assertOptionalString = (obj: any, name: string, values?: string[]) => {
if (Object.prototype.hasOwnProperty.call(obj, name)) {
- let value = obj[name];
+ const value = obj[name];
if (typeof value !== 'string') {
throw new TypeError(
`Not a string parameter: '${name}' (${typeof value})`,
diff --git a/src/shared/settings/Blacklist.ts b/src/shared/settings/Blacklist.ts
index 1903a78..6e6b51c 100644
--- a/src/shared/settings/Blacklist.ts
+++ b/src/shared/settings/Blacklist.ts
@@ -8,7 +8,7 @@ export type BlacklistItemJSON = string | {
export type BlacklistJSON = BlacklistItemJSON[];
const regexFromWildcard = (pattern: string): RegExp => {
- let regexStr = '^' + pattern.replace(/\*/g, '.*') + '$';
+ const regexStr = '^' + pattern.replace(/\*/g, '.*') + '$';
return new RegExp(regexStr);
};
@@ -72,7 +72,7 @@ export default class Blacklist {
}
static fromJSON(json: BlacklistJSON): Blacklist {
- let items = json.map(o => BlacklistItem.fromJSON(o));
+ const items = json.map(o => BlacklistItem.fromJSON(o));
return new Blacklist(items);
}
diff --git a/src/shared/settings/Key.ts b/src/shared/settings/Key.ts
index 3a3eb3b..cfe1e7e 100644
--- a/src/shared/settings/Key.ts
+++ b/src/shared/settings/Key.ts
@@ -33,8 +33,8 @@ export default class Key {
static fromMapKey(str: string): Key {
if (str.startsWith('<') && str.endsWith('>')) {
- let inner = str.slice(1, -1);
- let shift = inner.includes('S-');
+ const inner = str.slice(1, -1);
+ const shift = inner.includes('S-');
let base = inner.slice(inner.lastIndexOf('-') + 1);
if (shift && base.length === 1) {
base = base.toUpperCase();
diff --git a/src/shared/settings/Keymaps.ts b/src/shared/settings/Keymaps.ts
index 5870313..3880654 100644
--- a/src/shared/settings/Keymaps.ts
+++ b/src/shared/settings/Keymaps.ts
@@ -15,8 +15,8 @@ export default class Keymaps {
}
static fromJSON(json: KeymapsJSON): Keymaps {
- let entries: { [key: string]: operations.Operation } = {};
- for (let key of Object.keys(json)) {
+ const entries: { [key: string]: operations.Operation } = {};
+ for (const key of Object.keys(json)) {
entries[key] = operations.valueOf(json[key]);
}
return new Keymaps(entries);
diff --git a/src/shared/settings/Search.ts b/src/shared/settings/Search.ts
index 7d7e555..7de03de 100644
--- a/src/shared/settings/Search.ts
+++ b/src/shared/settings/Search.ts
@@ -13,11 +13,11 @@ export default class Search {
}
static fromJSON(json: SearchJSON): Search {
- for (let [name, url] of Object.entries(json.engines)) {
+ 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]+');
}
- let matches = url.match(/{}/g);
+ const matches = url.match(/{}/g);
if (matches === null) {
throw new TypeError(`No {}-placeholders in URL of "${name}"`);
} else if (matches.length > 1) {
diff --git a/src/shared/settings/Settings.ts b/src/shared/settings/Settings.ts
index 97dda7f..add5389 100644
--- a/src/shared/settings/Settings.ts
+++ b/src/shared/settings/Settings.ts
@@ -40,9 +40,9 @@ export default class Settings {
}
static fromJSON(json: unknown): Settings {
- let valid = validate(json);
+ const valid = validate(json);
if (!valid) {
- let message = (validate as any).errors!!
+ const message = (validate as any).errors!!
.map((err: Ajv.ErrorObject) => {
return `'${err.dataPath}' ${err.message}`;
})
@@ -50,8 +50,8 @@ export default class Settings {
throw new TypeError(message);
}
- let obj = json as SettingsJSON;
- let settings = { ...DefaultSetting };
+ const obj = json as SettingsJSON;
+ const settings = { ...DefaultSetting };
if (obj.keymaps) {
settings.keymaps = Keymaps.fromJSON(obj.keymaps);
}
diff --git a/src/shared/urls.ts b/src/shared/urls.ts
index 9c76b97..bac929e 100644
--- a/src/shared/urls.ts
+++ b/src/shared/urls.ts
@@ -12,7 +12,7 @@ const isLocalhost = (url: string): boolean => {
return true;
}
- let [host, port] = url.split(':', 2);
+ const [host, port] = url.split(':', 2);
return host === 'localhost' && !isNaN(Number(port));
};
@@ -22,7 +22,7 @@ const isMissingHttp = (keywords: string): boolean => {
}
try {
- let u = new URL('http://' + keywords);
+ const u = new URL('http://' + keywords);
return isLocalhost(u.host);
} catch (e) {
// fallthrough
@@ -32,7 +32,7 @@ const isMissingHttp = (keywords: string): boolean => {
const searchUrl = (keywords: string, search: Search): string => {
try {
- let u = new URL(keywords);
+ const u = new URL(keywords);
if (SUPPORTED_PROTOCOLS.includes(u.protocol.toLowerCase())) {
return u.href;
}
@@ -47,7 +47,7 @@ const searchUrl = (keywords: string, search: Search): string => {
let template = search.engines[search.defaultEngine];
let query = keywords;
- let first = trimStart(keywords).split(' ')[0];
+ const first = trimStart(keywords).split(' ')[0];
if (Object.keys(search.engines).includes(first)) {
template = search.engines[first];
query = trimStart(trimStart(keywords).slice(first.length));
@@ -57,7 +57,7 @@ const searchUrl = (keywords: string, search: Search): string => {
const normalizeUrl = (url: string): string => {
try {
- let u = new URL(url);
+ const u = new URL(url);
if (SUPPORTED_PROTOCOLS.includes(u.protocol.toLowerCase())) {
return u.href;
}
diff --git a/src/shared/utils/dom.ts b/src/shared/utils/dom.ts
index c1f2190..a6186cb 100644
--- a/src/shared/utils/dom.ts
+++ b/src/shared/utils/dom.ts
@@ -1,5 +1,5 @@
const isContentEditable = (element: Element): boolean => {
- let value = element.getAttribute('contenteditable');
+ const value = element.getAttribute('contenteditable');
if (value === null) {
return false;
}
@@ -14,12 +14,12 @@ interface Rect {
}
const rectangleCoordsRect = (coords: string): Rect => {
- let [left, top, right, bottom] = coords.split(',').map(n => Number(n));
+ const [left, top, right, bottom] = coords.split(',').map(n => Number(n));
return { left, top, right, bottom };
};
const circleCoordsRect = (coords: string): Rect => {
- let [x, y, r] = coords.split(',').map(n => Number(n));
+ const [x, y, r] = coords.split(',').map(n => Number(n));
return {
left: x - r,
top: y - r,
@@ -29,14 +29,14 @@ const circleCoordsRect = (coords: string): Rect => {
};
const polygonCoordsRect = (coords: string): Rect => {
- let params = coords.split(',');
+ const params = coords.split(',');
let minx = Number(params[0]),
maxx = Number(params[0]),
miny = Number(params[1]),
maxy = Number(params[1]);
- let len = Math.floor(params.length / 2);
+ const len = Math.floor(params.length / 2);
for (let i = 2; i < len; i += 2) {
- let x = Number(params[i]),
+ const x = Number(params[i]),
y = Number(params[i + 1]);
if (x < minx) {
minx = x;
@@ -59,15 +59,15 @@ const viewportRect = (e: Element): Rect => {
return e.getBoundingClientRect();
}
- let mapElement = e.parentNode as HTMLMapElement;
- let imgElement = document.querySelector(
+ const mapElement = e.parentNode as HTMLMapElement;
+ const imgElement = document.querySelector(
`img[usemap="#${mapElement.name}"]`
) as HTMLImageElement;
- let {
+ const {
left: mapLeft,
top: mapTop
} = imgElement.getBoundingClientRect();
- let coords = e.getAttribute('coords');
+ const coords = e.getAttribute('coords');
if (!coords) {
return e.getBoundingClientRect();
}
@@ -96,8 +96,8 @@ const viewportRect = (e: Element): Rect => {
};
const isVisible = (element: Element): boolean => {
- let rect = element.getBoundingClientRect();
- let style = window.getComputedStyle(element);
+ const rect = element.getBoundingClientRect();
+ const style = window.getComputedStyle(element);
if (style.overflow !== 'visible' && (rect.width === 0 || rect.height === 0)) {
return false;
@@ -113,7 +113,7 @@ const isVisible = (element: Element): boolean => {
return false;
}
- let { display, visibility } = window.getComputedStyle(element);
+ const { display, visibility } = window.getComputedStyle(element);
if (display === 'none' || visibility === 'hidden') {
return false;
}