forked from eclipse-cdt-cloud/vscode-ui-components
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.ts
More file actions
28 lines (25 loc) · 1.05 KB
/
utils.ts
File metadata and controls
28 lines (25 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/********************************************************************************
* Copyright (C) 2024-2025 EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the MIT License as outlined in the LICENSE File
********************************************************************************/
/**
* Finds a nested value from an object using a dot-separated path.
*/
export function findNestedValue<T>(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
obj: Record<string, any>,
path: string | string[]
): T | undefined {
const keys = Array.isArray(path) ? path : path.split('.');
return keys.reduce((acc, key) => acc?.[key], obj) as T | undefined;
}
/**
* Check if an object has a property.
*/
export function hasProperty<TKey extends object>(object: object, ...keys: (keyof TKey)[]): object is TKey {
return keys.every(key => key in object);
}
export type WithRequired<T, K extends keyof T> = T & { [P in K]-?: T[P] };
export type MaybePromise<T> = T | Promise<T>;