@refinedev/core
Version:
Refine is a React meta-framework for building enterprise-level, data-intensive applications rapidly with support for modern UI libraries and headless integrations.
17 lines (14 loc) • 508 B
text/typescript
import fromPairs from "lodash/fromPairs";
import zip from "lodash/zip";
import type { MapDataFn } from "../../../hooks/export/types";
export const importCSVMapper = <TItem = any, TVariables = any>(
data: any[][],
mapData: MapDataFn<TItem, TVariables> = (item) => item as any,
): TVariables[] => {
const [headers, ...body] = data;
return body
.map((entry) => fromPairs(zip(headers, entry)))
.map((item: any, index, array: any) =>
mapData.call(undefined, item, index, array),
);
};