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

nestly

v0.2.0

Published

Create structured data from tabular input with JSON and YAML literals

Downloads

9

Readme

nestly

This is a Node module and command line tool for creating structured data from tabular input using a declarative "meta-structure" in JSON or YAML, which looks something like this:

values:
  '{x}':
    '{y}': '{z}'

In a meta-structure, any object key with { and } markers becomes a nesting point for your data. Everything else (such as the top-level values key) is preserved as-is. In the case above, the tabular input would be assumed to have columns named x, y, and z. The other implicit assumption is that there is only one unique value of z for each permutation of x and y. So, if you had some CSV data like this:

x,y,z
a,a,2
a,b,3
b,a,1
b,b,5

Then nestly would combine the above meta-structure and data to create the following output in YAML:

values:
  'a':
    'a': '2'
    'b': '3'
  'b':
    'a': '1'
    'b': '5'

Command line interface

The nestly command line tool works like this:

nestly [--config file | filename] data-filename [-o | output-filename]

Options:
  --cf          The format of the config file: "json" or "yaml"
                                                       [default: "json"]
  --if          The format of the input data: "csv", "tsv", "json", or
                "yaml"
  --of          The format of the output data: "json" or "yaml"
                                                       [default: "json"]
  -c, --config  The path to your nesting configuration file
  -i, --in      The path of your input data file
  -o, --out     The name of the ouput file
  -h, --help    Show this help screen

The config should be a JSON or YAML file that encodes the "meta-structure" described above. If you don't provide the --if (input format) and --of (output format) options, then the formats are inferred from the filenames. (You should provide the format options if you're piping to or from stdio.) The above output would be generated with:

nestly --config structure.yml xyz.csv -o nested.yml

What problem does this solve?

I made it to ease the incorporation of data into Jekyll projects, where tabular formats can be tricky to work with. For instance, let's say you have some data in a spreadsheet like this:

City | Year | Population :--- | :--- | ---: San Diego | 2012 | 1,337,000 San Diego | 2013 | 1,356,000 San Francisco | 2012 | 827,420 San Francisco | 2013 | 837,442 San Jose | 2012 | 982,579 San Jose | 2013 | 998,537

If I wanted to get the population for a particular city and year in a template, I would need to do something funky like this:

{% assign row = site.data.cities | where: 'City', city | where: 'Year': year | first %}
{{ row.Population }}

But if we generated data with a structure like this:

'{City}':
  population:
    '{Year}': '{Population}'

Then getting the population for a city becomes:

{{ site.data.cities[city].population[year] }}