Move string utils and migrate to typescript

This commit is contained in:
Bill Thornton 2022-04-10 01:30:26 -04:00
parent 5b016bafad
commit a238ae21f1
3 changed files with 5 additions and 5 deletions

View File

@ -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';

View File

@ -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';

View File

@ -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);