# ngx-file-parser

> Simple Angular component to parse CSV, JSON files

Latest version **1.0.7** (published 2020-06-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install ngx-file-parser
pnpm add ngx-file-parser
yarn add ngx-file-parser
bun add ngx-file-parser
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.7 |
| Published | 2020-06-06 |
| First published | 2020-06-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 264.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | https://fore.dev \| Rasmus Brants |
| Maintainers | brantsrasmus |
| Keywords | angular, javascript, typescript, component, angular-material, csv, json, parser, file, file-parser, simple, config |

## Links

- npm: https://www.npmjs.com/package/ngx-file-parser
- Repository: https://github.com/foredev/ngx-file-parser
- Issues: https://github.com/foredev/ngx-file-parser/issues
- npm.io page: https://npm.io/package/ngx-file-parser

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^1.10.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.7 (latest) — 2020-06-06
- 1.0.6 — 2020-06-06
- 1.0.5 — 2020-06-06
- 1.0.4 — 2020-06-06
- 1.0.3 — 2020-06-06
- 1.0.2 — 2020-06-05
- 1.0.1 — 2020-06-05

## README

# ngx-file-parser

[![npm version](http://img.shields.io/npm/v/ngx-file-parser.svg?style=flat)](https://npmjs.org/package/ngx-file-parser)

Simple component to parse files with extensions

- CSV
- JSON

To be implemented: XML....

See [demo](https://ngx-file-parser.web.app/)

## Dependencies

- [Angular](https://angular.io) >= 9.1.9
- [Angular Material](https://material.angular.io/) >= 9.2.4

## Installation

#### 1.

NPM:
`npm install ngx-file-parser --save`

Yarn:
`yarn add ngx-file-parser`

#### 2.

Import the `NgxFileParserModule` to provide the necessary components and directives.

```ts
import { NgxFileParserModule } from 'ngx-file-parser';

@NgModule({
  ...
  imports: [ NgxFileParserModule ],
  ...
})
export class AppModule { }
```

## Usage

Declare NgxFileParserConfig object to provide to the directive

#### `NgxFileParserConfig` has the following properties

| Property           | Description                                                                     | Default     |
| ------------------ | ------------------------------------------------------------------------------- | ----------- |
| btnText            | Text to be displayed on button                                                  | Choose file |
| btnIcon            | Material icon to be displayed on button                                         | backup      |
| btnColor\*         | Color accent to the button                                                      | transparent |
| accepts            | Array of file name extensions                                                   | ['.csv']    |
| csvNamedProperties | If parsed CSV file should be returned as array of objects with named properties | false       |

\*See [Angular Material buttons for accents](https://material.angular.io/components/button/overview)

# Example

```ts
import { NgxFileParserConfig } from "ngx-file-parser";

ngxFileParserConfig: NgxFileParserConfig = {
  btnText: "Upload",
  btnIcon: "backup",
  btnColor: "primary",
  accepts: [".csv"],
  csvNamedProperties: true,
};
```

Use the ngx-file-btn directive and provide the needed config object and event listener function to handle the parsed object

```html
<ngx-file-btn
  [(config)]="ngxFileParserConfig"
  (parsedFile)="handleParsedFile($event)"
></ngx-file-btn>
```

#### `ngx-file-btn` has the following output events

| Event      | Description                    | Type       |
| ---------- | ------------------------------ | ---------- |
| parsedFile | The result of the parsed file. | INgxResult |
| processing | If the file is being processed | boolean    |

```ts
export interface INgxResult {
  extension: string;
  result: INgxCsv | INgxJson | INgxComplexCsv;
}
```

# Returns

All parsed object is returned as INgxResult with the extension of the file and a result object and is emitted to this event listener with the \$event containing the parsed object

```ts
  handleParsedFile(parsedFileObj: INgxResult) {
    this.parsedFile = parsedFileObj.result as INgxCsv | INgxJson | INgxComplexCsv;
  }
```

## CSV

Returns the interface `INgxCsv` with properties
| Property | Description |
| -------- | ----------------|
| headers | Array of strings |
| data | Array of arrays of string |

## CSV Named Properties

Returns the interface `INgxComplexCsv` with properties
| Property | Description |
| -------- | ----------------|
| [key: string]: string; | Property as definied in the upload CSV |

## JSON

Returns the interface `INgxJson` with the properties that are definied in the upload JSON file

# Contribute

All PR's, issues and contributors are welcome! Feel free to start contributing

## License

MIT

---
_Source: https://npm.io/package/ngx-file-parser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
