@redocly/theme
Version:
Shared UI components lib
39 lines (38 loc) • 1.25 kB
TypeScript
export declare function findDeepFirst<T extends {
items?: T[];
}>(list: T[], cb: (item: T) => boolean): T | undefined;
export declare function toStringIfDefined(value: unknown): string | undefined;
/**
* Returns true when the function executed in browser.
*/
export declare function isBrowser(): boolean;
export declare function isPlainObject(obj: any): boolean;
/**
* Returns the previous and next values in an array for a given index.
*
* Edge cases:
* - If the index is `0`, `prev` will be `null`.
* - If the index is the last position in the array, `next` will be `null`.
* - If the index is out of bounds (negative or greater than the last index), both `prev` and `next` will be `null`.
*
* @example
* const array = [10, 20, 30, 40];
* getAdjacentValues(array, 2);
* // returns: { prev: 20, next: 40 }
*
* getAdjacentValues(array, 0);
* // returns: { prev: null, next: 20 }
*
* getAdjacentValues(array, 3);
* // returns: { prev: 30, next: null }
*
* getAdjacentValues(array, -1);
* // returns: { prev: null, next: null }
*
* getAdjacentValues(array, 4);
* // returns: { prev: null, next: null }
*/
export declare function getAdjacentValues<T>(array: T[], index: number): {
prev: T | null;
next: T | null;
};