Move boolean and float parsing to shared utils
This commit is contained in:
parent
5238888ecf
commit
f32538ace4
5 changed files with 48 additions and 50 deletions
|
@ -2,7 +2,6 @@
|
|||
* Module that manages SyncPlay settings.
|
||||
* @module components/syncPlay/core/Settings
|
||||
*/
|
||||
|
||||
import { Events, AppStorage } from 'jellyfin-apiclient';
|
||||
|
||||
/**
|
||||
|
@ -47,38 +46,7 @@ class SyncPlaySettings {
|
|||
|
||||
console.debug(`SyncPlay Settings set: '${name}' from '${oldValue}' to '${newValue}'.`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of a setting as boolean.
|
||||
* @param {string} name The name of the setting.
|
||||
* @param {boolean} defaultValue The default value if the setting does not exist.
|
||||
* @returns {boolean} The value.
|
||||
*/
|
||||
getBool(name, defaultValue = false) {
|
||||
const value = this.get(name);
|
||||
if (value !== 'true' && value !== 'false') {
|
||||
return defaultValue;
|
||||
} else {
|
||||
return this.get(name) !== 'false';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of a setting as float number.
|
||||
* @param {string} name The name of the setting.
|
||||
* @param {number} defaultValue The default value if the setting does not exist.
|
||||
* @returns {number} The value.
|
||||
*/
|
||||
getFloat(name, defaultValue = 0) {
|
||||
const value = this.get(name);
|
||||
if (value === null || value === '' || isNaN(value)) {
|
||||
return defaultValue;
|
||||
} else {
|
||||
return Number.parseFloat(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** SyncPlaySettings singleton. */
|
||||
const Settings = new SyncPlaySettings();
|
||||
export default Settings;
|
||||
export default new SyncPlaySettings();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue