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 🙏

© 2026 – Pkg Stats / Ryan Hefner

true-csv

v1.2.3

Published

Validate CSV headers and data row-by-row

Readme

true-csv

npm

🔍 A lightweight utility to validate CSV string content with custom rules for headers and fields.


📦 Installation

npm install true-csv

🚀 Usage

import { validateCSV } from 'true-csv';

const csv = `
Name,Email,Age
Saurabh,[email protected],25
John,john[at]email,16
Saurabh,[email protected],25
Saurabh,[email protected],25
saur,[email protected],20
`;

const result = validateCSV(csv, {
  headers: ["Name", "Email", "Age"],
  rules: {
    Name: { required: true },
    Email: { required: true, pattern: "^\\S+@\\S+\\.\\S+$" },
    Age: { required: true, type: "number", min: 18 }
  }
});

console.log(JSON.stringify(result, null, 2));

✅ API

validateCSV(csvString, options)

  • csvString: string
    Raw CSV content as a string.

  • options: object

    • headers: string[] – List of expected headers (column names).
    • rules: object – Validation rules for each field.

🔧 Rule Format

Each rule object can have the following:

  • required: boolean — Whether the field is required.
  • pattern: string — A regex pattern the field must match.
  • type: 'number' — Enforce that the field is a number.
  • min: number — Minimum value (if type is number).

📤 Output Structure

{
  headerValid: true | false,
  errors: [ 
    { row: 0, column: 'Header', message: '...' } 
  ],
  validRows: [ { Name: '', Email: '', Age: '' }, ... ],
  invalidRows: [ { row: 3, data: { ... } }, ... ]
}

🧪 Example Output

{
  "headerValid": true,
  "errors": [],
  "validRows": [
    { "Name": "Saurabh", "Email": "[email protected]", "Age": "25" },
    { "Name": "saur", "Email": "[email protected]", "Age": "20" }
  ],
  "invalidRows": [
    {
      "row": 3,
      "data": { "Name": "John", "Email": "john[at]email", "Age": "16" }
    },
    {
      "row": 4,
      "data": { "Name": "Saurabh", "Email": "[email protected]", "Age": "25" }
    },
    {
      "row": 5,
      "data": { "Name": "Saurabh", "Email": "[email protected]", "Age": "25" }
    }
  ]
}

🛠 Dev

Clone locally:

git clone https://github.com/your-username/csv-checker.git
cd csv-checker
npm install

Test locally:

node index.js

📄 License

MIT © 2025 Saurabh