npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ngx-rich-json-csv-parser

v1.0.0

Published

convert JSON to CSV file and Download it in the .csv format for your Angular project

Downloads

23

Readme

ngx-rich-json-csv-parser

Ngx-rich-json-csv-parser help you to convert JSON to CSV file and Download it in the .csv format.

Features

  1. Convert JSON to CSV
  2. Download JSON data in CSV format file.
  3. Insert serial number
  4. Customize CSV file Header text
  5. Sort the CSV file data based on Header text
  6. Customize CSV file name

Installation

Start by installing the Angular Rich JSON CSV Parser library from npm

npm i -s ngx-rich-json-csv-parser

Next, you'll need to import the NgxRichJsonCsvParserModule module in your app's module.

app.module.ts


import { NgxRichJsonCsvParserModule } from 'ngx-rich-json-csv-parser';
...

@NgModule({
    ...
    imports: [NgxRichJsonCsvParserModule],
    ...
});

Next, To consume this library, create a instance of this library service in component ts file. eg csv-download-example.component.ts

import { Component } from '@angular/core';
import { HeaderCaseMode, HeaderSortMode, NgxRichJsonCsvParserService } from 'ngx-rich-json-csv-parser';
...

export class CSVDownloadExampleComponent {

  jsonData = []; //your JSON data to convert CSV
  constructor(private _ngxRichJsonCsvParserService: NgxRichJsonCsvParserService) {

  }
  download() { // Sample function to covert JSON data to CSV and download CSV file 
    this._ngxRichJsonCsvParserService.downloadFile(this.jsonData, [], true, 'test', 'mySl', SortMode.DESC, HeaderCaseMode.StartCase);
  }
}

Usages and API details

To download JSON data as a CSV file format, use downloadFile() function, eg:

this._ngxRichJsonCsvParserService.downloadFile(<Your JSON Data>,<Custom Header List>,<show Serial Number(boolean)>,<Your CSV File Name>,< your Serial Number Header Name>, < Sort Header list>,<Format your CSV headers text cases> );

Argument Details

| Order | Name | Type | Details | |------: |--------------------------------------------: |--------------------: |----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | | 1 | JSON Data | An array of objects | JSON data which is used to convert into CSV | | 2 | Custom Header | An array of String | You can provide custom csv header name, please note number of element in this header array should be equal to number of property in single JSON array object data | | 3 | isAutoGenerateSlNo(IsGenerateSerial Number) | Boolean | This flag is used to generate Numerical serial number start from 1 | | 4 | CSV File Name | string | Your custom CSV file name | | 5 | Serial Number header name | string | If isAutoGenerateSlNo is true then you can provide custom header for Serial number | | 6 | Sort CSV Header list | enum | To sort CSV Header list, available options are- without Sorting : HeaderSortMode.NONE- to sort ascending order: HeaderSortMode.ASC- to sort descending order: HeaderSortMode.DESC | | 7 | Header Text format | enum | To format CSV all header text to uppercase or lowercase or capitalize or startcase(title case)eg: HeaderCaseMode.StartCase |

this._ngxRichJsonCsvParserService.downloadFile(jsonData, [], true, 'test', 'mySl', SortMode.DESC, HeaderCaseMode.StartCase); //example

To convert JSON to CSV data format without downloading, use ConvertToCSV() function, eg:

this._ngxRichJsonCsvParserService.ConvertToCSV(this.jsonData, [], true, 'mySl', HeaderSortMode.DESC, HeaderCaseMode.StartCase); // this function returns csv data
Argument details

| Order | Name | Type | Details | |:-----: |:-------------------------------------------: |:-------------------: |:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | | 1 | JSON Data | An array of objects | JSON data which is used to convert into CSV | | 2 | Custom Header | An array of String | You can provide custom csv header name, please note number of element in this header array should be equal to number of property in single JSON array object data | | 3 | isAutoGenerateSlNo(IsGenerateSerial Number) | Boolean | This flag is used to generate Numerical serial number start from 1 | | 4 | Serial Number header name | string | If isAutoGenerateSlNo is true then you can provide custom header for Serial number | | 5 | Sort CSV Header list | enum | To sort CSV Header list, available options are- without Sorting : HeaderSortMode.NONE- to sort ascending order: HeaderSortMode.ASC- to sort descending order: HeaderSortMode.DESC | | 6 | Header Text format | enum | To format CSV all header text to uppercase or lowercase or capitalize or startcase(title case)eg: HeaderCaseMode.StartCase |

const c = this._ngxRichJsonCsvParserService.ConvertToCSV(this.jsonData, [], true, 'mySl', HeaderSortMode.DESC, HeaderCaseMode.StartCase);
console.log(c) //example

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT