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

unified-doc-parse-csv

v0.2.1

Published

unified-doc parser to parse csv into a hast table node (RFC-4180 compliant)

Downloads

44

Readme

unified-doc-parse-csv

unified-doc parser to parse csv content into a hast table node (RFC-4180 compliant).

Install

npm install unified-doc-parse-csv

Use

Given some RFC-4180 compliant CSV content, parse into a hast table with semantic table, tbody, tr, td nodes

import csv from "unified-doc-parse-csv";
import unified from "unified";

const content = 'row0col0,row0col1,row0col2\nrow1col0,row1col1,row1col2';

const processor = unified().use(csv);

expect(processor.parse(content)).toEqual({
  type: 'element',
  tagName: 'table',
  properties: {},
  children: [
    {
      type: 'element',
      tagName: 'tbody',
      properties: {},
      children: [
        {
          type: 'element',
          tagName: 'tr',
          properties: {},
          children: [
            {
              type: 'element',
              tagName: 'td',
              properties: {},
              children: [
                {
                  type: 'text',
                  value: 'row0col0',
                  position: {
                    start: {
                      line: 1,
                      column: 1,
                      offset: 0,
                    },
                    end: {
                      line: 1,
                      column: 9,
                      offset: 8,
                    },
                  },
                },
              ],
              position: {
                start: {
                  line: 1,
                  column: 1,
                  offset: 0,
                },
                end: {
                  line: 1,
                  column: 9,
                  offset: 8,
                },
              },
            },
            {
              type: 'element',
              tagName: 'td',
              properties: {},
              children: [
                {
                  type: 'text',
                  value: 'row0col1',
                  position: {
                    start: {
                      line: 1,
                      column: 10,
                      offset: 9,
                    },
                    end: {
                      line: 1,
                      column: 18,
                      offset: 17,
                    },
                  },
                },
              ],
              position: {
                start: {
                  line: 1,
                  column: 10,
                  offset: 9,
                },
                end: {
                  line: 1,
                  column: 18,
                  offset: 17,
                },
              },
            },
            {
              type: 'element',
              tagName: 'td',
              properties: {},
              children: [
                {
                  type: 'text',
                  value: 'row0col2',
                  position: {
                    start: {
                      line: 1,
                      column: 19,
                      offset: 18,
                    },
                    end: {
                      line: 1,
                      column: 27,
                      offset: 26,
                    },
                  },
                },
              ],
              position: {
                start: {
                  line: 1,
                  column: 19,
                  offset: 18,
                },
                end: {
                  line: 1,
                  column: 27,
                  offset: 26,
                },
              },
            },
          ],
          position: {
            start: {
              line: 1,
              column: 1,
              offset: 0,
            },
            end: {
              line: 1,
              column: 27,
              offset: 26,
            },
          },
        },
        {
          type: 'element',
          tagName: 'tr',
          properties: {},
          children: [
            {
              type: 'element',
              tagName: 'td',
              properties: {},
              children: [
                {
                  type: 'text',
                  value: 'row1col0',
                  position: {
                    start: {
                      line: 2,
                      column: 1,
                      offset: 27,
                    },
                    end: {
                      line: 2,
                      column: 9,
                      offset: 35,
                    },
                  },
                },
              ],
              position: {
                start: {
                  line: 2,
                  column: 1,
                  offset: 27,
                },
                end: {
                  line: 2,
                  column: 9,
                  offset: 35,
                },
              },
            },
            {
              type: 'element',
              tagName: 'td',
              properties: {},
              children: [
                {
                  type: 'text',
                  value: 'row1col1',
                  position: {
                    start: {
                      line: 2,
                      column: 10,
                      offset: 36,
                    },
                    end: {
                      line: 2,
                      column: 18,
                      offset: 44,
                    },
                  },
                },
              ],
              position: {
                start: {
                  line: 2,
                  column: 10,
                  offset: 36,
                },
                end: {
                  line: 2,
                  column: 18,
                  offset: 44,
                },
              },
            },
            {
              type: 'element',
              tagName: 'td',
              properties: {},
              children: [
                {
                  type: 'text',
                  value: 'row1col2',
                  position: {
                    start: {
                      line: 2,
                      column: 19,
                      offset: 45,
                    },
                    end: {
                      line: 2,
                      column: 27,
                      offset: 53,
                    },
                  },
                },
              ],
              position: {
                start: {
                  line: 2,
                  column: 19,
                  offset: 45,
                },
                end: {
                  line: 2,
                  column: 27,
                  offset: 53,
                },
              },
            },
          ],
          position: {
            start: {
              line: 2,
              column: 1,
              offset: 27,
            },
            end: {
              line: 2,
              column: 27,
              offset: 53,
            },
          },
        },
      ],
    },
  ],
  position: {
    start: {
      line: 1,
      column: 1,
      offset: 0,
    },
    end: {
      line: 2,
      column: 27,
      offset: 53,
    },
  },
});

API

unified().use(content[, options])

Interface

function parse(
  /** Configurable options (compatible with tdast-util-from-csv's options) */
  options?: Options
): void;

hast parser to parse csv content into a hast table node (RFC-4180 compliant).

Use the parser with any unified processor. Implemented with tdast-util-from-csv and tdast-util-to-hast-table.

Related interfaces

interface Options {
  // if the first row of the CSV contains header values
  header?: boolean;
}