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

record-jar

v1.0.4

Published

Self-contained JavaScript class for reading and writing data from the "record-jar" metaformat.

Downloads

22

Readme

Record-Jar

A self-contained JavaScript class for parsing and packing data in the so-called "record-jar" metaformat.

The what?

This is a "record-jar":

Planet: Mercury
Orbital-Radius: 57,910,000 km
Diameter: 4,880 km
%%
Planet: Venus
Orbital-Radius: 108,200,000 km
Diameter: 12,103.6 km
%%
Planet: Earth
Orbital-Radius: 149,600,000 km
Mass: 5.972e24 kg
Moons: Luna

You might've already seen this format if you've perused the IANA subtag registry. The registry lists every IETF language tag available for identifying the language of web documents, and is perhaps the most frequently-referenced example of a record-jar file.

If the term's unfamiliar to you, it probably brought to mind some arcane compression format, or something to do with Java executables (my-sick-program.jar). The term was actually coined by Eric S. Raymond in his excellent book, The Art of UNIX Programming (p.116) whilst describing various data file metaformats. The name "Record-Jar" was derived from the "Cookie-Jar" metaformat, which listed quotes that were selected at random by the fortune program. Each quote was delimited by a newline-separated %% or %, which left the data it sandwiched easy to parse:

"Simple cookie-jar format is appropriate for pieces of text that have no
natural ordering, distinguishable structure above word level, or search keys
other than their text context."
	-- Eric S. Raymond, "The Art of UNIX Programming", pg 116
%%
"A data file metaformat is a set of syntactic and lexical conventions that is
either formally standardized or sufficiently well established by practice that
there are standard service libraries to handle marshaling and unmarshaling it."
	-- Eric S. Raymond, "The Art of UNIX Programming", pg 112
%%
"lu2 is very common Sumerian texts in its full meaning as "man". It is also
frequent as a head noun in relative clauses modifying animate antecedents;
clause such as that occurring in lines 4-5 can be understood and translated as
"the man who built", "the one who built", "he who built", and so on. Akkadian
scribes themselves sometimes translated lu2 as ša, the Akkadian relative
pronoun."
	-- John L. Hayes, "A Manual of Sumerian Grammar and Texts", pg 106

You get it.

When the hell would I use this?

Probably for the exact same reason I wrote it: for parsing the IANA subtag registry. Furthermore, I don't expect this script will invoke a loadbalancer-shattering level of demand, but it's nice knowing it might benefit somebody out there one day needing to build a list of BCP 47 tags.

Usage

Create a new RecordJar instance by passing it a block of text as its first argument.

var data = load("languages.txt");
var jar  = new RecordJar(data);

Then loop over its .records property, reading or matching whatever you need to:

for(var i = 0; i < jar.records.length; ++i){
	console.log( jar.records[i] );
}

When adding new data, you needn't access the array methods of .records directly: RecordJar instances offer their own .push method for your convenience:

jar.push({
	Name: "Waryfish",
	Kingdom: "Animalia",
	Genera: [
		"Ahliesaurus",
		"Luciosudis",
		"Scopelosaurus"
	]
});

Finally, when typecast to a string, RecordJars will produce compiled, serialisable versions of their contents in the same format they were designed to read:

/** Either of the following two lines will work. You know the drill. */
var str = jar.toString();
var str = jar + "";

console.log(str);

/** Example output: **/
`Planet: Earth
Orbital-Radius: 149,600,000 km
Diameter: 12,756.3 km
Mass: 5.972e24 kg
Moons: Luna
%%
Name: Waryfish
Kingdom: Animalia
Genera: Ahliesaurus
Genera: Luciosudis
Genera: Scopelosaurus`