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

reader-files

v1.0.4

Published

This Angular Module allows you to read and parse CSV and JSON file(s)

Downloads

3

Readme

Reader-Files

This Angular Module allows you to read and parse CSV files based on object type yu provided and JSON files. This service cna read single and batch files.

For multiple CSV files it merges the data <T[]> into one observable For multiple json files it provides an array with { file : string, data: any }

NOTE: If you are using multiple instances of this class to read files, extend the class of the complent and add the type of the object and do not import it as a dependency into the class of the component.

For CSV files there are 2 options for the object that is defined

  1. If parseAsObject is FALSE, then the returned data will be a array[]

  2. If parseAsObject is TRUE, then the returned data will be an object defined by the header (firstline of data) data will be array[T]

Option 1:

["Government of Canada",Canada,CA,Ontario,ON,K1A],
["Government of Canada",Canada,CA,Ontario,ON,K1A]

Option 2:

[
  { city: "Government of Canada", country: "Canada', country_abbr: "CA", region: "Ontario", region_abbr: "ON",zip: "ON,K1A" },
  { city: "Government of Canada", country: "Canada', country_abbr: "CA", region: "Ontario", region_abbr: "ON",zip: "ON,K1A" }
]

File Strtcture for CSV

Your first line should define the model of the data

Installation

npm install reader-files

Scaffolding

Import the module into your project under imports

imports: [
    BrowserModule,
    AppRoutingModule,
    ReaderFilesModule,
  ],

Use

In your component file, import the module in the constructor and add the generic type

private readerParser: ReaderFileParserService<CountryRegionCity>,

Then call any of the functions, like the eample below

const file = 'assets/data/united-states.csv'
this.dataTextFile = this.readerParser.readCSVFile(file, true)

Here is a sample of a component setup

export class AppComponent implements OnInit {

  dataTextFile: Observable<CountryRegionCity[]>
  dataTextFiles: Observable<CountryRegionCity[]>

  dataJsonFile: any
  dataJsonFiles: any

  constructor(
    private readerParser: ReaderFileParserService<CountryRegionCity>
    ) {}

  ngOnInit() {

    const file = 'assets/data/united-states.csv'
    const files = ['assets/data/canada.csv', 'assets/data/united-states.csv']

    const jsonFile = 'assets/data/sample-1.json'
    const jsonFiles = ['assets/data/sample-1.file.service.json', 'assets/data/sample-2.json']

    this.dataTextFile = this.readerParser.readCSVFile(file, true)
    this.dataTextFiles = this.readerParser.readCSVFiles(files, true)

    this.dataJsonFile = this.readerParser.readJSONFile(jsonFile)
    this.dataJsonFiles = this.readerParser.readJSONFiles(jsonFiles)

    console.log(this.dataJson)

  }

}