From e47a0f488f3d9bbcb76ebcf4f5afe203c1ee06c0 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Tue, 27 Feb 2024 07:23:42 -0500 Subject: Object utilities (#729) * Create utilities * Rename old isObject * Use new isObject * Remove old function * Add additional function * Simplify for now * Rename function for clarity * Rename function * Expand type * Update eslint --- ext/js/pages/settings/backup-controller.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'ext/js/pages/settings/backup-controller.js') diff --git a/ext/js/pages/settings/backup-controller.js b/ext/js/pages/settings/backup-controller.js index 2a0706e4..dd739d39 100644 --- a/ext/js/pages/settings/backup-controller.js +++ b/ext/js/pages/settings/backup-controller.js @@ -19,8 +19,8 @@ import {Dexie} from '../../../lib/dexie.js'; import {parseJson} from '../../core/json.js'; import {log} from '../../core/log.js'; +import {isObjectNotArray} from '../../core/object-utilities.js'; import {toError} from '../../core/to-error.js'; -import {isObject} from '../../core/utilities.js'; import {OptionsUtil} from '../../data/options-util.js'; import {getAllPermissions} from '../../data/permissions-util.js'; import {arrayBufferUtf8Decode} from '../../data/sandbox/array-buffer-util.js'; @@ -354,7 +354,7 @@ export class BackupController { const warnings = []; const anki = options.anki; - if (isObject(anki)) { + if (isObjectNotArray(anki)) { const fieldTemplates = anki.fieldTemplates; if (typeof fieldTemplates === 'string') { warnings.push('anki.fieldTemplates contains a non-default value'); @@ -372,12 +372,12 @@ export class BackupController { } const audio = options.audio; - if (isObject(audio)) { + if (isObjectNotArray(audio)) { const sources = audio.sources; if (Array.isArray(sources)) { for (let i = 0, ii = sources.length; i < ii; ++i) { const source = sources[i]; - if (!isObject(source)) { continue; } + if (!isObjectNotArray(source)) { continue; } const {url} = source; if (typeof url === 'string' && url.length > 0 && !this._isLocalhostUrl(url)) { warnings.push(`audio.sources[${i}].url uses a non-localhost URL`); @@ -403,9 +403,9 @@ export class BackupController { const profiles = optionsFull.profiles; if (Array.isArray(profiles)) { for (const profile of profiles) { - if (!isObject(profile)) { continue; } + if (!isObjectNotArray(profile)) { continue; } const options = profile.options; - if (!isObject(options)) { continue; } + if (!isObjectNotArray(options)) { continue; } const warnings2 = this._settingsImportSanitizeProfileOptions(options, dryRun); for (const warning of warnings2) { @@ -428,7 +428,7 @@ export class BackupController { const data = parseJson(dataString); // Type check - if (!isObject(data)) { + if (!isObjectNotArray(data)) { throw new Error(`Invalid data type: ${typeof data}`); } @@ -451,7 +451,7 @@ export class BackupController { // Verify options exists let optionsFull = data.options; - if (!isObject(optionsFull)) { + if (!isObjectNotArray(optionsFull)) { throw new Error(`Invalid options type: ${typeof optionsFull}`); } -- cgit v1.2.3