mirror of https://github.com/msgbyte/tailchat
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
523 B
TypeScript
22 lines
523 B
TypeScript
export default function virtualId<T extends { _id: string }>(
|
|
arr: T[]
|
|
): Array<T & { id: string }>;
|
|
export default function virtualId<T extends { _id: string }>(
|
|
doc: T
|
|
): T & { id: string };
|
|
|
|
/** Virtual ID (_id to id) for react-admin */
|
|
export default function virtualId<T extends { _id: string }>(el: Array<T> | T) {
|
|
if (Array.isArray(el)) {
|
|
return el.map((e) => {
|
|
return {
|
|
id: e._id,
|
|
...e,
|
|
_id: undefined,
|
|
};
|
|
});
|
|
}
|
|
|
|
return { id: el._id, ...el, _id: undefined };
|
|
}
|