summaryrefslogtreecommitdiff
path: root/src/misc
diff options
context:
space:
mode:
authorMatain <[email protected]>2022-06-12 23:38:31 +0800
committerMatain <[email protected]>2022-06-12 23:38:31 +0800
commite4e921e0b93f74bf126ca80cbb83f5e912f73a88 (patch)
treeca586f4753f5266ab67051235c7a79370fca1333 /src/misc
parenta825925cc97d95762634d234ef06be1627a21fb1 (diff)
parentea5d7cf003eeef30cb7bbe789c6ba7f314bf1ce4 (diff)
Merge branch 'haishanh-master'
Diffstat (limited to 'src/misc')
-rw-r--r--src/misc/chart.ts4
-rw-r--r--src/misc/errors.ts7
-rw-r--r--src/misc/i18n.ts5
-rw-r--r--src/misc/motion.ts4
-rw-r--r--src/misc/request-helper.ts6
-rw-r--r--src/misc/shallowEqual.ts7
-rw-r--r--src/misc/utils.ts10
7 files changed, 17 insertions, 26 deletions
diff --git a/src/misc/chart.ts b/src/misc/chart.ts
index c62fa06..56e05a2 100644
--- a/src/misc/chart.ts
+++ b/src/misc/chart.ts
@@ -1,4 +1,4 @@
-import { createAsset } from "use-asset"
+import { createAsset } from 'use-asset';
import prettyBytes from './pretty-bytes';
export const chartJSResource = createAsset(() => {
@@ -11,7 +11,7 @@ export const commonChartOptions: import('chart.js').ChartOptions<'line'> = {
responsive: true,
maintainAspectRatio: true,
plugins: {
- legend: { labels: { boxWidth: 20 } }
+ legend: { labels: { boxWidth: 20 } },
},
scales: {
x: { display: false, type: 'category' },
diff --git a/src/misc/errors.ts b/src/misc/errors.ts
index 1bc369a..ec12b6a 100644
--- a/src/misc/errors.ts
+++ b/src/misc/errors.ts
@@ -1,5 +1,12 @@
export const DOES_NOT_SUPPORT_FETCH = 0;
+export class YacdError extends Error {
+ constructor(public message: string, public code?: string | number) {
+ super(message);
+ Error.captureStackTrace(this, this.constructor);
+ }
+}
+
export const errors = {
[DOES_NOT_SUPPORT_FETCH]: {
message: 'Browser not supported!',
diff --git a/src/misc/i18n.ts b/src/misc/i18n.ts
index cf1a4f2..eecd72a 100644
--- a/src/misc/i18n.ts
+++ b/src/misc/i18n.ts
@@ -8,10 +8,7 @@ const allLocales = {
en: import('src/i18n/en'),
};
-type BackendRequestCallback = (
- err: null,
- result: { status: number; data: any }
-) => void;
+type BackendRequestCallback = (err: null, result: { status: number; data: any }) => void;
i18next
.use(HttpBackend)
diff --git a/src/misc/motion.ts b/src/misc/motion.ts
index 5f2fe50..7fac864 100644
--- a/src/misc/motion.ts
+++ b/src/misc/motion.ts
@@ -1,5 +1,3 @@
import { createResource } from './createResource';
-export const framerMotionResouce = createResource(
- () => import('framer-motion')
-);
+export const framerMotionResouce = createResource(() => import('framer-motion'));
diff --git a/src/misc/request-helper.ts b/src/misc/request-helper.ts
index 3bc8476..c01b994 100644
--- a/src/misc/request-helper.ts
+++ b/src/misc/request-helper.ts
@@ -12,7 +12,7 @@ function genCommonHeaders({ secret }: { secret?: string }) {
return h;
}
function buildWebSocketURLBase(baseURL: string, params: URLSearchParams, endpoint: string) {
- const qs = '?' + params.toString()
+ const qs = '?' + params.toString();
const url = new URL(baseURL);
url.protocol === 'https:' ? (url.protocol = 'wss:') : (url.protocol = 'ws:');
return `${trimTrailingSlash(url.href)}${endpoint}${qs}`;
@@ -32,7 +32,7 @@ export function buildWebSocketURL(apiConfig: ClashAPIConfig, endpoint: string) {
token: secret,
});
- return buildWebSocketURLBase(baseURL, params, endpoint)
+ return buildWebSocketURLBase(baseURL, params, endpoint);
}
export function buildLogsWebSocketURL(apiConfig: LogsAPIConfig, endpoint: string) {
@@ -42,5 +42,5 @@ export function buildLogsWebSocketURL(apiConfig: LogsAPIConfig, endpoint: string
level: logLevel,
});
- return buildWebSocketURLBase(baseURL, params, endpoint)
+ return buildWebSocketURLBase(baseURL, params, endpoint);
}
diff --git a/src/misc/shallowEqual.ts b/src/misc/shallowEqual.ts
index 241b725..937bc27 100644
--- a/src/misc/shallowEqual.ts
+++ b/src/misc/shallowEqual.ts
@@ -12,12 +12,7 @@ function is(x, y) {
export default function shallowEqual(objA, objB) {
if (is(objA, objB)) return true;
- if (
- typeof objA !== 'object' ||
- objA === null ||
- typeof objB !== 'object' ||
- objB === null
- ) {
+ if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
return false;
}
diff --git a/src/misc/utils.ts b/src/misc/utils.ts
index d3a7bfc..9497026 100644
--- a/src/misc/utils.ts
+++ b/src/misc/utils.ts
@@ -1,7 +1,4 @@
-export function throttle<T extends any[]>(
- fn: (...args: T) => unknown,
- timeout: number
-) {
+export function throttle<T extends any[]>(fn: (...args: T) => unknown, timeout: number) {
let pending = false;
return (...args: T) => {
@@ -15,10 +12,7 @@ export function throttle<T extends any[]>(
};
}
-export function debounce<T extends any[]>(
- fn: (...args: T) => unknown,
- timeout: number
-) {
+export function debounce<T extends any[]>(fn: (...args: T) => unknown, timeout: number) {
let timeoutId: ReturnType<typeof setTimeout>;
return (...args: T) => {
if (timeoutId) clearTimeout(timeoutId);