jorel
Version:
A unified wrapper for working with LLMs from multiple providers, including streams, images, documents & automatic tool use.
29 lines (28 loc) • 1.7 kB
TypeScript
import { Nullable } from "./type-utils";
export type HasId = {
id: string;
};
export type IdOrHasId = HasId | string;
/** Get the first value in an array */
export declare const firstEntry: <T>(values: T[]) => Nullable<T>;
/** Get the last value in an array */
export declare const lastEntry: <T>(values: T[]) => Nullable<T>;
/** Extract the id from an object (or string) */
export declare const extractId: (idOrValue1: IdOrHasId) => string;
/** Extract the ids from a list of objects */
export declare const extractIds: (values: HasId[]) => string[];
/** Get the unique ids from a list of objects with ids or ids */
export declare function getUniqueIds(values: IdOrHasId[], asSet: true): Set<string>;
export declare function getUniqueIds(values: IdOrHasId[], asSet?: false): string[];
/** Checks whether the objects (or strings) share the same id */
export declare const equalsId: (idOrValue1: IdOrHasId) => (idOrValue2: IdOrHasId) => boolean;
/** Checks whether the objects (or strings) do not share the same id */
export declare const unEqualsId: (idOrValue1: IdOrHasId) => (idOrValue2: IdOrHasId) => boolean;
/** Checks whether the list of objects (or strings) contains the given id */
export declare const containsId: (values: IdOrHasId[], idOrValue: IdOrHasId) => boolean;
/** Replaces an object by its id */
export declare const replaceById: <T extends HasId>(values: T[], replacementValue: T, addIfNotFound?: boolean) => T[];
/** Retrieves an object by its id */
export declare const getById: <T extends HasId>(values: T[], valueOrId: IdOrHasId) => T | null;
/** Remove an object by its id */
export declare const removeById: <T extends HasId>(values: T[], valueOrId: IdOrHasId) => T[];