aboutsummaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/base64.ts8
-rw-r--r--src/utils/boolean.test.ts2
-rw-r--r--src/utils/boolean.ts3
-rw-r--r--src/utils/convert.ts2
-rw-r--r--src/utils/defaults.test.ts2
-rw-r--r--src/utils/defaults.ts6
-rw-r--r--src/utils/error.test.ts3
-rw-r--r--src/utils/error.ts3
-rw-r--r--src/utils/macAddress.ts2
-rw-r--r--src/utils/random.ts4
10 files changed, 21 insertions, 14 deletions
diff --git a/src/utils/base64.ts b/src/utils/base64.ts
index 44fda1e..16912ee 100644
--- a/src/utils/base64.ts
+++ b/src/utils/base64.ts
@@ -6,7 +6,7 @@ function textToBase64(str: string, { makeUrlSafe = false }: { makeUrlSafe?: bool
}
function base64ToText(str: string, { makeUrlSafe = false }: { makeUrlSafe?: boolean } = {}) {
- if (!isValidBase64(str, { makeUrlSafe: makeUrlSafe })) {
+ if (!isValidBase64(str, { makeUrlSafe })) {
throw new Error('Incorrect base64 string');
}
@@ -17,7 +17,8 @@ function base64ToText(str: string, { makeUrlSafe = false }: { makeUrlSafe?: bool
try {
return window.atob(cleanStr);
- } catch (_) {
+ }
+ catch (_) {
throw new Error('Incorrect base64 string');
}
}
@@ -37,7 +38,8 @@ function isValidBase64(str: string, { makeUrlSafe = false }: { makeUrlSafe?: boo
return removePotentialPadding(window.btoa(window.atob(cleanStr))) === cleanStr;
}
return window.btoa(window.atob(cleanStr)) === cleanStr;
- } catch (err) {
+ }
+ catch (err) {
return false;
}
}
diff --git a/src/utils/boolean.test.ts b/src/utils/boolean.test.ts
index 52bda9e..07daa05 100644
--- a/src/utils/boolean.test.ts
+++ b/src/utils/boolean.test.ts
@@ -8,7 +8,7 @@ describe('boolean utils', () => {
expect(isNotThrowing(_.noop)).to.eql(true);
expect(
isNotThrowing(() => {
- throw new Error();
+ throw new Error('message');
}),
).to.eql(false);
});
diff --git a/src/utils/boolean.ts b/src/utils/boolean.ts
index cf10b37..8dca5e9 100644
--- a/src/utils/boolean.ts
+++ b/src/utils/boolean.ts
@@ -4,7 +4,8 @@ function isNotThrowing(cb: () => unknown): boolean {
try {
cb();
return true;
- } catch (_) {
+ }
+ catch (_) {
return false;
}
}
diff --git a/src/utils/convert.ts b/src/utils/convert.ts
index c8c325f..c897543 100644
--- a/src/utils/convert.ts
+++ b/src/utils/convert.ts
@@ -7,5 +7,5 @@ export function formatBytes(bytes: number, decimals = 2) {
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
- return parseFloat((bytes / Math.pow(k, i)).toFixed(decimals)) + ' ' + sizes[i];
+ return `${parseFloat((bytes / k ** i).toFixed(decimals))} ${sizes[i]}`;
}
diff --git a/src/utils/defaults.test.ts b/src/utils/defaults.test.ts
index b322968..5001798 100644
--- a/src/utils/defaults.test.ts
+++ b/src/utils/defaults.test.ts
@@ -9,7 +9,7 @@ describe('defaults util', () => {
expect(
withDefaultOnError(() => {
- throw '';
+ throw new Error('message');
}, 'default'),
).to.eql('default');
});
diff --git a/src/utils/defaults.ts b/src/utils/defaults.ts
index 1e52b49..c988af5 100644
--- a/src/utils/defaults.ts
+++ b/src/utils/defaults.ts
@@ -3,7 +3,8 @@ export { withDefaultOnError, withDefaultOnErrorAsync };
function withDefaultOnError<A, B>(cb: () => A, defaultValue: B): A | B {
try {
return cb();
- } catch (_) {
+ }
+ catch (_) {
return defaultValue;
}
}
@@ -11,7 +12,8 @@ function withDefaultOnError<A, B>(cb: () => A, defaultValue: B): A | B {
async function withDefaultOnErrorAsync<A, B>(cb: () => A, defaultValue: B): Promise<Awaited<A> | B> {
try {
return await cb();
- } catch (_) {
+ }
+ catch (_) {
return defaultValue;
}
}
diff --git a/src/utils/error.test.ts b/src/utils/error.test.ts
index 0272804..62bf272 100644
--- a/src/utils/error.test.ts
+++ b/src/utils/error.test.ts
@@ -6,6 +6,7 @@ describe('error util', () => {
it('get an error message if the callback throws, undefined instead', () => {
expect(
getErrorMessageIfThrows(() => {
+ // eslint-disable-next-line no-throw-literal
throw 'message';
}),
).to.equal('message');
@@ -18,11 +19,11 @@ describe('error util', () => {
expect(
getErrorMessageIfThrows(() => {
+ // eslint-disable-next-line no-throw-literal
throw { message: 'message' };
}),
).to.equal('message');
- // eslint-disable-next-line @typescript-eslint/no-empty-function
expect(getErrorMessageIfThrows(() => {})).to.equal(undefined);
});
});
diff --git a/src/utils/error.ts b/src/utils/error.ts
index 681db91..297edd9 100644
--- a/src/utils/error.ts
+++ b/src/utils/error.ts
@@ -6,7 +6,8 @@ function getErrorMessageIfThrows(cb: () => unknown) {
try {
cb();
return undefined;
- } catch (err) {
+ }
+ catch (err) {
if (_.isString(err)) {
return err;
}
diff --git a/src/utils/macAddress.ts b/src/utils/macAddress.ts
index 89f12d3..4488b32 100644
--- a/src/utils/macAddress.ts
+++ b/src/utils/macAddress.ts
@@ -1,5 +1,5 @@
-import { useValidation } from '@/composable/validation';
import type { Ref } from 'vue';
+import { useValidation } from '@/composable/validation';
const macAddressValidationRules = [
{
diff --git a/src/utils/random.ts b/src/utils/random.ts
index 3a13be5..02df947 100644
--- a/src/utils/random.ts
+++ b/src/utils/random.ts
@@ -5,14 +5,14 @@ const randFromArray = (array: unknown[]) => array[Math.floor(random() * array.le
const randIntFromInterval = (min: number, max: number) => Math.floor(random() * (max - min) + min);
// Durstenfeld shuffle
-const shuffleArrayMutate = <T>(array: T[]): T[] => {
+function shuffleArrayMutate<T>(array: T[]): T[] {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array;
-};
+}
const shuffleArray = <T>(array: T[]): T[] => shuffleArrayMutate([...array]);