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/core/object-utilities.js | 32 ++++++++++++++++++++++++++++++++ ext/js/core/utilities.js | 9 --------- 2 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 ext/js/core/object-utilities.js (limited to 'ext/js/core') diff --git a/ext/js/core/object-utilities.js b/ext/js/core/object-utilities.js new file mode 100644 index 00000000..8cbba7cd --- /dev/null +++ b/ext/js/core/object-utilities.js @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2024 Yomitan Authors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @param {unknown} value + * @returns {value is Record} + */ +export function isObjectNotArray(value) { + return typeof value === 'object' && value !== null && !Array.isArray(value); +} + +/** + * @param {unknown} value + * @returns {value is Record} + */ +export function isObject(value) { + return typeof value === 'object' && value !== null; +} diff --git a/ext/js/core/utilities.js b/ext/js/core/utilities.js index 1b785e79..1428a744 100644 --- a/ext/js/core/utilities.js +++ b/ext/js/core/utilities.js @@ -16,15 +16,6 @@ * along with this program. If not, see . */ -/** - * Checks whether a given value is a non-array object. - * @param {unknown} value The value to check. - * @returns {boolean} `true` if the value is an object and not an array, `false` otherwise. - */ -export function isObject(value) { - return typeof value === 'object' && value !== null && !Array.isArray(value); -} - /** * Converts any string into a form that can be passed into the RegExp constructor. * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions -- cgit v1.2.3