diff options
Diffstat (limited to 'src/helpers')
-rw-r--r-- | src/helpers/i18n-helpers.ts | 12 | ||||
-rw-r--r-- | src/helpers/password-helpers.ts | 14 | ||||
-rw-r--r-- | src/helpers/recipe-helpers.ts | 14 | ||||
-rw-r--r-- | src/helpers/schedule-helpers.ts | 8 | ||||
-rw-r--r-- | src/helpers/url-helpers.ts | 2 | ||||
-rw-r--r-- | src/helpers/userAgent-helpers.ts | 2 | ||||
-rw-r--r-- | src/helpers/validation-helpers.ts | 19 |
7 files changed, 33 insertions, 38 deletions
diff --git a/src/helpers/i18n-helpers.ts b/src/helpers/i18n-helpers.ts index c1f18f446..ec7dc8e98 100644 --- a/src/helpers/i18n-helpers.ts +++ b/src/helpers/i18n-helpers.ts | |||
@@ -4,13 +4,11 @@ export function getLocale({ | |||
4 | let localeStr = locale; | 4 | let localeStr = locale; |
5 | if (locales[locale] === undefined) { | 5 | if (locales[locale] === undefined) { |
6 | let localeFuzzy: string | undefined; | 6 | let localeFuzzy: string | undefined; |
7 | Object.keys(locales).forEach((localStr) => { | 7 | for (const localStr of Object.keys(locales)) { |
8 | if (locales && Object.hasOwnProperty.call(locales, localStr)) { | 8 | if (locales && Object.hasOwnProperty.call(locales, localStr) && locale.slice(0, 2) === localStr.slice(0, 2)) { |
9 | if (locale.substring(0, 2) === localStr.substring(0, 2)) { | ||
10 | localeFuzzy = localStr; | 9 | localeFuzzy = localStr; |
11 | } | 10 | } |
12 | } | 11 | } |
13 | }); | ||
14 | 12 | ||
15 | if (localeFuzzy !== undefined) { | 13 | if (localeFuzzy !== undefined) { |
16 | localeStr = localeFuzzy; | 14 | localeStr = localeFuzzy; |
@@ -61,12 +59,12 @@ export function getSelectOptions({ | |||
61 | if (sort) { | 59 | if (sort) { |
62 | keys = keys.sort(Intl.Collator().compare); | 60 | keys = keys.sort(Intl.Collator().compare); |
63 | } | 61 | } |
64 | keys.forEach((key) => { | 62 | for (const key of keys) { |
65 | options.push({ | 63 | options.push({ |
66 | value: key, | 64 | value: key, |
67 | label: locales[key], | 65 | label: locales[key], |
68 | }); | 66 | }); |
69 | }); | 67 | } |
70 | 68 | ||
71 | return options; | 69 | return options; |
72 | } | 70 | } |
diff --git a/src/helpers/password-helpers.ts b/src/helpers/password-helpers.ts index 89c75c752..e5d9a4a25 100644 --- a/src/helpers/password-helpers.ts +++ b/src/helpers/password-helpers.ts | |||
@@ -12,9 +12,9 @@ export function scorePassword(password: string) { | |||
12 | 12 | ||
13 | // award every unique letter until 5 repetitions | 13 | // award every unique letter until 5 repetitions |
14 | const letters = {}; | 14 | const letters = {}; |
15 | for (let i = 0; i < password.length; i += 1) { | 15 | for (const letter of password) { |
16 | letters[password[i]] = (letters[password[i]] || 0) + 1; | 16 | letters[letter] = (letters[letter] || 0) + 1; |
17 | score += 5.0 / letters[password[i]]; | 17 | score += 5 / letters[letter]; |
18 | } | 18 | } |
19 | 19 | ||
20 | // bonus points for mixing it up | 20 | // bonus points for mixing it up |
@@ -26,11 +26,11 @@ export function scorePassword(password: string) { | |||
26 | }; | 26 | }; |
27 | 27 | ||
28 | let variationCount = 0; | 28 | let variationCount = 0; |
29 | Object.keys(variations).forEach((key) => { | 29 | for (const key of Object.keys(variations)) { |
30 | variationCount += (variations[key] === true) ? 1 : 0; | 30 | variationCount += variations[key] === true ? 1 : 0; |
31 | }); | 31 | } |
32 | 32 | ||
33 | score += (variationCount - 1) * 10; | 33 | score += (variationCount - 1) * 10; |
34 | 34 | ||
35 | return parseInt(score.toString(), 10); | 35 | return Number.parseInt(score.toString(), 10); |
36 | } | 36 | } |
diff --git a/src/helpers/recipe-helpers.ts b/src/helpers/recipe-helpers.ts index 965429210..65ef04088 100644 --- a/src/helpers/recipe-helpers.ts +++ b/src/helpers/recipe-helpers.ts | |||
@@ -1,3 +1,4 @@ | |||
1 | /* eslint-disable global-require */ | ||
1 | import { parse } from 'path'; | 2 | import { parse } from 'path'; |
2 | import { userDataRecipesPath } from '../environment'; | 3 | import { userDataRecipesPath } from '../environment'; |
3 | 4 | ||
@@ -15,20 +16,17 @@ export function loadRecipeConfig(recipeId: string) { | |||
15 | // Delete module from cache | 16 | // Delete module from cache |
16 | delete require.cache[require.resolve(configPath)]; | 17 | delete require.cache[require.resolve(configPath)]; |
17 | 18 | ||
18 | // eslint-disable-next-line | 19 | // eslint-disable-next-line import/no-dynamic-require |
19 | let config = require(configPath); | 20 | const config = require(configPath); |
20 | 21 | ||
21 | const moduleConfigPath = require.resolve(configPath); | 22 | const moduleConfigPath = require.resolve(configPath); |
22 | config.path = parse(moduleConfigPath).dir; | 23 | config.path = parse(moduleConfigPath).dir; |
23 | 24 | ||
24 | return config; | 25 | return config; |
25 | } catch (e) { | 26 | } catch (error) { |
26 | console.error(e); | 27 | console.error(error); |
27 | return null; | 28 | return null; |
28 | } | 29 | } |
29 | } | 30 | } |
30 | 31 | ||
31 | module.paths.unshift( | 32 | module.paths.unshift(getDevRecipeDirectory(), getRecipeDirectory()); |
32 | getDevRecipeDirectory(), | ||
33 | getRecipeDirectory(), | ||
34 | ); | ||
diff --git a/src/helpers/schedule-helpers.ts b/src/helpers/schedule-helpers.ts index 754fd5556..55b7c1e6f 100644 --- a/src/helpers/schedule-helpers.ts +++ b/src/helpers/schedule-helpers.ts | |||
@@ -5,15 +5,15 @@ export function isInTimeframe(start: string, end: string) { | |||
5 | startHourStr, | 5 | startHourStr, |
6 | startMinuteStr, | 6 | startMinuteStr, |
7 | ] = start.split(':'); | 7 | ] = start.split(':'); |
8 | const startHour = parseInt(startHourStr, 10); | 8 | const startHour = Number.parseInt(startHourStr, 10); |
9 | const startMinute = parseInt(startMinuteStr, 10); | 9 | const startMinute = Number.parseInt(startMinuteStr, 10); |
10 | 10 | ||
11 | const [ | 11 | const [ |
12 | endHourStr, | 12 | endHourStr, |
13 | endMinuteStr, | 13 | endMinuteStr, |
14 | ] = end.split(':'); | 14 | ] = end.split(':'); |
15 | const endHour = parseInt(endHourStr, 10); | 15 | const endHour = Number.parseInt(endHourStr, 10); |
16 | const endMinute = parseInt(endMinuteStr, 10); | 16 | const endMinute = Number.parseInt(endMinuteStr, 10); |
17 | 17 | ||
18 | const currentHour = new Date().getHours(); | 18 | const currentHour = new Date().getHours(); |
19 | const currentMinute = new Date().getMinutes(); | 19 | const currentMinute = new Date().getMinutes(); |
diff --git a/src/helpers/url-helpers.ts b/src/helpers/url-helpers.ts index 3657ae693..1e87ecabb 100644 --- a/src/helpers/url-helpers.ts +++ b/src/helpers/url-helpers.ts | |||
@@ -12,7 +12,7 @@ export function isValidExternalURL(url: string | URL) { | |||
12 | let parsedUrl: URL; | 12 | let parsedUrl: URL; |
13 | try { | 13 | try { |
14 | parsedUrl = new URL(url.toString()); | 14 | parsedUrl = new URL(url.toString()); |
15 | } catch (_) { | 15 | } catch { |
16 | return false; | 16 | return false; |
17 | } | 17 | } |
18 | 18 | ||
diff --git a/src/helpers/userAgent-helpers.ts b/src/helpers/userAgent-helpers.ts index 73c8bfd03..091a76400 100644 --- a/src/helpers/userAgent-helpers.ts +++ b/src/helpers/userAgent-helpers.ts | |||
@@ -8,7 +8,7 @@ import { | |||
8 | function macOS() { | 8 | function 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 && /\(/.test(cpuName)) { |
12 | cpuName = cpuName.split('(')[0]; | 12 | cpuName = cpuName.split('(')[0]; |
13 | } | 13 | } |
14 | return `Macintosh; ${cpuName} Mac OS X ${version.replace(/\./g, '_')}`; | 14 | return `Macintosh; ${cpuName} Mac OS X ${version.replace(/\./g, '_')}`; |
diff --git a/src/helpers/validation-helpers.ts b/src/helpers/validation-helpers.ts index 3a9622309..23c297443 100644 --- a/src/helpers/validation-helpers.ts +++ b/src/helpers/validation-helpers.ts | |||
@@ -49,16 +49,15 @@ export function url({ field }) { | |||
49 | const value = field.value.trim(); | 49 | const value = field.value.trim(); |
50 | let isValid = false; | 50 | let isValid = false; |
51 | 51 | ||
52 | if (value !== '') { | 52 | isValid = |
53 | // eslint-disable-next-line | 53 | value !== '' |
54 | isValid = Boolean( | 54 | ? Boolean( |
55 | value.match( | 55 | // eslint-disable-next-line unicorn/better-regex |
56 | /(^|[\s.:;?\-\]<(])(https?:\/\/[-\w;/?:@&=+$|_.!~*|'()[\]%#,☺]+[\w/#](\(\))?)(?=$|[\s',|().:;?\-[\]>)])/i, | 56 | /(^|[\s.:;?\-\]<(])(https?:\/\/[-\w;/?:@&=+$|_.!~*|'()[\]%#,☺]+[\w/#](\(\))?)(?=$|[\s',|().:;?\-[\]>)])/i.test( |
57 | ), | 57 | value, |
58 | ); | 58 | ), |
59 | } else { | 59 | ) |
60 | isValid = true; | 60 | : true; |
61 | } | ||
62 | 61 | ||
63 | return [ | 62 | return [ |
64 | isValid, | 63 | isValid, |