Coder Social home page Coder Social logo

alberthaff / ngx-papaparse Goto Github PK

View Code? Open in Web Editor NEW
91.0 4.0 20.0 4.26 MB

Papa Parse wrapper for Angular

Home Page: https://alberthaff.dk/projects/ngx-papaparse/docs/v8

License: MIT License

JavaScript 8.46% TypeScript 91.54%
csv csv-parser papaparse angular angular4 ngx-papapa ngx-papaparse converts workers multithreading

ngx-papaparse's People

Contributors

alberthaff avatar amiram avatar anikets43 avatar dependabot[bot] avatar foohyfooh avatar joaquimgamero avatar paulstelzer avatar pburgmer avatar reigelj avatar rodrigowbazevedo avatar tiagomsmagalhaes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ngx-papaparse's Issues

Create docs in GitHub repo

The docs should be placed in /docs/index.md in each version's branch.

Versions:

  • Version 1
  • Version 2
  • Version 3

transformHeader

Feature Request

I would like to see the transformHeader configuration property supported by this component. This feature is useful for trimming off pesky white space between commas in the header row, in addition to formatting headers in other ways or performing fuzzy matching on them before getting the output back from Papa.

See the PapaParse docs for a complete description of config.transformHeader.

Expected behavior

I would like to provide a function to configuration which accepts the header as an argument and returns a string to be used in place of that header so that I can trim white space, performing matching, etc. with the headers. This function should work precisely as config.transformHeader works in PapaParse.

Error: Can't resolve 'papaparse/papaparse.min.js' wiht ngx-papaparse@6

Describe the bug

Today I upgraded ngx-papaparse to version 6.0 and then my build failed with error message:

./node_modules/ngx-papaparse/fesm2020/ngx-papaparse.mjs:3:0-50 - Error: Module not found: Error: Can't resolve 'papaparse/papaparse.min.js' in '/path/to/project/node_modules/ngx-papaparse/fesm2020'

Papaparse was not added as dependency in package.json because it was not necessary with ngx-paparse@5.

Is it now necessary to add papaparse as dependency to use ngx-papaparse@6 ?

Config interface for unparse method should different from config for parse method

As documented at https://www.papaparse.com/docs#json-to-csv, config for parse method is different from config for unparse method.

For example, unparse config has quotes option, which does not exist in parse config.

This library, use PapaParseConfig interface for both parse and unparse method. This cause a compile error when I try to pass {quotes: true} as config parameter for unparse.

this.papa.unparse(data, {quotes: true});

I think we can fix this problem by providing different inteface for parse and unparse.

RenamedHeaders not present in metadata

Describe the bug

Trying to parse a csv with duplicate column names and config header: true will rename duplicate headers but will not add the information in the meta properties of the parse result.

To Reproduce

Please provide the necessary steps to reproduce the unwanted behaviour.

this.papa.parse(file, {
        worker: true,
        header: true,
        skipEmptyLines: true,
        complete: (results: ParseResult<{[key: string]: string}[]>) => {
             console.log(results);
        }
}

Expected behavior

According to the documentation, I should see something in ParseResult.meta.renamedHeaders

Software and platform

  • OS: Windows 10
  • Browser: Chrome
  • Version: 118.0.5993.70
  • Angular version: 16.1.8
  • Angular CLI version: 16.1.8
  • Node version: 16.14.2

Additional context

I'm using ngx-papaperse v8.0.0

Parameter 'a' implicitly has an 'any' type.

ngx-papaparse- 1.2.2
node - v6.9.1
npm- 5.0.4
angular- 4.2.6
typescript- 2.3.4

C:/USA/Intranet/Client/node_modules/ngx-papaparse/dist/lib/papaparse.interface.d.ts(45,28): error TS7006: Parameter 'b' implicitly has an 'any' type.

Enabled serviceworkers, but page still freezes while CSV file is being parsed

Describe the bug

When enabling serviceworkers by setting the according flag to true, the CSV data is correctly parsed, but the page UI completely freezes until parsing is finished. So, the behaviour is the same as wehen setting the workers flag to false.

To Reproduce

  1. Add the following to the "assets" array inside angular.json:
{
  "glob": "**/papaparse.min.js",
  "input": "./node_modules/papaparse",
  "output": "/assets/"
}
  1. Adding the folowing to the "providers" array inside the app.module.ts:
{
  provide: 'PapaParseGlobalConfig',
  useValue: <PapaParseGlobalConfig>{
    scriptPath: '/assets/papaparse.min.js'
  }
}
  1. Create a file object from existing blob and use the papa.parse method as follows:
const csvData = new File([blob], fileName);
this.papa.parse(csvData,
  {
      fastMode: true,
      worker: true,
      delimiter: ';',
      header: true,
      complete: (results, file) => {
        some post logic...
        ...  
      }
    }
  }
);

