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 🙏

© 2026 – Pkg Stats / Ryan Hefner

shape-map

v1.1.0

Published

RDF Node/ShEx Shape mapping format.

Readme

shape-map

npm version CI

Parse ShapeMaps — the language that says which nodes to validate against which shapes, e.g. <#n>@<#S1>.

Install

npm install shape-map

Quick start

const ShapeMap = require("shape-map");
const shapeMapParser = ShapeMap.Parser.construct(
  "http://base.example/fallback/",
  { base: "http://my.example/url/", prefixes: {} },  // resolves shapes
  { base: "http://my.example/url/", prefixes: {} }   // resolves nodes
);
const smap = shapeMapParser.parse("<#n>@<#S1>");
console.log(smap);
[
  {
    node: 'http://my.example/url/#n',
    shape: 'http://my.example/url/#S1',
    status: 'conformant'
  }
]

The result is an array of node/shape associations, ready to hand to @shexjs/validator's validateShapeMap. (status is the association's asserted status — conformant unless written with ! for nonconformant or ? for unknown.)

Parser.construct(fallbackBase, schemaMeta, dataMeta)

Construct a ShapeMap parser with appropriate bases and prefixes for resolving shapes and nodes:

  • fallbackBase — a URL string to use as a base if schemaMeta/dataMeta don't supply one
  • schemaMeta{base, prefixes} used to resolve the shape side (right of @)
  • dataMeta{base, prefixes} used to resolve the node side (left of @)

Base URLs for schema and data

URLs in the node specifier (left of the @ sign) are resolved against the dataMeta base and prefixes; the shape specifier uses the schemaMeta. Here the schema and data have different base URLs:

const shapeMapParser = ShapeMap.Parser.construct(
  "http://base.example/fallback/",
  { base: "http://my.example/schema/", prefixes: {} },
  { base: "http://my.example/data/", prefixes: {} }
);
const smap = shapeMapParser.parse("<#n>@<#S1>");
[
  {
    node: 'http://my.example/data/#n',
    shape: 'http://my.example/schema/#S1',
    status: 'conformant'
  }
]

Prefixes for schema and data

Prefixes declared in the metas let the two sides of the map use each document's own names:

const shapeMapParser = ShapeMap.Parser.construct(
  "http://base.example/fallback/",
  { base: "http://my.example/schema/", prefixes: {shape: "http://my.example/shapes#"} },
  { base: "http://my.example/data/", prefixes: {"": "http://my.example/data#"} }
);
const smap = shapeMapParser.parse(":n@shape:S1");
[
  {
    node: 'http://my.example/data#n',
    shape: 'http://my.example/shapes#S1',
    status: 'conformant'
  }
]

Use with the @shexjs loader and validator

The ShapeMap parser is typically used with @shexjs/loader (or @shexjs/node), whose load() returns exactly the metadata construct wants. This example ShapeMap (<#n>@s:S1) uses the data's base URL and the schema's s: prefix:

const {ctor: RdfJsDb} = require("@shexjs/neighborhood-rdfjs");
const {ShExValidator} = require("@shexjs/validator");
const ShExLoader = require("@shexjs/loader")({
  rdfjs: require("n3"),  // no fetch needed with {url, text} arguments
});
const ShapeMap = require("shape-map");

main();
async function main () {
  const loaded = await ShExLoader.load(
    { shexc: [{url: "http://my.example/schema/", text: `PREFIX p: <http://my.example/ns#>
PREFIX s: <http://my.example/shapes#>
s:S1 { p:p1 [1 2]; p:p2 [3 4] }`}]},
    { turtle: [{url: "http://my.example/data", text: `PREFIX : <http://my.example/ns#>
<#n> :p1 1 ; :p2 3 .`}] }
  );
  const {schema, schemaMeta, data, dataMeta} = loaded;
  const shapeMapParser = ShapeMap.Parser.construct(
    "http://base.example/fallback/",
    schemaMeta[0],
    dataMeta[0]
  );
  const smap = shapeMapParser.parse("<#n>@s:S1");
  const validator = new ShExValidator(schema, RdfJsDb(data));
  const results = validator.validateShapeMap(smap);
  results.forEach(r => console.log(r.node, r.status));
}
http://my.example/data#n conformant

validateShapeMap returns the same associations with status set to what validation found and an appinfo saying why — see @shexjs/validator.


shape-map is one of the shex.js packages; installing shex pulls in the whole suite, and its README maps them.