aboutsummaryrefslogtreecommitdiffstats
path: root/src/helpers
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/helpers
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/helpers')
-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
10 files changed, 16 insertions, 17 deletions
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];