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

n3writer-wrapper

v1.1.0

Published

Helpers for n3.Writer: topological blank-node inlining, uniform reindent, and multiline literal expansion

Readme

n3writer-wrapper

Helpers that improve the readability of n3.js Turtle/TriG output:

| Function | What it does | |---|---| | topoWrite(writer, quads) | Feeds quads to an N3 Writer using nested [ ] notation for blank nodes that appear as an object exactly once | | reindent(turtle, step?) | Normalises n3.Writer's mixed 4-space/2-space indentation to a uniform step (default: 2 spaces) at every nesting depth | | expandLiterals(turtle) | Converts "string\nwith\nescapes" to """stringwithnewlines""" for readability |

Install

npm install n3writer-wrapper

n3 itself is a peer dependency (optional — the structural types mean any compatible writer works):

npm install n3

Usage

import { Writer } from 'n3';
import { topoWrite, reindent, expandLiterals } from 'n3writer-wrapper';

const writer = new Writer({ format: 'Turtle', prefixes: { ex: 'http://example.org/' } });
topoWrite(writer, quads);
const turtle = await new Promise<string>((resolve, reject) =>
  writer.end((err, result) => (err ? reject(err) : resolve(result)))
);
const pretty = expandLiterals(reindent(turtle));

Sample output

Given examples/fhir-provenance.ttl — a FHIR Provenance resource co-signing a Bundle, where every blank node is single-use:

PREFIX fhir: <http://hl7.org/fhir/>
PREFIX xsd:  <http://www.w3.org/2001/XMLSchema#>

<http://something4> a fhir:Provenance ;
  fhir:id [ fhir:v "prov1" ] ;
  fhir:target [ fhir:reference [ fhir:v "Bundle/signed" ] ] ;
  fhir:recorded [ fhir:v "2024-06-09T11:06:35+10:00"^^xsd:dateTime ] ;
  fhir:signature [
    fhir:when [ fhir:v "2024-06-09T11:06:35+10:00"^^xsd:dateTime ] ;
    fhir:who  [ fhir:reference [ fhir:v "Organization/ig-publisher" ] ] ;
    fhir:sigFormat [ fhir:v "application/jose" ] ;
    fhir:data  [ fhir:v "eyJhbGciOiJSUzI1NiIsImI2NCI6ZmFsc2UsImNyaXQiOlsiYjY0Il19..stub" ]
  ] .

After topoWrite + reindent + expandLiterals:

@prefix fhir: <http://hl7.org/fhir/>.
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.

<http://something4> a fhir:Provenance;
  fhir:id [ fhir:v "prov1" ];
  fhir:target [
    fhir:reference [ fhir:v "Bundle/signed" ]
  ];
  fhir:recorded [ fhir:v "2024-06-09T11:06:35+10:00"^^xsd:dateTime ];
  fhir:signature [
    fhir:when [ fhir:v "2024-06-09T11:06:35+10:00"^^xsd:dateTime ];
    fhir:who [
      fhir:reference [ fhir:v "Organization/ig-publisher" ]
    ];
    fhir:sigFormat [ fhir:v "application/jose" ];
    fhir:data [ fhir:v "eyJhbGciOiJSUzI1NiIsImI2NCI6ZmFsc2UsImNyaXQiOlsiYjY0Il19..stub" ]
  ].

topoWrite(writer, quads)

Blank nodes that appear as an object exactly once are inlined as [ ] blocks. Blank nodes used more than once, or with no outgoing triples, fall back to _:label references. Duplicate quads (e.g. from a SPARQL CONSTRUCT) are silently deduplicated.

Input quads can be any iterable of RDFJS-compatible quads (n3, graphy, etc.).

reindent(turtle, step = ' ')

n3.Writer hard-codes 4 spaces for predicate-continuation lines and 2 spaces inside [ ] blocks. reindent normalises this so each additional nesting level adds exactly one step:

# before                          # after (step = '  ')
<ex:s> ex:p1 "a" ;                <ex:s> ex:p1 "a" ;
    ex:p2 [                         ex:p2 [
      ex:q "v"                          ex:q "v"
    ] .                             ] .

expandLiterals(turtle)

Converts \n escape sequences inside double-quoted literals to real newlines using triple-quoted form:

"line1\nline2"  →  """line1
                   line2"""

Falls back to the original form if the expanded content would contain """.

TypeScript

The package ships with declarations. The TurtleWriter interface is structural, so it matches n3.Writer without importing n3 as a type dependency:

import type { TurtleWriter, RdfQuad } from 'n3writer-wrapper';

License

MIT