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

reference-spec-reader

v0.2.0

Published

Experimental parser for [`ReferenceFileSystem` description](https://github.com/intake/fsspec-reference-maker). This repository also provides a `ReferenceStore` implementation, a storage backend for [`Zarr.js`](https://github.com/gzuidhof/zarr.js). An exam

Downloads

5,283

Readme

reference-spec-reader

Experimental parser for ReferenceFileSystem description. This repository also provides a ReferenceStore implementation, a storage backend for Zarr.js. An example of the V1 specification (JSON) is shown below:

{
  "version": 1,
  "templates": {
    "u": "server.domain/path",
    "f": "{{ c }}"
  },
  "gen": [
    {
      "key": "gen_key{{ i }}",
      "url": "http://{{ u }}_{{ i }}",
      "offset": "{{ (i + 1) * 1000 }}",
      "length": "1000",
      "dimensions": {
        "i": { "stop": 5 }
      }
    }
  ],
  "refs": {
    "key0": "data",
    "key1": ["http://target_url", 10000, 100],
    "key2": ["http://{{ u }}", 10000, 100],
    "key3": ["http://{{ f(c='text') }}", 10000, 100],
    "key4": ["http://{{ f(c='text') }}"]
  }
}

API Reference

#parse(spec[, renderString]) · Source

Parses both v0 and v1 references into Map<string, Ref>. A Ref is a union type of the following:

  • string: Inline ascii/base64 encoded data.
  • [url: string]: A url for a whole file.
  • [url: string | null, offset: number, length: number]: A tuple describing a binary section of a url.
const spec = await fetch('http://localhost:8080/ref.json').then(res => res.json());
const ref = parse(spec);
console.log(ref);
// Map(9) {
//  'key0' => 'data',
//  'key1' => [ 'http://target_url', 10000, 100 ],
//  'key2' => [ 'http://server.domain/path', 10000, 100 ],
//  'key3' => [ 'http://text', 10000, 100 ],
//  'key4' => [ 'http://text' ],
//  'gen_key0' => [ 'http://server.domain/path_0', 1000, 1000 ],
//  'gen_key1' => [ 'http://server.domain/path_1', 2000, 1000 ],
//  'gen_key2' => [ 'http://server.domain/path_2', 3000, 1000 ],
//  'gen_key3' => [ 'http://server.domain/path_3', 4000, 1000 ],
//  'gen_key4' => [ 'http://server.domain/path_4', 5000, 1000 ]
// }

This library includes a minimal built-in render method to render jinja-templates included in the v1 spec. This method can be overriden by providing a custom renderString function as a second argument.

import nunjucks from 'nunjucks';
const spec = await fetch('http://localhost:8080/ref.json').then(res => res.json());
const ref = parse(spec, nunjucks.renderString);

# ReferenceStore.fromJSON(data, [, options]) · Source

A Zarr.js store reference implementation. Uses fetch API.

  • data: A string in a supported JSON format, or a corresponding Object instance. Must adhere to v0 or v1 reference specification.
  • options:
    • target: A default target url for the reference.
    • renderString: A custom renderString function.
// create store from an input JSON string (v0 references).
ReferenceStore.fromJSON(`{"key0":"data","key1":"base64:aGVsbG8sIHdvcmxk"}`);
// create a store from an input JSON string loaded from `url`
ReferenceStore.fromJSON(await fetch(url).then(res => res.text()));
// create a store from an input JSON object loaded from `url`
ReferenceStore.fromJSON(await fetch(url).then(res => res.json()));
// create a store from an input JSON object loaded from `url` with default binary target
const res = await fetch('http://localhost:8080/data.tif.json');
ReferenceStore.fromJSON(await res.json(), { target: 'http://localhost:8080/data.tif' });

Usage

This package is written as a pure ES Module and is intended for use in various JavaScript runtimes. It can be imported from a CDN via URL directly, or installed as a dependency from pnpm for use in Node.js or via a bundler.

// Browser or Deno via a CDN
import { ReferenceStore, parse } from 'https://cdn.skypack.dev/reference-spec-reader@<version>';

// Node.js or bundler
import { ReferenceStore, parse } from 'referece-spec-reader';

Development

I welcome any input, feedback, bug reports, and contributions. This project requires Node.js (version 12 or later) for running the test suite and linting/formating the code.

Installation

cd reference-spec-reader
pnpm install

Running tests

pnpm test # runs unit tests only
pnpm run test:ci # runs CI test suite (type-checking, linting, and unit tests)

NOTE: If making a PR, please run pnpm fmt to auto-format your changes. The linting check will fail for unformatted code.