mirror of
https://github.com/Redocly/redoc.git
synced 2025-03-10 21:05:47 +03:00
This was declared in the local stubs file but not shipped, meaning that consumers with typescript libchecking enabled would have to also add the GenericObject definition to their local stubs file. This commit inlines the definition where necessary, or replaces it with object where appropriate.
29 lines
763 B
TypeScript
29 lines
763 B
TypeScript
export function objectHas(object: object, path: string | Array<string>): boolean {
|
|
let _path = <Array<string>>path;
|
|
|
|
if (typeof path === 'string') {
|
|
_path = path.split('.');
|
|
}
|
|
|
|
return _path.every((key: string) => {
|
|
if (typeof object != 'object' || object === null || !(key in object)) return false;
|
|
object = object[key];
|
|
return true;
|
|
});
|
|
}
|
|
|
|
export function objectSet(object: object, path: string | Array<string>, value: any): void {
|
|
let _path = <Array<string>>path;
|
|
|
|
if (typeof path === 'string') {
|
|
_path = path.split('.');
|
|
}
|
|
const limit = _path.length - 1;
|
|
for (let i = 0; i < limit; ++i) {
|
|
const key = _path[i];
|
|
object = object[key] ?? (object[key] = {});
|
|
}
|
|
const key = _path[limit];
|
|
object[key] = value;
|
|
}
|