diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2024-02-27 07:23:42 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-27 12:23:42 +0000 |
commit | e47a0f488f3d9bbcb76ebcf4f5afe203c1ee06c0 (patch) | |
tree | 35a4a7411dd3154b19316b330c4976f291f021d2 /ext/js/core | |
parent | e74fadc5a411e907da088729ea13e23e6f5aa58d (diff) |
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
Diffstat (limited to 'ext/js/core')
-rw-r--r-- | ext/js/core/object-utilities.js | 32 | ||||
-rw-r--r-- | ext/js/core/utilities.js | 9 |
2 files changed, 32 insertions, 9 deletions
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 <https://www.gnu.org/licenses/>. + */ + +/** + * @param {unknown} value + * @returns {value is Record<string, unknown>} + */ +export function isObjectNotArray(value) { + return typeof value === 'object' && value !== null && !Array.isArray(value); +} + +/** + * @param {unknown} value + * @returns {value is Record<string|number|symbol, unknown>} + */ +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 @@ -17,15 +17,6 @@ */ /** - * 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 * @param {string} string The string to convert to a valid regular expression. |