2023-09-04 09:33:07 +00:00
|
|
|
import { DefaultType } from './types';
|
2022-11-22 12:16:34 +00:00
|
|
|
|
2023-09-04 09:33:07 +00:00
|
|
|
/**
|
|
|
|
* gets row id by looking for one of id, Id, or ID keys on the object
|
|
|
|
*/
|
|
|
|
export function defaultGetRowId<D extends DefaultType>(row: D): string {
|
|
|
|
const key = ['id', 'Id', 'ID'].find((key) =>
|
|
|
|
Object.hasOwn(row, key)
|
|
|
|
) as keyof D;
|
|
|
|
|
|
|
|
const value = row[key];
|
2022-11-22 12:16:34 +00:00
|
|
|
|
2023-09-04 09:33:07 +00:00
|
|
|
if (typeof value === 'string' || typeof value === 'number') {
|
|
|
|
return value.toString();
|
2022-11-22 12:16:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
|
|
|
}
|