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

csvtoflatfile

v3.0.0

Published

Converts a csv to a Flatfile

Downloads

40

Readme

CsvtoFlatfile

CsvtoFlatfile is a fast an easy way to convert your csv into a Flatfile. It fully supports all available customization options allowing you full control over your data.

It serves as an auto-map alternative when you know exactly what you want your data to look like.

Downloads

Notes

  • csvtoflatfile is a Node.js ECMAScript modules (ESM) library.

  • Non-essential fields are automatically generated if not provided.

Installation

Follow these steps to install and use csvtoflatfile in your project:

  1. Install the package via npm:
npm install csvtoflatfile
  1. Import the package
import { convertCsvToWorkbook, createFlatfile } from 'csvtoflatfile'; // or import csvtoflatfile from 'csvtoflatfile';

Basic Usage

import { readFile } from "fs/promises";
import { convertCsvToWorkbook, createFlatfile } from 'csvtoflatfile';

const generateFlatfile = async () => {
    const importedCsv: string = await readFile("./yourData.csv", 'utf8');

    // create a workbook
    const { workbook, recordData } = convertCsvToWorkbook({
      workbookName: "Zillow", // the name of your newly created workbook
      csvConfigs: [{
        csv: importedCsv, // your csv file
        hasColumnHeaders: true, // whether or not your csv data includes headers
        sheetName: 'Cool Sheet #1' // the sheet name for your data
      }]
    });


    // optionally, modify/customize your data. Any Flatfile supported record keys are supported.
    // In this case we'll add a warning message when the number of floods exceeds 11.
    const zillowRecords = recordData[0];
    const modifiedRecordData = zillowRecords.map((parsedWeatherData) => {
        return parsedWeatherData.map((weatherData) => {
            // add a warning when floods exceed 11
            const floodsExceedsEleven = (Number(weatherData.value) > 11 && weatherData.header === 'Flood';
            if (floodsExceedsEleven) return {
                ...weatherData, messages: [{
                    type: "warn",
                    message: "That's a lot of flooding!"
                }]
            }
            return { ...weatherData, updatedAt: new Date().toISOString() }; // you can also insert custom record data fields here that will be inserted into the flatile!
        });
    });

    // create the Flatfile
    const flatfile = await createFlatfile({ workbook,
      recordDataList: [modifiedRecordData], flatfileApiKey: process.env?.flatfile ?? ''
    });
    return flatfile; // Flatfile contains the flatfile and record creation response
}

Result

image

Multiple Files

const generateFlatfile = async () => {
    const zillowData = await readFile("./testData/zillow.csv", 'utf8');;
    const nileData = await readFile("./testData/nile.csv", 'utf8');
    const treeData = await readFile("./testData/trees.csv", 'utf8');

    const data = convertCsvToWorkbook({
        workbookName: "Workbook",
        workbookSpaceId: "space1",
        csvConfigs: [
          { csv: zillowData, hasColumnHeaders: true, sheetName: 'Zillow' },
          { csv: nileData, hasColumnHeaders: true, sheetName: 'The Nile' },
          { csv: treeData, hasColumnHeaders: true, sheetName: 'Trees' }
        ]
    });

    const flatfile = await createFlatfile({
      workbook: data.workbook,
      recordDataList: data.recordData,
      flatfileApiKey: process.env?.flatfile ?? ''
    });
    return flatfile;
}

Result

image

Advanced Usage

🚧 Demo code coming soon. See demo/example.ts for more advanced usage.

Roadmap

The csvtoflatfile project is currently under active development, but the core functionality has been added (#1 & #2). Here's the current roadmap:

  1. CSV to Workbook Conversion: ✔️ Complete!

  2. File Upload / Record insertion: ✔️ Complete!

  3. Add multiple sheets on initial Flatfile creation ✔️ Complete!

  4. Append new sheets to existing Flatfiles 🚧 Work In Progress.

  5. Automap integration https://flatfile.com/docs/plugins/automations/automap