finder-refferenct3/source/util/ObjectUtil.ts

67 lines
1.7 KiB
TypeScript
Raw Normal View History

2024-10-31 02:37:08 +00:00
/**
*
*/
export default class ObjectUtil {
/**
*
* @param {any} arg
*/
static isObject(arg) {
return Object.prototype.toString.call(arg) === '[object Object]';
}
/**
*
* @param {object} object
* @param {any} name
*/
static containsProperty(object, name) {
let result = false;
const search = (_object) => {
if (this.isObject(_object)) {
for (const key in _object) {
if (key == name) {
result = true;
return;
}
search(_object[key]);
}
} else if (Array.isArray(_object)) {
for (let i = 0; i < _object.length; i++) {
search(_object[i]);
}
}
}
search(object);
return result;
}
/**
*
* @param {object} object
* @param {any} value
*/
static containsValue(object, value) {
let result = false;
const search = (_object) => {
if (this.isObject(_object)) {
for (const key in _object) {
if (_object[key] === value) {
result = true;
return;
}
search(_object[key]);
}
} else if (Array.isArray(_object)) {
for (let i = 0; i < _object.length; i++) {
search(_object[i]);
}
}
}
search(object);
return result;
}
}