aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar Vijay A <avijayr@protonmail.com>2021-08-15 17:15:09 +0530
committerLibravatar Vijay Raghavan Aravamudhan <vraravam@users.noreply.github.com>2021-08-15 13:54:00 +0000
commitbc76d19c6f5687dd18c96db249e0abe7ad79a673 (patch)
treed4e977f99be77d723ce93bb3866468d8b63ec038 /src
parentchore: npm upgrades (diff)
downloadferdium-app-bc76d19c6f5687dd18c96db249e0abe7ad79a673.tar.gz
ferdium-app-bc76d19c6f5687dd18c96db249e0abe7ad79a673.tar.zst
ferdium-app-bc76d19c6f5687dd18c96db249e0abe7ad79a673.zip
chore: typescript conversion of some minor utilities
Also removed 'targz' unused package from runtime.
Diffstat (limited to 'src')
-rw-r--r--src/api/server/LocalApi.ts (renamed from src/api/server/LocalApi.js)10
-rw-r--r--src/helpers/array-helpers.ts (renamed from src/helpers/array-helpers.js)2
-rw-r--r--src/helpers/asar-helpers.ts (renamed from src/helpers/asar-helpers.js)2
-rw-r--r--src/helpers/async-helpers.ts (renamed from src/helpers/async-helpers.js)2
-rw-r--r--src/helpers/i18n-helpers.ts (renamed from src/helpers/i18n-helpers.js)4
-rw-r--r--src/helpers/password-helpers.ts (renamed from src/helpers/password-helpers.js)6
-rw-r--r--src/helpers/recipe-helpers.ts (renamed from src/helpers/recipe-helpers.js)6
-rw-r--r--src/helpers/routing-helpers.js4
-rw-r--r--src/helpers/routing-helpers.ts3
-rw-r--r--src/helpers/schedule-helpers.ts (renamed from src/helpers/schedule-helpers.js)2
-rw-r--r--src/helpers/userAgent-helpers.ts (renamed from src/helpers/userAgent-helpers.js)2
11 files changed, 21 insertions, 22 deletions
diff --git a/src/api/server/LocalApi.js b/src/api/server/LocalApi.ts
index 644f15b93..71721bb0f 100644
--- a/src/api/server/LocalApi.js
+++ b/src/api/server/LocalApi.ts
@@ -8,9 +8,9 @@ const debug = require('debug')('Ferdi:LocalApi');
8 8
9export default class LocalApi { 9export default class LocalApi {
10 // Settings 10 // Settings
11 getAppSettings(type) { 11 getAppSettings(type: any) {
12 return new Promise(resolve => { 12 return new Promise(resolve => {
13 ipcRenderer.once('appSettings', (event, resp) => { 13 ipcRenderer.once('appSettings', (_event, resp) => {
14 debug('LocalApi::getAppSettings resolves', resp.type, resp.data); 14 debug('LocalApi::getAppSettings resolves', resp.type, resp.data);
15 resolve(resp); 15 resolve(resp);
16 }); 16 });
@@ -19,7 +19,7 @@ export default class LocalApi {
19 }); 19 });
20 } 20 }
21 21
22 async updateAppSettings(type, data) { 22 async updateAppSettings(type: any, data: any) {
23 debug('LocalApi::updateAppSettings resolves', type, data); 23 debug('LocalApi::updateAppSettings resolves', type, data);
24 ipcRenderer.send('updateAppSettings', { 24 ipcRenderer.send('updateAppSettings', {
25 type, 25 type,
@@ -31,7 +31,7 @@ export default class LocalApi {
31 async getAppCacheSize() { 31 async getAppCacheSize() {
32 const partitionsDir = getServicePartitionsDirectory(); 32 const partitionsDir = getServicePartitionsDirectory();
33 return new Promise((resolve, reject) => { 33 return new Promise((resolve, reject) => {
34 du(partitionsDir, (err, size) => { 34 du(partitionsDir, (err: Error | null, size?: number | undefined) => {
35 if (err) reject(err); 35 if (err) reject(err);
36 36
37 debug('LocalApi::getAppCacheSize resolves', size); 37 debug('LocalApi::getAppCacheSize resolves', size);
@@ -40,7 +40,7 @@ export default class LocalApi {
40 }); 40 });
41 } 41 }
42 42
43 async clearCache(serviceId = null) { 43 async clearCache(serviceId: string | null = null) {
44 const s = serviceId 44 const s = serviceId
45 ? session.fromPartition(`persist:service-${serviceId}`) 45 ? session.fromPartition(`persist:service-${serviceId}`)
46 : session.defaultSession; 46 : session.defaultSession;
diff --git a/src/helpers/array-helpers.js b/src/helpers/array-helpers.ts
index 5e592b7f7..ae5d8d99f 100644
--- a/src/helpers/array-helpers.js
+++ b/src/helpers/array-helpers.ts
@@ -1,4 +1,4 @@
1export const shuffleArray = (arr) => arr 1export const shuffleArray = (arr: any[]) => arr
2 .map((a) => [Math.random(), a]) 2 .map((a) => [Math.random(), a])
3 .sort((a, b) => a[0] - b[0]) 3 .sort((a, b) => a[0] - b[0])
4 .map((a) => a[1]); 4 .map((a) => a[1]);
diff --git a/src/helpers/asar-helpers.js b/src/helpers/asar-helpers.ts
index 9e4380c06..3d9f0d941 100644
--- a/src/helpers/asar-helpers.js
+++ b/src/helpers/asar-helpers.ts
@@ -1,3 +1,3 @@
1export function asarPath(dir = '') { 1export function asarPath(dir: string = '') {
2 return dir.replace('app.asar', 'app.asar.unpacked'); 2 return dir.replace('app.asar', 'app.asar.unpacked');
3} 3}
diff --git a/src/helpers/async-helpers.js b/src/helpers/async-helpers.ts
index c6c57e28e..aae3c3928 100644
--- a/src/helpers/async-helpers.js
+++ b/src/helpers/async-helpers.ts
@@ -1,5 +1,5 @@
1/* eslint-disable import/prefer-default-export */ 1/* eslint-disable import/prefer-default-export */
2 2
3export function sleep(ms = 0) { 3export function sleep(ms: number = 0) {
4 return new Promise((r) => setTimeout(r, ms)); 4 return new Promise((r) => setTimeout(r, ms));
5} 5}
diff --git a/src/helpers/i18n-helpers.js b/src/helpers/i18n-helpers.ts
index 807b9066e..c1f18f446 100644
--- a/src/helpers/i18n-helpers.js
+++ b/src/helpers/i18n-helpers.ts
@@ -3,7 +3,7 @@ export function getLocale({
3}) { 3}) {
4 let localeStr = locale; 4 let localeStr = locale;
5 if (locales[locale] === undefined) { 5 if (locales[locale] === undefined) {
6 let localeFuzzy; 6 let localeFuzzy: string | undefined;
7 Object.keys(locales).forEach((localStr) => { 7 Object.keys(locales).forEach((localStr) => {
8 if (locales && Object.hasOwnProperty.call(locales, localStr)) { 8 if (locales && Object.hasOwnProperty.call(locales, localStr)) {
9 if (locale.substring(0, 2) === localStr.substring(0, 2)) { 9 if (locale.substring(0, 2) === localStr.substring(0, 2)) {
@@ -31,7 +31,7 @@ export function getLocale({
31export function getSelectOptions({ 31export function getSelectOptions({
32 locales, resetToDefaultText = '', automaticDetectionText = '', sort = true, 32 locales, resetToDefaultText = '', automaticDetectionText = '', sort = true,
33}) { 33}) {
34 const options = []; 34 const options: object[] = [];
35 35
36 if (resetToDefaultText) { 36 if (resetToDefaultText) {
37 options.push( 37 options.push(
diff --git a/src/helpers/password-helpers.js b/src/helpers/password-helpers.ts
index cf461e4f7..89c75c752 100644
--- a/src/helpers/password-helpers.js
+++ b/src/helpers/password-helpers.ts
@@ -1,10 +1,10 @@
1import crypto from 'crypto'; 1import crypto from 'crypto';
2 2
3export function hash(password) { 3export function hash(password: crypto.BinaryLike) {
4 return crypto.createHash('sha256').update(password).digest('base64'); 4 return crypto.createHash('sha256').update(password).digest('base64');
5} 5}
6 6
7export function scorePassword(password) { 7export function scorePassword(password: string) {
8 let score = 0; 8 let score = 0;
9 if (!password) { 9 if (!password) {
10 return score; 10 return score;
@@ -32,5 +32,5 @@ export function scorePassword(password) {
32 32
33 score += (variationCount - 1) * 10; 33 score += (variationCount - 1) * 10;
34 34
35 return parseInt(score, 10); 35 return parseInt(score.toString(), 10);
36} 36}
diff --git a/src/helpers/recipe-helpers.js b/src/helpers/recipe-helpers.ts
index 7e4bfa85a..965429210 100644
--- a/src/helpers/recipe-helpers.js
+++ b/src/helpers/recipe-helpers.ts
@@ -1,15 +1,15 @@
1import { parse } from 'path'; 1import { parse } from 'path';
2import { userDataRecipesPath } from '../environment'; 2import { userDataRecipesPath } from '../environment';
3 3
4export function getRecipeDirectory(id = '') { 4export function getRecipeDirectory(id: string = ''): string {
5 return userDataRecipesPath(id); 5 return userDataRecipesPath(id);
6} 6}
7 7
8export function getDevRecipeDirectory(id = '') { 8export function getDevRecipeDirectory(id: string = ''): string {
9 return userDataRecipesPath('dev', id); 9 return userDataRecipesPath('dev', id);
10} 10}
11 11
12export function loadRecipeConfig(recipeId) { 12export function loadRecipeConfig(recipeId: string) {
13 try { 13 try {
14 const configPath = `${recipeId}/package.json`; 14 const configPath = `${recipeId}/package.json`;
15 // Delete module from cache 15 // Delete module from cache
diff --git a/src/helpers/routing-helpers.js b/src/helpers/routing-helpers.js
deleted file mode 100644
index 14922ebf3..000000000
--- a/src/helpers/routing-helpers.js
+++ /dev/null
@@ -1,4 +0,0 @@
1import RouteParser from 'route-parser';
2
3// eslint-disable-next-line
4export const matchRoute = (pattern, path) => new RouteParser(pattern).match(path);
diff --git a/src/helpers/routing-helpers.ts b/src/helpers/routing-helpers.ts
new file mode 100644
index 000000000..18169f01b
--- /dev/null
+++ b/src/helpers/routing-helpers.ts
@@ -0,0 +1,3 @@
1import RouteParser from 'route-parser';
2
3export const matchRoute = (pattern: string, path: string) => new RouteParser(pattern).match(path);
diff --git a/src/helpers/schedule-helpers.js b/src/helpers/schedule-helpers.ts
index a3020cad6..754fd5556 100644
--- a/src/helpers/schedule-helpers.js
+++ b/src/helpers/schedule-helpers.ts
@@ -1,6 +1,6 @@
1/* eslint-disable import/prefer-default-export */ 1/* eslint-disable import/prefer-default-export */
2 2
3export function isInTimeframe(start, end) { 3export function isInTimeframe(start: string, end: string) {
4 const [ 4 const [
5 startHourStr, 5 startHourStr,
6 startMinuteStr, 6 startMinuteStr,
diff --git a/src/helpers/userAgent-helpers.js b/src/helpers/userAgent-helpers.ts
index ede5e6dc4..73c8bfd03 100644
--- a/src/helpers/userAgent-helpers.js
+++ b/src/helpers/userAgent-helpers.ts
@@ -6,7 +6,7 @@ import {
6} from '../environment'; 6} from '../environment';
7 7
8function macOS() { 8function macOS() {
9 const version = macosVersion(); 9 const version = macosVersion() || '';
10 let cpuName = os.cpus()[0].model.split(' ')[0]; 10 let cpuName = os.cpus()[0].model.split(' ')[0];
11 if (cpuName && cpuName.match(/\(/)) { 11 if (cpuName && cpuName.match(/\(/)) {
12 cpuName = cpuName.split('(')[0]; 12 cpuName = cpuName.split('(')[0];