Expected behavior

If the workers flag is set to true the page should stay reactive, while CSV data is parsed, as described in the docs:

Using a worker will keep your page reactive, but may be slightly slower. 
Note that worker option is only available when parsing files and not when converting from JSON to CSV. 

Software and platform

  • OS: Windows 10
  • Browser: Chrome
  • Version: 103.0.5060.134
  • Angular version: 7
  • Angular CLI version: 7.3.9
  • Node version: 16.5.0

Additional context

Add any other context about the problem here.

Result as Observable

I'd like to have some way to return the response as an async observable, I think it's possible using the step callback.

I'll fork and look the project, and try to create a PR.

Any suggestions?

Move docs to website

  • Docs for version 1.x (Angular 2 / 4)
  • Docs for version 2.x (Angular 5)
  • Docs for version 3.x (Angular 6)
  • Fix scrolling error
  • Do not change the URL multiple times while scrolling

Angular 4.4.6

ERROR in Error: Metadata version mismatch for module D:/admin/node_modules/ngx-papaparse/ngx-papaparse.d.ts, found version 4, expected 3, resolving symbol AppModule in D:/admin/src/app/app.module.ts, resolving symbol AppModule in D:/admin/src/app/app.module.ts
    at Error (native)
    at syntaxError (D:\admin\node_modules\@angular\compiler\bundles\compiler.umd.js:1729:34)
    at simplifyInContext (D:\admin\node_modules\@angular\compiler\bundles\compiler.umd.js:24979:23)
    at StaticReflector.simplify (D:\admin\node_modules\@angular\compiler\bundles\compiler.umd.js:24991:13)
    at StaticReflector.annotations (D:\admin\node_modules\@angular\compiler\bundles\compiler.umd.js:24418:41)
    at _getNgModuleMetadata (D:\admin\node_modules\@angular\compiler-cli\src\ngtools_impl.js:138:31)
    at _extractLazyRoutesFromStaticModule (D:\admin\node_modules\@angular\compiler-cli\src\ngtools_impl.js:109:26)
    at Object.listLazyRoutesOfModule (D:\admin\node_modules\@angular\compiler-cli\src\ngtools_impl.js:53:22)
    at Function.NgTools_InternalApi_NG_2.listLazyRoutes (D:\admin\node_modules\@angular\compiler-cli\src\ngtools_api.js:91:39)
    at AotPlugin._getLazyRoutesFromNgtools (D:\admin\node_modules\@ngtools\webpack\src\plugin.js:212:44)
    at _donePromise.Promise.resolve.then.then.then.then.then (D:\admin\node_modules\@ngtools\webpack\src\plugin.js:448:24)
    at process._tickCallback (internal/process/next_tick.js:109:7)

webpack: Failed to compile.

any guess what happended?

Switch to Angular-librarian

Switch to Angular-librarian for compilation.

  • Rewrite module (with provider).
  • Write examples
  • Update the description, author and tags in package.json

Preserve a leading zero

I have an import file

code,from,to
IMSF01,0700,2200

but after import (code below), i noticed the console log showing 'from' node is storing 700 (number) instead of 0700 (string)

this.papa.parse($event.srcElement.files[0], {
  header: true,
  dynamicTyping: true,
  skipEmptyLines: "greedy",
  worker: true,
  complete: (result, file) => {
      // BUG! imported 0700 became 700
    console.log(result);
    this.importData = result.data;
  }
})

Is there any any config i can turn on to preserve the leading zeros?

Assign CSV results while complete callback triggered, but results are blank

I have my "complete" callback assigned results to a component level varible
...

  parseCsvFile(file) {
    this.papa.parse(file, {
      header: true,
      dynamicTyping: true,
      skipEmptyLines: "greedy",
      worker: true,
      complete: this.onPapaParseComplete
    });
  }

   onPapaParseComplete(results) {
    console.log("Completed Results", results);
    this.rosterCSVData = results.data
...
  onUploadRoster() {
    console.log(this.rosterCSVData) ===> NULL
  }
}

I import file and confirmed the data in csv. But later call onUploadRoster(), the result is blank. How come?

Entry point 'ngx-papaparse' contains deep imports using Angular 9

Describe the bug

A clear and concise description of what the bug or problem is.
Everytime i run ng serve there is this warning that displays saying Entry point 'ngx-papaparse' contains deep imports into

To Reproduce

Please provide the necessary steps to reproduce the unwanted behaviour.
Previously, I added this package to an Angular 6 Project in stackblitz here for testing purposes only.

Version of ngx-papaparse - 2.1.0
Version of Angular - 6.0.0

Expected behavior

A clear and concise description of what you expected to happen.
I want to fixed this warning though it says that it is not a problem but I'm concern if this will continue to display when I run ng serve in the future, I'm currently in Angular 9.

Software and platform

  • OS: Linux
  • Browser: Chrome
  • Version: Version 84.0.4147.105 (Official Build) (64-bit)
  • Angular version: 9.0.7
  • Angular CLI version: 9.0.7
  • Node version: 12.19.0

Additional context

Add any other context about the problem here.
I've search several related topics about this, and the common answer is to ignore because it's not a major problem but I'm not satisfied of this.

Any clarification would be helpful. I'm not really sure if this thing must be taken seriously or not at all. Thanks.

complete callback has wrong signature

Describe the bug

The complete callback has the following signature is PapaParseConfig

complete?: (results: PapaParseResult, parser: PapaParseParser) => void;

but Papa Parse actually calls with the results and a File object if parsing a local file.

This causes type errors when using this callback and the only workaround I found was to define a complete callback specifying the type of the second argument as any, e.g.

complete: (results, file: any) => {}

The signature for step looks correct, I'm not sure about chunk.

An accessor cannot be declared in an ambient context.

Describe the bug

The compilation error occurs because there are some lines that typescript detects:
An accessor cannot be declared in an ambient context.

The errors are in node_modules/ngx-papaparse/lib/papa.de.ts, in the lines:

  • 32: 9 - TS1086 error
  • 37: 9 - TS1086 error
  • 41: 9 - error TS1086
  • 46: 9 - TS1086 error

To Reproduce

The error occurs when compiling the angular project

ng serve

Expected behavior

hope it compiles correctly, no errors

Software and platform

  • OS: Ubuntu 20.04
  • Browser: Google Chrome 91.0.4472.114
  • Version: 5
  • Angular version: 12
  • Angular CLI version: 12.0.4
  • Node version: 14.17.2

Additional context

Although it is not a good practice, the problem can be solved by adding to the tsconfig.ts file, in compilerOptions the line: "skipLibCheck": true, and now, TypeScript allows me to use the library as long as I do not use the incompatible parts or with

Angular 10 - unable to install

I tried installing with the following command from the readme instructions:
npm install ngx-papaparse@5 --save
However I got the following error:

npm ERR! code ETARGET
npm ERR! notarget No matching version found for ngx-papaparse@5.
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.

So, I went down to 4, which installs without any issue:
npm install ngx-papaparse@4 --save

However, I cannot actually use the library in my project (in app.module.ts):
import { PapaParseModule } from 'ngx-papaparse';
Results in the this error:
Module '"../../node_modules/ngx-papaparse/ngx-papaparse"' has no exported member 'PapaParseModule'.ts(2305)

ERROR in node_modules/ngx-papaparse/lib/papa.d.ts:5:22

Cannot use ngx-papaparse with angular 9+
Already ran npm install [email protected]

ERROR in node_modules/ngx-papaparse/lib/papa.d.ts:5:22 - error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class.

This likely means that the library (ngx-papaparse) which declares Papa has not been processed correctly by ngcc, or is not compatible with Angular Ivy. Check if a newer version of the library is available, and update if so. Also consider checking with the library's authors to see if the library is expected to be
compatible with Ivy.

