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

n3-parser.js

v0.1.2

Published

N3 parser

Readme

N3 to JSON-LD converter

Parse N3 (not just turtle) and converts it to JSON-LD. That JSON-LD can also be converted back to N3, though not all JSON-LD features are supported in that conversion (but everything that gets output by the parser can be converted back).

Usage

Install with npm using npm install n3-parser.js.

const N3Parser = require('n3-parser.js').N3Parser;

let parser = new N3Parser();
let jsonld = parser.toJSONLD(`PREFIX dc: <http://purl.org/dc/elements/1.1/>
    <http://en.wikipedia.org/wiki/Tony_Benn>
    dc:title "Tony Benn";
    dc:publisher "Wikipedia".
`);
console.log(jsonld);

// Output:
// { '@context': { dc: 'http://purl.org/dc/elements/1.1/' },
//  '@id': 'http://en.wikipedia.org/wiki/Tony_Benn',
//  'dc:title': 'Tony Benn',
//  'dc:publisher': 'Wikipedia' }

const JSONLDParser = require('n3-parser.js').JSONLDParser;
let jsonldParser = new JSONLDParser();
let n3 = jsonldParser.toN3(jsonld);
console.log(n3);

// Output:
// PREFIX dc: <http://purl.org/dc/elements/1.1/>
// <http://en.wikipedia.org/wiki/Tony_Benn> dc:title "Tony Benn" ;
// dc:publisher "Wikipedia" .

N3 features

N3 has several features that are not covered by JSON-LD. In those cases we made some adaptations to the JSON-LD syntax. This also means that the output is not valid JSON-LD (but can still be converted back to N3 by our parser).

Formulas

For N3 formulas we use JSON-LD graphs without an @id. These do have semantic differences though, which should be taken into account. (JSON-LD treats these as graphs with a blank node as identifier).

=>

=> gets translated to its corresponding URI log:implies.

Literal/formula subjects

JSON-LD only supports URIs in the subject position. For literals we solve this by allowing JSON-LD @value objects to also have predicates:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
"Apple" rdfs:label "red" .
{ "@context": { "rdfs": "http://www.w3.org/2000/01/rdf-schema#" },
  "@value": "Apple",
  "rdfs:label": "red" }

Similarly, for formulas we allow JSON-LD graphs to have predicates:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
{} rdfs:label "red" .
{ "@context": { "rdfs": "http://www.w3.org/2000/01/rdf-schema#" },
  "@graph": [],
  "rdfs:label": "red" }

Variables

JSON-LD has no variables. We use the same syntax as URIs for those, e.g.:

{ "@id": "?b" }

Literal/formula predicates

JSON-LD only supports URIs in the predicate position, while N3 allows all terms there. The solution there is a bit more convoluted. We replace the offending predicate by a newly generated blank node, and also create a new object containing both the blank node and its corresponding value (or graph).

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
?a "predicate" ?b .
{
  "@context": {
    "rdfs": "http://www.w3.org/2000/01/rdf-schema#"
  },
  "@graph": [
    {
      "@value": "predicate",
      "@id": "_:b_01a89c31-59be-4aef-a7f5-708f33917877"
    },
    {
      "@id": "?a",
      "_:b_01a89c31-59be-4aef-a7f5-708f33917877": {
        "@id": "?b"
      }
    }
  ]
}

Base

JSON-LD has no good way to represent an empty prefix (e.g. :a). We replace all such prefixes with #base, which allows us to retain the empty prefix when converting back to N3.

PREFIX : <http://example.com/>
:s :p ?o .
{
  "@context": {
    "#base": "http://example.com/"
  },
  "@id": "#base:s",
  "#base:p": {
    "@id": "?o"
  }
}