From a238ae21f18651c07a3ad035fe4dd0faabe7c2e9 Mon Sep 17 00:00:00 2001 From: Bill Thornton Date: Sun, 10 Apr 2022 01:30:26 -0400 Subject: [PATCH] Move string utils and migrate to typescript --- src/components/syncPlay/core/PlaybackCore.js | 2 +- src/components/syncPlay/core/timeSync/TimeSyncCore.js | 2 +- src/{scripts/stringUtils.js => utils/string.ts} | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) rename src/{scripts/stringUtils.js => utils/string.ts} (75%) diff --git a/src/components/syncPlay/core/PlaybackCore.js b/src/components/syncPlay/core/PlaybackCore.js index a47872e9cb..91eb71c091 100644 --- a/src/components/syncPlay/core/PlaybackCore.js +++ b/src/components/syncPlay/core/PlaybackCore.js @@ -5,7 +5,7 @@ import { Events } from 'jellyfin-apiclient'; import browser from '../../../scripts/browser'; -import { toBoolean, toFloat } from '../../../scripts/stringUtils'; +import { toBoolean, toFloat } from '../../../utils/string.ts'; import * as Helper from './Helper'; import { getSetting } from './Settings'; diff --git a/src/components/syncPlay/core/timeSync/TimeSyncCore.js b/src/components/syncPlay/core/timeSync/TimeSyncCore.js index 772121dac8..cf9d6f09d7 100644 --- a/src/components/syncPlay/core/timeSync/TimeSyncCore.js +++ b/src/components/syncPlay/core/timeSync/TimeSyncCore.js @@ -5,7 +5,7 @@ import { Events } from 'jellyfin-apiclient'; import appSettings from '../../../../scripts/settings/appSettings'; -import { toFloat } from '../../../../scripts/stringUtils'; +import { toFloat } from '../../../../utils/string.ts'; import { getSetting } from '../Settings'; import TimeSyncServer from './TimeSyncServer'; diff --git a/src/scripts/stringUtils.js b/src/utils/string.ts similarity index 75% rename from src/scripts/stringUtils.js rename to src/utils/string.ts index 0fcb8a2899..301f4c44a3 100644 --- a/src/scripts/stringUtils.js +++ b/src/utils/string.ts @@ -4,7 +4,7 @@ * @param {boolean} defaultValue The default value if the string is invalid. * @returns {boolean} The value. */ -export function toBoolean(value, defaultValue = false) { +export function toBoolean(value: string | undefined | null, defaultValue = false) { if (value !== 'true' && value !== 'false') { return defaultValue; } else { @@ -18,8 +18,8 @@ export function toBoolean(value, defaultValue = false) { * @param {number} defaultValue The default value if the string is invalid. * @returns {number} The value. */ -export function toFloat(value, defaultValue = 0) { - if (value === null || value === '' || isNaN(value)) { +export function toFloat(value: string | null | undefined, defaultValue = 0) { + if (!value || isNaN(value as never)) { return defaultValue; } else { return parseFloat(value);