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

gracenode-staticdata

v0.2.3

Published

staticdata module for gracenode framework

Downloads

6

Readme

Staticdata Module

Staticdata module for gracenode framework.

This is designed to function within gracenode framework.

How to include it in my project

To add this package as your gracenode module, add the following to your package.json:

"dependencies": {
        "gracenode": "",
        "gracenode-staticdata": ""
}

To use this module in your application, add the following to your gracenode bootstrap code:

var gracenode = require('gracenode');
// this tells gracenode to load the module
gracenode.use('gracenode-staticdata');

To access the module:

// the prefix gracenode- will be removed automatically
gracenode.staticdata

Access

Configurations

// staticdata module supports CSV and JSON format
{
	"modules": {
		"staticdata": {
			"path": "directory path to the static files",
			"delimiter": optional and defaults to ',', // for parsing CSV files
			"index": { // optional // for getOneByIndex and getManyByIndex
				"staticFileName": ["indexName", [...]]
			},
			"maxOpenFiles": <int> // optional. the number of opened and read files at once on set up. default is 100
		}
	}
}

CSV

Supported CSV Delimiters

gracenode-staticdata module supports the following delimiters in CSV file format:

  • Comma (,)
  • Tab (\t)
  • Semicolon (;)
  • Caret (^)
  • Vertical bar (|)

Escaping Characters

If your CSV data contains the same characters as the deimiter, the characters must be escaped with a backslash ().

Example (delimiter is ,):

"id","name","age"
100,"Marley, Bob",33
101,"Harper, Ben",45

#####API: csvToObj

Parses CSV data into an object.

#####API: create

Returns and instance of StaticData class

Example:

/* 
In order to create a static data object from a static data file called "example.csv",
do the following:
*/
var example = gracenode.staticdata.create('example');
StaticData class

######.inflate()

Combines 2 staticdata objects on parentKey and childKey.

parentKey is the column from source staticdata and childKey is the column from the staticdata given to the function.

NOTE: The child staticdata MUST be indexed by childKey.

Example:

// CSV data of men.csv
name,wife
Bob,1
Kevin,2
Nathan,3
/*
[
	{ "name": "Bob", "wife": 1 },
	{ "name": "Kevin", "wife": 2 },
	{ "name": "Nathan", "wife": 3 }
]
*/
// CSV data of women.csv
id,name
1,Sandy
2,Olivia
3,Jess
/*
[
	{ "id": 1, "name": "Sandy" }
	{ "id": 2, "name": "Olivia" }
	{ "id": 3, "name": "Jess" }
]
*/
// inflate the 2 files
var men = gracenode.staticdata.create('men');
var women = gracenode.staticdata.create('women');
men.inflate(women, 'wife', 'id');
/*
Resulting data
[
	{
		"name": "Bob",
		"wife": {
			"id": 1,
			"Sandy"
		}
	},
	{
		"name": "Kevin",
		"wife": {
			"id": 2,
			"Olivia"
		}
	},
	{
		"name": "Nathan",
		"wife": {
			"id": 3,
			"Jess"
		}
	}
]
*/

######.getOneByIndex()

######.getManyByIndex()

######.getOne()

######.getMany()

######.getAll()

######.getAllByIndexName()

All get methods accepts an array of property names as an option to retrieve ONLY the given properties