From a237443aca3f08756c1d22c754d0a535e7caaf57 Mon Sep 17 00:00:00 2001 From: Kitteh Date: Fri, 7 May 2021 23:08:02 +0100 Subject: [PATCH] Add typing to PageState.ts. --- .eslintrc.json | 61 +++++++++++++++++ .eslintrc.yml | 30 --------- package.json | 5 +- runLinter.sh | 2 +- src/{PageState.js => PageState.ts} | 79 +++++++++++------------ src/api/apiUtils.js | 2 +- src/formatDistance.js | 2 +- src/globalPageState.js | 3 - src/globalPageState.ts | 2 + src/htmlUtils.ts | 8 +-- src/main.js | 2 +- src/pageUtils.js | 2 +- src/pages/Home.js | 2 +- src/pages/KeyValue/KeyValueDelete.js | 2 +- src/pages/KeyValue/KeyValueNew.js | 2 +- src/pages/KeyValue/KeyValueSecret.js | 2 +- src/pages/KeyValue/KeyValueSecretsEdit.js | 2 +- src/pages/KeyValue/KeyValueVersions.js | 2 +- src/pages/KeyValue/KeyValueView.js | 2 +- src/pages/Login.js | 2 +- src/pages/Me.js | 2 +- src/pages/SetLanguage.js | 2 +- src/pages/SetVaultURL.js | 2 +- src/pages/TOTP/NewTOTP.js | 2 +- src/pages/TOTP/TOTPView.js | 2 +- src/pages/Template.js | 2 +- src/pages/Transit/TransitDecrypt.js | 2 +- src/pages/Transit/TransitEncrypt.js | 2 +- src/pages/Transit/TransitView.js | 2 +- src/pages/Transit/TransitViewSecret.js | 2 +- src/pages/Unseal.js | 2 +- src/playground.js | 2 +- src/types/Page.js | 6 +- src/utils.ts | 12 ++-- 34 files changed, 146 insertions(+), 110 deletions(-) create mode 100644 .eslintrc.json delete mode 100644 .eslintrc.yml rename src/{PageState.js => PageState.ts} (59%) delete mode 100644 src/globalPageState.js create mode 100644 src/globalPageState.ts diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..1b583b7 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,61 @@ +{ + "extends": [ + "eslint:recommended", + "plugin:import/errors", + "plugin:import/warnings", + "plugin:@typescript-eslint/recommended" + ], + "plugins": [ + "sort-imports-es6-autofix", + "@typescript-eslint" + ], + "parserOptions": { + "ecmaVersion": 12, + "sourceType": "module", + "experimentalObjectRestSpread": true + }, + "globals": { + "pageContent": "writable", + "module": "writable", + "process": "writable" + }, + "rules": { + "no-unused-vars": [ + "off" + ], + "@typescript-eslint/no-unused-vars": [ + "error", + { + "argsIgnorePattern": "^_" + } + ], + "@typescript-eslint/no-empty-function": [ + "error", + { + "allow": ["arrowFunctions"] + } + ], + "sort-imports-es6-autofix/sort-imports-es6": [ + 2 + ], + "@typescript-eslint/no-explicit-any": [ + 0 + ] + }, + "env": { + "browser": true, + "es6": true + }, + "root": true, + "parser": "@typescript-eslint/parser", + "settings": { + "import/resolver": { + "node": { + "extensions": [ + ".js", + ".ts" + ] + } + } + } +} \ No newline at end of file diff --git a/.eslintrc.yml b/.eslintrc.yml deleted file mode 100644 index 4ba28d4..0000000 --- a/.eslintrc.yml +++ /dev/null @@ -1,30 +0,0 @@ ---- -extends: - - eslint:recommended - - plugin:import/errors - - plugin:import/warnings - -plugins: - - sort-imports-es6-autofix - -parserOptions: - ecmaVersion: 12 - sourceType: module - experimentalObjectRestSpread: true - -globals: - pageContent: writable - module: writable - process: writable - - -rules: - no-unused-vars: - - 2 - - argsIgnorePattern: ^_ - sort-imports-es6-autofix/sort-imports-es6: - - 2 - -env: - browser: true - es6: true diff --git a/package.json b/package.json index e57e3f8..e88d9ea 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,13 @@ { "devDependencies": { "@babel/eslint-parser": "^7.13.14", + "@typescript-eslint/eslint-plugin": "^4.22.1", + "@typescript-eslint/parser": "^4.22.1", "clipboard": "^2.0.8", "codejar": "^3.4.0", "css-loader": "^5.2.1", "date-fns": "^2.21.1", - "eslint": "^7.24.0", + "eslint": "^7.25.0", "eslint-plugin-import": "^2.22.1", "eslint-plugin-sort-imports-es6-autofix": "^0.6.0", "file-saver": "^2.0.5", @@ -18,6 +20,7 @@ "raw-loader": "^4.0.2", "sass-loader": "^11.0.1", "ts-loader": "^9.1.2", + "typescript": "^4.2.4", "uikit": "^3.6.19", "webpack": "^5.32.0", "webpack-cli": "^4.6.0", diff --git a/runLinter.sh b/runLinter.sh index b707134..08c9db9 100755 --- a/runLinter.sh +++ b/runLinter.sh @@ -1,3 +1,3 @@ #!/bin/bash -npx eslint -c .eslintrc.yml src +npx eslint -c .eslintrc.json "$@" --fix src/ --ext .js,.ts \ No newline at end of file diff --git a/src/PageState.js b/src/PageState.ts similarity index 59% rename from src/PageState.js rename to src/PageState.ts index 60e658a..abe9b8e 100644 --- a/src/PageState.js +++ b/src/PageState.ts @@ -4,10 +4,9 @@ import { getKeyByObjectPropertyValue, } from "./utils"; -export class PageState extends Page { +export class PageState { constructor() { - super(); - this._currentPage = new Page(); + // Do Nothing } // NOTE: When a item in the page state isn't a string (e.g it is a array or object), @@ -19,40 +18,40 @@ export class PageState extends Page { // by using a bunch of functions and modifying localStorage in order to remove some of // the clunkyness of this approach, but for now, this works. - get apiURL() { - let apiurl = localStorage.getItem('apiURL') || ""; + get apiURL(): string | null { + const apiurl = localStorage.getItem('apiURL') || ""; return apiurl.length > 0 ? apiurl : null; } - set apiURL(value) { + set apiURL(value: string) { localStorage.setItem('apiURL', value); } - - get token() { - let tok = localStorage.getItem('token') || ""; + + get token(): string | null { + const tok = localStorage.getItem('token') || ""; return tok.length > 0 ? tok : null; } - set token(value) { + set token(value: string) { localStorage.setItem('token', value); } - get pageDirection() { + get pageDirection(): string { return localStorage.getItem('pageDirection') || "ltr"; } - set pageDirection(value) { + set pageDirection(value: string) { localStorage.setItem('pageDirection', value); } - get language() { + get language(): string { return localStorage.getItem('language') || ""; } - set language(value) { + set language(value: string) { localStorage.setItem('language', value); } - get currentBaseMount() { + get currentBaseMount(): string { return localStorage.getItem('currentBaseMount') || ""; } - set currentBaseMount(value) { + set currentBaseMount(value: string) { localStorage.setItem('currentBaseMount', value); } @@ -60,59 +59,59 @@ export class PageState extends Page { // Since this is a array we can't act directly on it so we need // functions to do the same modifications. // See the note at the start o - popCurrentSecretPath() { - let secPath = this.currentSecretPath; + popCurrentSecretPath(): void { + const secPath = this.currentSecretPath; secPath.pop(); this.currentSecretPath = secPath; } - pushCurrentSecretPath(...args) { - let secPath = this.currentSecretPath; + pushCurrentSecretPath(...args: string[]): void { + const secPath = this.currentSecretPath; secPath.push(...args); this.currentSecretPath = secPath; } - get currentSecretPath() { + + get currentSecretPath(): string[] { return JSON.parse(localStorage.getItem('currentSecretPath') || "[]"); } - set currentSecretPath(value) { + set currentSecretPath(value: string[]) { localStorage.setItem('currentSecretPath', JSON.stringify(value)); } - get currentSecretVersion() { - let result = localStorage.getItem('currentSecretVersion') - + get currentSecretVersion(): string | null { + const result = localStorage.getItem('currentSecretVersion') return result != "null" ? result || null : null; } - set currentSecretVersion(value) { + set currentSecretVersion(value: string) { localStorage.setItem('currentSecretVersion', String(value)); } - get currentSecret() { + get currentSecret(): string { return localStorage.getItem('currentSecret') || ""; } - set currentSecret(value) { + set currentSecret(value: string) { localStorage.setItem('currentSecret', value); } - get currentMountType() { + get currentMountType(): string { return localStorage.getItem('currentMountType') || ""; } - set currentMountType(value) { + set currentMountType(value: string) { localStorage.setItem('currentMountType', value); } - get currentPage() { - let curPage = localStorage.getItem('currentPage') || "HOME"; - return allPages[curPage]; - } - get currentPageString() { - let key = getKeyByObjectPropertyValue(allPages, this.currentPage); + get currentPageString(): string { + const key = getKeyByObjectPropertyValue(allPages, this.currentPage); return key; } - set currentPage(value) { - if (typeof page == 'object') { - let key = getKeyByObjectPropertyValue(allPages, value); + get currentPage(): Page | string { + const curPage = localStorage.getItem('currentPage') || "HOME"; + return (allPages as any)[curPage]; + } + set currentPage(value: Page | string) { + if (typeof value == 'object') { + const key = getKeyByObjectPropertyValue(allPages, value); localStorage.setItem('currentPage', key); } else { - localStorage.setItem('currentPage', value); + localStorage.setItem('currentPage', (value as string)); } } } \ No newline at end of file diff --git a/src/api/apiUtils.js b/src/api/apiUtils.js index 96a934e..87f185c 100644 --- a/src/api/apiUtils.js +++ b/src/api/apiUtils.js @@ -1,4 +1,4 @@ -import { pageState } from "../globalPageState.js"; +import { pageState } from "../globalPageState.ts"; export function getHeaders() { return { diff --git a/src/formatDistance.js b/src/formatDistance.js index 6d8bee9..8f888a2 100644 --- a/src/formatDistance.js +++ b/src/formatDistance.js @@ -1,6 +1,6 @@ import { de, enGB, fr, it, nl, ru } from 'date-fns/locale' import { formatDistance as formatDistanceReal} from 'date-fns'; -import { pageState } from "./globalPageState.js"; +import { pageState } from "./globalPageState.ts"; function getLocale() { return { diff --git a/src/globalPageState.js b/src/globalPageState.js deleted file mode 100644 index 24fb850..0000000 --- a/src/globalPageState.js +++ /dev/null @@ -1,3 +0,0 @@ -import { PageState } from "./PageState.js"; - -export const pageState = new PageState(); \ No newline at end of file diff --git a/src/globalPageState.ts b/src/globalPageState.ts new file mode 100644 index 0000000..dd60325 --- /dev/null +++ b/src/globalPageState.ts @@ -0,0 +1,2 @@ +import { PageState } from "./PageState"; +export const pageState = new PageState(); \ No newline at end of file diff --git a/src/htmlUtils.ts b/src/htmlUtils.ts index 16bc55c..28dfc68 100644 --- a/src/htmlUtils.ts +++ b/src/htmlUtils.ts @@ -30,7 +30,7 @@ const optionsFunctions: optionsFunctionsObject = { } interface ElementInfo { - condition?: Boolean; + condition?: boolean; tag: string; class?: string | string[]; id?: string; @@ -45,9 +45,9 @@ interface ElementInfo { export function makeElement(elementInfo: ElementInfo) { if ("condition" in elementInfo) { if (!elementInfo.condition) { return null; } } - let element = document.createElement(elementInfo.tag); + const element = document.createElement(elementInfo.tag); - for (let key of Object.getOwnPropertyNames(elementInfo)) { + for (const key of Object.getOwnPropertyNames(elementInfo)) { if (getObjectKeys(optionsFunctions).includes(key)) { (optionsFunctions as any)[key](element, elementInfo[key]); } @@ -57,7 +57,7 @@ export function makeElement(elementInfo: ElementInfo) { } export function setElementAttributes(element: Element, attributes: {[propName: string]: any}) { - for (let key of Object.getOwnPropertyNames(attributes)) { + for (const key of Object.getOwnPropertyNames(attributes)) { element.setAttribute(key, attributes[key]); } } \ No newline at end of file diff --git a/src/main.js b/src/main.js index 6d0696b..f4a3713 100644 --- a/src/main.js +++ b/src/main.js @@ -19,7 +19,7 @@ import { } from "./pageUtils.js"; import { getSealStatus } from "./api/getSealStatus"; import { makeElement } from "./htmlUtils"; -import { pageState } from "./globalPageState.js"; +import { pageState } from "./globalPageState.ts"; // Translations import { formatDistance } from './formatDistance.js'; diff --git a/src/pageUtils.js b/src/pageUtils.js index 55118f0..e3d3048 100644 --- a/src/pageUtils.js +++ b/src/pageUtils.js @@ -1,7 +1,7 @@ import { getSealStatus } from "./api/getSealStatus"; import { lookupSelf } from "./api/lookupSelf"; import { makeElement } from "./htmlUtils"; -import { pageState } from "./globalPageState.js"; +import { pageState } from "./globalPageState.ts"; import UIkit from 'uikit/dist/js/uikit.min.js'; import i18next from 'i18next'; diff --git a/src/pages/Home.js b/src/pages/Home.js index ccc00c6..6d1c673 100644 --- a/src/pages/Home.js +++ b/src/pages/Home.js @@ -3,7 +3,7 @@ import { changePage, prePageChecks, setErrorText } from "../pageUtils.js"; import { getMounts } from "../api/getMounts"; import { lookupSelf } from "../api/lookupSelf"; import { makeElement } from "../htmlUtils"; -import { pageState } from "../globalPageState.js"; +import { pageState } from "../globalPageState.ts"; import { sortedObjectMap } from "../utils"; import i18next from 'i18next'; diff --git a/src/pages/KeyValue/KeyValueDelete.js b/src/pages/KeyValue/KeyValueDelete.js index 863ff2e..b0039ef 100644 --- a/src/pages/KeyValue/KeyValueDelete.js +++ b/src/pages/KeyValue/KeyValueDelete.js @@ -2,7 +2,7 @@ import { Page } from "../../types/Page.js"; import { changePage, setPageContent, setTitleElement } from "../../pageUtils.js"; import { deleteSecret } from "../../api/deleteSecret"; import { makeElement } from "../../htmlUtils"; -import { pageState } from "../../globalPageState.js"; +import { pageState } from "../../globalPageState.ts"; import i18next from 'i18next'; export class KeyValueDeletePage extends Page { diff --git a/src/pages/KeyValue/KeyValueNew.js b/src/pages/KeyValue/KeyValueNew.js index 27f2af0..4af26d7 100644 --- a/src/pages/KeyValue/KeyValueNew.js +++ b/src/pages/KeyValue/KeyValueNew.js @@ -2,7 +2,7 @@ import { Page } from "../../types/Page.js"; import { changePage, setErrorText, setPageContent, setTitleElement } from "../../pageUtils.js"; import { createOrUpdateSecret } from "../../api/createOrUpdateSecret"; import { makeElement } from "../../htmlUtils"; -import { pageState } from "../../globalPageState.js"; +import { pageState } from "../../globalPageState.ts"; import i18next from 'i18next'; export class KeyValueNewPage extends Page { diff --git a/src/pages/KeyValue/KeyValueSecret.js b/src/pages/KeyValue/KeyValueSecret.js index 6580b91..bc69f85 100644 --- a/src/pages/KeyValue/KeyValueSecret.js +++ b/src/pages/KeyValue/KeyValueSecret.js @@ -4,7 +4,7 @@ import { changePage, setPageContent, setTitleElement } from "../../pageUtils.js" import { getCapabilities } from "../../api/getCapabilities"; import { getSecret } from "../../api/getSecret"; import { makeElement } from "../../htmlUtils"; -import { pageState } from "../../globalPageState.js"; +import { pageState } from "../../globalPageState.ts"; import { sortedObjectMap } from "../../utils"; import { undeleteSecret } from "../../api/undeleteSecret"; import Prism from "prismjs"; diff --git a/src/pages/KeyValue/KeyValueSecretsEdit.js b/src/pages/KeyValue/KeyValueSecretsEdit.js index f53b0d7..adb195f 100644 --- a/src/pages/KeyValue/KeyValueSecretsEdit.js +++ b/src/pages/KeyValue/KeyValueSecretsEdit.js @@ -4,7 +4,7 @@ import { changePage, setErrorText, setPageContent, setTitleElement } from "../.. import { createOrUpdateSecret } from "../../api/createOrUpdateSecret.js"; import { getSecret } from "../../api/getSecret.js"; import { makeElement } from "../../htmlUtils"; -import { pageState } from "../../globalPageState.js"; +import { pageState } from "../../globalPageState.ts"; import { verifyJSONString } from "../../utils"; import i18next from 'i18next'; diff --git a/src/pages/KeyValue/KeyValueVersions.js b/src/pages/KeyValue/KeyValueVersions.js index d09a36c..97a566e 100644 --- a/src/pages/KeyValue/KeyValueVersions.js +++ b/src/pages/KeyValue/KeyValueVersions.js @@ -3,7 +3,7 @@ import { changePage, setPageContent, setTitleElement } from "../../pageUtils.js" import { getSecretMetadata } from "../../api/getSecretMetadata.js"; import { makeElement } from "../../htmlUtils"; import { objectToMap } from "../../utils"; -import { pageState } from "../../globalPageState.js"; +import { pageState } from "../../globalPageState.ts"; import i18next from 'i18next'; diff --git a/src/pages/KeyValue/KeyValueView.js b/src/pages/KeyValue/KeyValueView.js index ba7def9..fe32ed2 100644 --- a/src/pages/KeyValue/KeyValueView.js +++ b/src/pages/KeyValue/KeyValueView.js @@ -3,7 +3,7 @@ import { Page } from "../../types/Page.js"; import { changePage, setErrorText, setTitleElement } from "../../pageUtils.js"; import { getSecrets } from "../../api/getSecrets"; import { makeElement } from "../../htmlUtils"; -import { pageState } from "../../globalPageState.js"; +import { pageState } from "../../globalPageState.ts"; import i18next from 'i18next'; diff --git a/src/pages/Login.js b/src/pages/Login.js index 03c2ed6..b25da17 100644 --- a/src/pages/Login.js +++ b/src/pages/Login.js @@ -4,7 +4,7 @@ import { Page } from "../types/Page.js"; import { changePage, setErrorText, setPageContent } from "../pageUtils.js"; import { lookupSelf } from "../api/lookupSelf"; import { makeElement } from "../htmlUtils"; -import { pageState } from "../globalPageState.js"; +import { pageState } from "../globalPageState.ts"; import { usernameLogin } from "../api/usernameLogin"; import i18next from 'i18next'; diff --git a/src/pages/Me.js b/src/pages/Me.js index 3cd7ff6..6a69f6f 100644 --- a/src/pages/Me.js +++ b/src/pages/Me.js @@ -2,7 +2,7 @@ import { Page } from "../types/Page.js"; import { addClipboardNotifications, changePage, prePageChecks, setErrorText, setPageContent } from "../pageUtils.js"; import { getCapabilitiesPath } from "../api/getCapabilities.js"; import { makeElement } from "../htmlUtils"; -import { pageState } from "../globalPageState.js"; +import { pageState } from "../globalPageState.ts"; import { renewSelf } from "../api/renewSelf.js"; import { sealVault } from "../api/sealVault.js"; import ClipboardJS from "clipboard"; diff --git a/src/pages/SetLanguage.js b/src/pages/SetLanguage.js index f07b428..99235f6 100644 --- a/src/pages/SetLanguage.js +++ b/src/pages/SetLanguage.js @@ -2,7 +2,7 @@ import { Margin } from "../elements/Margin.js"; import { Page } from "../types/Page.js"; import { changePage, setPageContent } from "../pageUtils.js"; import { makeElement } from "../htmlUtils"; -import { pageState } from "../globalPageState.js"; +import { pageState } from "../globalPageState.ts"; import i18next from 'i18next'; import translations from "../translations/index.mjs"; diff --git a/src/pages/SetVaultURL.js b/src/pages/SetVaultURL.js index cafb78c..849d750 100644 --- a/src/pages/SetVaultURL.js +++ b/src/pages/SetVaultURL.js @@ -1,7 +1,7 @@ import { Page } from "../types/Page.js"; import { changePage, setPageContent } from "../pageUtils.js"; import { makeElement } from "../htmlUtils"; -import { pageState } from "../globalPageState.js"; +import { pageState } from "../globalPageState.ts"; export class SetVaultURLPage extends Page { constructor() { diff --git a/src/pages/TOTP/NewTOTP.js b/src/pages/TOTP/NewTOTP.js index 23fc78f..e1fa965 100644 --- a/src/pages/TOTP/NewTOTP.js +++ b/src/pages/TOTP/NewTOTP.js @@ -4,7 +4,7 @@ import { Page } from "../../types/Page.js"; import { addNewTOTP } from "../../api/addNewTOTP"; import { changePage, setErrorText, setPageContent, setTitleElement } from "../../pageUtils.js"; import { makeElement } from "../../htmlUtils"; -import { pageState } from "../../globalPageState.js"; +import { pageState } from "../../globalPageState.ts"; import i18next from 'i18next'; diff --git a/src/pages/TOTP/TOTPView.js b/src/pages/TOTP/TOTPView.js index 49e9934..3f40ebc 100644 --- a/src/pages/TOTP/TOTPView.js +++ b/src/pages/TOTP/TOTPView.js @@ -6,7 +6,7 @@ import { getTOTPCode } from "../../api/getTOTPCode"; import { getTOTPKeys } from "../../api/getTOTPKeys"; import { makeElement } from "../../htmlUtils"; import { objectToMap } from "../../utils"; -import { pageState } from "../../globalPageState.js"; +import { pageState } from "../../globalPageState.ts"; import i18next from 'i18next'; export class TOTPViewPage extends Page { diff --git a/src/pages/Template.js b/src/pages/Template.js index 71eb1bb..f85bfba 100644 --- a/src/pages/Template.js +++ b/src/pages/Template.js @@ -1,7 +1,7 @@ import { Page } from "../types/Page.js"; import { changePage, setPageContent, setTitleElement } from "../pageUtils.js"; import { makeElement } from "../htmlUtils"; -import { pageState } from "../globalPageState.js"; +import { pageState } from "../globalPageState.ts"; export class TemplatePage extends Page { constructor() { diff --git a/src/pages/Transit/TransitDecrypt.js b/src/pages/Transit/TransitDecrypt.js index 009c5ed..8ffc1c5 100644 --- a/src/pages/Transit/TransitDecrypt.js +++ b/src/pages/Transit/TransitDecrypt.js @@ -3,7 +3,7 @@ import { Margin } from "../../elements/Margin.js"; import { Page } from "../../types/Page.js"; import { changePage, setErrorText, setPageContent, setTitleElement } from "../../pageUtils.js"; import { makeElement } from "../../htmlUtils"; -import { pageState } from "../../globalPageState.js"; +import { pageState } from "../../globalPageState.ts"; import { transitDecrypt } from "../../api/transitDecrypt"; import UIkit from 'uikit/dist/js/uikit.min.js'; import i18next from "i18next"; diff --git a/src/pages/Transit/TransitEncrypt.js b/src/pages/Transit/TransitEncrypt.js index 61ab6d9..6eff514 100644 --- a/src/pages/Transit/TransitEncrypt.js +++ b/src/pages/Transit/TransitEncrypt.js @@ -3,7 +3,7 @@ import { Margin } from "../../elements/Margin.js"; import { Page } from "../../types/Page.js"; import { changePage, setErrorText, setPageContent, setTitleElement } from "../../pageUtils.js"; import { makeElement } from "../../htmlUtils"; -import { pageState } from "../../globalPageState.js"; +import { pageState } from "../../globalPageState.ts"; import { transitEncrypt } from "../../api/transitEncrypt"; import UIkit from 'uikit/dist/js/uikit.min.js'; import i18next from "i18next"; diff --git a/src/pages/Transit/TransitView.js b/src/pages/Transit/TransitView.js index e476477..8f19ae9 100644 --- a/src/pages/Transit/TransitView.js +++ b/src/pages/Transit/TransitView.js @@ -3,7 +3,7 @@ import { Page } from "../../types/Page.js"; import { changePage, setErrorText, setTitleElement } from "../../pageUtils.js"; import { getTransitKeys } from "../../api/getTransitKeys"; import { makeElement } from "../../htmlUtils"; -import { pageState } from "../../globalPageState.js"; +import { pageState } from "../../globalPageState.ts"; import i18next from 'i18next'; export class TransitViewPage extends Page { diff --git a/src/pages/Transit/TransitViewSecret.js b/src/pages/Transit/TransitViewSecret.js index ac355b3..163c5c6 100644 --- a/src/pages/Transit/TransitViewSecret.js +++ b/src/pages/Transit/TransitViewSecret.js @@ -1,7 +1,7 @@ import { Page } from "../../types/Page.js"; import { changePage, setPageContent, setTitleElement } from "../../pageUtils.js"; import { makeElement } from "../../htmlUtils"; -import { pageState } from "../../globalPageState.js"; +import { pageState } from "../../globalPageState.ts"; import i18next from 'i18next'; export class TransitViewSecretPage extends Page { diff --git a/src/pages/Unseal.js b/src/pages/Unseal.js index 68f2ca0..89e95a4 100644 --- a/src/pages/Unseal.js +++ b/src/pages/Unseal.js @@ -27,7 +27,7 @@ export class UnsealPage extends Page { try { this.qrScanner.deinit(); } catch (_) { - ()=>{}; + // Do Nothing } } diff --git a/src/playground.js b/src/playground.js index d9ac79e..ed8ab01 100644 --- a/src/playground.js +++ b/src/playground.js @@ -1,4 +1,4 @@ -import { pageState } from "./globalPageState.js"; +import { pageState } from "./globalPageState.ts"; import i18next from 'i18next'; // Playground is a way to debug and test things. diff --git a/src/types/Page.js b/src/types/Page.js index 9030029..1b3ad62 100644 --- a/src/types/Page.js +++ b/src/types/Page.js @@ -1,8 +1,11 @@ import { changePage } from "../pageUtils.js"; export class Page { - constructor() { } + constructor() { + // Do Nothing + } render() { + // Do Nothing } get name() { return "Page"; @@ -14,5 +17,6 @@ export class Page { changePage("HOME"); } cleanup() { + // Do Nothing } } \ No newline at end of file diff --git a/src/utils.ts b/src/utils.ts index 9a1c31e..0849011 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -2,18 +2,18 @@ export function removeDoubleSlash(str: string): string { return str.replace(/\/\/+/g, "/"); } -export const getObjectKeys = (obj: Object) => Object.getOwnPropertyNames(obj); -export const objectToMap = (obj: Object) => new Map(Object.entries(obj)); -export const sortedObjectMap = (obj: Object) => new Map(Object.entries(obj).sort()); +export const getObjectKeys = (obj: Record) => Object.getOwnPropertyNames(obj); +export const objectToMap = (obj: Record) => new Map(Object.entries(obj)); +export const sortedObjectMap = (obj: Record) => new Map(Object.entries(obj).sort()); -export function getKeyByObjectPropertyValue(map: object, searchValue: any) { - for (let key of getObjectKeys(map)) { +export function getKeyByObjectPropertyValue(map: Record, searchValue: any) { + for (const key of getObjectKeys(map)) { if ((map as any)[key] === searchValue) return key; } } -export function verifyJSONString(str: string): Boolean { +export function verifyJSONString(str: string): boolean { try { JSON.parse(str); } catch (e) {