0.4.0 • Published 2 years ago

react-dsv-import v0.4.0

Weekly downloads
76
License
MIT
Repository
github
Last release
2 years ago

react-dsv-import

Flexible, typed and easy to use React Component ⚛ to provide CSV, TSV and other delimiter-separated values formats (DSV) import functionality.

npm npm peer dependency version GitHub Maintainability Test Coverage

Demonstration

Getting started

Add the package with the package manager of choice to your project:

  • yarn: yarn add react-dsv-import
  • npm: npm install react-dsv-import
  • npx: npx -p react-dsv-import

TypeScript

import { DSVImport, ColumnsType } from 'react-dsv-import';

type BasicType = { forename: string; surname: string; email: string };

const columns: ColumnsType<BasicType> = [
  { key: 'forename', label: 'Forename' },
  { key: 'surname', label: 'Surname' },
  { key: 'email', label: 'Email' }
];

<DSVImport<BasicType> columns={columns}>
  <DSVImport.TextareaInput />
  <DSVImport.TablePreview />
</DSVImport>

JavaScript

import { DSVImport } from 'react-dsv-import';

const columns = [
  { key: 'forename', label: 'Forename' },
  { key: 'surname', label: 'Surname' },
  { key: 'email', label: 'Email' }
];

<DSVImport columns={columns}>
  <DSVImport.TextareaInput />
  <DSVImport.TablePreview />
</DSVImport>

API

The <DSVImport<T>> components has the following API:

PropertyTypeDescription
columnsColumnTypeDescription of the expected columns
transformers?Transformer[]Globally applied transformers
onChange?(value: T[]) => voidCallback which is called after parsing the input
onValidation?(errors: Error<T>[]) => voidCallback which is called if there are validation errors

Types

Within this section additional types are explained.

ColumnType

PropertyTypeDescription
keystringKey of the current column
labelstringLabel of the current column, which can be shown to the user
rules?Rule[]Validation rules which are applied to this column
transformers?Transformer[]Transformers which are applied to this column

Rule

PropertyTypeDescription
messagestringError message
contraint{ unique: boolean } \| { constraint:Constraint}Constraint for this rule

Constraint

(value: string) => boolean

Transformer

(value: string) => string

Project

This section describes the status of the project.

Features

The most important features of this component are:

  • ✅ Type definitions and type safety
  • ✅ DSV format detection
  • ✅ Fully compositable
  • ✅ Automatic testing with >90% coverage
  • ✅ Input validation
  • Ant Design integration (see storybook)
  • ✅ Input transformation (e.g. trim, ...)
  • Material UI integration (see storybook)

✅ means the feature is implemented and released. ❌ indicates that a feature is planned.

Links

Tools

Resources

0.3.11

2 years ago

0.4.0

2 years ago

0.3.9

3 years ago

0.3.7

4 years ago

0.3.6

4 years ago

0.3.5

4 years ago

0.3.4

4 years ago

0.3.3

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.0

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.5

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.1

4 years ago