5 export declare class Papa {

Please update for Angular 9

Describe the bug

I'm getting this warning while installing packages on my app that's recently been updated to Angular 9:

Entry point 'ngx-papaparse' contains deep imports into '.../node_modules/papaparse/papaparse.min.js'. This is probably not a problem, but may cause the compilation of entry points to be out of order.

To Reproduce

Install current ngx-papaparse on a new or upgraded Angular 9 project

Expected behavior

No warnings or errors

Software and platform

  • OS: Ubuntu 19.10
  • Browser: any
  • Version: any
  • Angular version: 9.1.1
  • Angular CLI version: 9.1.1
  • Node version: 12.16.2

Additional context

Please update for Angular 8

Describe the bug

I'm getting this error while installing packages on my app that's recently been updated to Angular 8:

npm WARN [email protected] requires a peer of @angular/common@^6.0.0 || ^7.0.0 but none is installed. You must install peer dependencies yourself.

To Reproduce

Install current ngx-papaparse on a new or upgraded Angular 8 project

npm install ngx-papaparse --save

Expected behavior

No warnings or errors

Software and platform

  • OS: Windows 10
  • Browser: Chrome
  • Version: 74.0.3729.169
  • Angular version: 8.0.0 / 8.0.2
  • Angular CLI version: 8.0.3
  • Node version: 12.4.0

Angular 15 Ivy Engine

This is just a suggestion:

After updating an Angular Project from v14 to v15 I get the following warning:

Processing legacy "View Engine" libraries:
- ngx-papaparse [es2015/esm2015] (https://github.com/alberthaff/ngx-papaparse)
Encourage the library authors to publish an Ivy distribution.

As detailed here, Ivy is going to be the only available Engine for Angular.

In your application's tsconfig.json file, remove enableIvy. In v15, Ivy is the only rendering engine so enableIvy is not required.

It is possible that in future versions of Angular this will cause some errors.

Start the header at a specific row number.

Describe the bug

A clear and concise description of what the bug or problem is.
The documentation tells that if you set the option "header" to true, the first row will be interpreted as field names, however in my case, the header of CSV file starts at row number 3.

To Reproduce

Please provide the necessary steps to reproduce the unwanted behaviour.
This is the screen shot for my CSV file (My personal trade history)
Screenshot_2020-10-13_14-48-34

Expected behavior

A clear and concise description of what you expected to happen.
So, generally I want to start the header at line 3 or maybe just ignore the first two lines. As I read the documentation there is an option called "comments" which is of type string, which skips the line whenever it encounters that comment (e.g "#" or "//") but these does not solve my issue.

Software and platform

  • OS: Windows 10
  • Browser: Google Chrome
  • Version: Version 84.0.4147.105 (Official Build) (64-bit)
  • Angular version: 9.0.7
  • Angular CLI version: 9.0.7
  • Node version: 13.3.0

Additional context

Thank you for providing this library which enable us to parse csv files easily.

Please publish v5 to npm

Version 5 is not published on npm yet.
Please publish this version because I am using Angular 9 and I need it.
Thanks.

Angular10 reports a CommonJS warning for PapaParse

Angular produces this message at the build. I can temporarily suppress it by adding an exception to angular.json file, but it would be nice to have the library properly packaged. Here's a link to Angular's documentation on CommonJS related issues: https://angular.io/guide/build#configuring-commonjs-dependencies

WARNING in /home/sergei/Projects/Angular/revenue-matters/node_modules/ngx-papaparse/__ivy_ngcc__/fesm2015/ngx-papaparse.js depends on 'papaparse/papaparse.min.js'. CommonJS or AMD dependencies can cause optimization bailouts.

Unit test for papa.parse

Papaparse and Unit Test

I have a method that is using parse from your module and I can't find a way to test this method.

Indeed, all my unit test expect are triggered before complete callback() (because of async).

I tried many things with jasmine : async... tick() ... but I can't find any solution.

Do you have any solution to wait 'complete callback()' in unit test?

Thank you for your help

Add support for papaparse 5.0.0

Papa parse 5.0.0 is out. Some features like transformHeader is really useful, do you mind add support for the latest version?

Metadata version mismatch in module?

I've been getting this error, possibly since a version change:

ERROR in Error: Metadata version mismatch for module /my/directories/node_modules/ngx-papaparse/ngx-papaparse.d.ts, found version 4, expected 3, resolving symbol RandomModule in /my/directories/src/app/modules/features/random/random.module.ts, resolving symbol RandomModule in /my/directories/src/app/modules/features/random/random.module.ts

The error disappears if I replace '"version":4' in ngx-papaparse.metadata.json with '"version":3'.

I'm not sure it's a problem with the module but I'm not really seeing what the error would be on my end either.

Missing export of PapaUnparseConfig type

Describe the bug

The exported class Papa has a method with signature

    unparse(data: any, config?: PapaUnparseConfig): string;

however the PapaUnparseConfig type is not exported from ngx-papaparse, making it impossible to pass a typed variable as parameter to unparse.

This parameter used to be of type PapaParseConfig which also used to be exported.

To Reproduce

import { Papa, PapaUnparseConfig } from 'ngx-papaparse'; // [ts] Module '".../ngx-papaparse"' has no exported member 'PapaUnparseConfig'. [2305]
...
class SomeClass {

  exportConfig: PapaUnparseConfig = {
    delimiter: ';',
    header: true,
    skipEmptyLines: true,
    newline: '\r\n',
    worker: true,
  };

...

  someFunction(...) {
    ...
    return this.papaParse.unparse(
      {
        fields: MY_CSV_COLUMNS,
        data: mydata,
      },
      this.exportConfig);
  }

Expected behavior

ngx-papaparse should export all types that the Papa class depends on.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.