UNPKG

synapse-react-client

Version:

[![npm version](https://badge.fury.io/js/synapse-react-client.svg)](https://badge.fury.io/js/synapse-react-client) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettie

38 lines (37 loc) 916 B
import i from "papaparse"; import { useMemo as p, useCallback as c } from "react"; import { isObject as m } from "lodash-es"; const { parse: f } = i, u = { jsonSchemaDefinition: { type: "string" } }; class g extends Error { parseErrors; constructor(r) { super("Error parsing CSV"), this.parseErrors = r; } } function d(s = u) { const { jsonSchemaDefinition: r } = s, o = p( () => m(r) && r.type && r.type === "string", [r] ); return { parse: c( (t) => new Promise((n, a) => { f(t, { // If the items are not strings, let papaparse guess the type. Otherwise, always parse as strings. dynamicTyping: !o, complete: (e) => { e.errors.length > 0 ? a(new g(e.errors)) : n(e.data.flat()); } }); }), [o] ) }; } export { g as UseParseCsvError, d as default }; //# sourceMappingURL=useParseCsv.js.map