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

mdld-convert

v1.0.0

Published

Gateway between MD-LD and standard RDF formats. Convert between Turtle, TriG, N-Triples, N-Quads, JSON-LD, RDFa, and MD-LD.

Readme

mdld-convert

Gateway between MD-LD and standard RDF formats. Convert between Turtle, TriG, N-Triples, N-Quads, JSON-LD, RDFa, and MD-LD.

Features

  • Simplified API: Single convert() function for all format conversions
  • Comprehensive format support: Turtle, TriG, N-Triples, N-Quads, JSON-LD, RDFa 1.1
  • Context preservation: Prefixes and vocabularies preserved by default
  • Quad-target API: Direct RDF ↔ Quads conversion for performance and quad-* ecosystem integration
  • Zero-dependency kernel: Uses external libraries (N3.js, jsonld.js, rdfa-parse) bundled into single ESM file
  • CLI tool: Command-line interface for terminal usage with quad JSON serialization
  • Round-trip safe: Deterministic conversions preserve semantic information

Installation

npm install mdld-convert

Library API

Core Conversion Function

import { convert, quadsToJSON, jsonToQuads } from 'mdld-convert'

Universal conversion between any supported formats:

const result = await convert({
  input,           // string (text) or object (JSON-LD)
  from,            // 'turtle', 'trig', 'nt', 'nq', 'jsonld', 'rdfa', 'mdld', 'quads'
  to,              // 'turtle', 'trig', 'nt', 'nq', 'jsonld', 'mdld', 'quads'
  context,         // prefix mappings for output (optional)
  baseIRI,         // base IRI for RDFa/JSON-LD (optional)
  vocab,           // vocabulary IRI for RDFa (optional)
  returnQuads      // return { quads, text } instead of just text (optional)
})

Examples

RDF → MD-LD:

const mdld = await convert({ 
  input: turtleText, 
  from: 'turtle', 
  to: 'mdld' 
})

MD-LD → RDF:

const turtle = await convert({ 
  input: mdldText, 
  from: 'mdld', 
  to: 'turtle' 
})

RDF → RDF (skip MD-LD):

const trig = await convert({ 
  input: turtleText, 
  from: 'turtle', 
  to: 'trig' 
})

With context preservation:

const turtle = await convert({ 
  input: mdldText, 
  from: 'mdld', 
  to: 'turtle',
  context: { ex: 'http://example.org/' }
})

Return quads for processing:

const { quads, text } = await convert({ 
  input: turtleText, 
  from: 'turtle', 
  to: 'turtle',
  returnQuads: true 
})
// Filter quads, then convert back
const filtered = quads.filter(q => q.predicate.value !== 'http://example.org/internal')
const result = await convert({ 
  input: filtered, 
  from: 'quads', 
  to: 'turtle' 
})

RDFa with options:

const mdld = await convert({ 
  input: htmlText, 
  from: 'rdfa', 
  to: 'mdld',
  baseIRI: 'http://example.org/',
  vocab: 'http://schema.org/'
})

Quad Utilities

// Serialize quads to JSON
const json = quadsToJSON(quads)

// Deserialize JSON to quads
const quads = jsonToQuads(json)

CLI Usage

# Import (RDF → MD-LD)
cat data.ttl | mdld-convert turtle
mdld-convert turtle -i data.ttl -o data.mdld
mdld-convert jsonld -i data.jsonld -o data.mdld
mdld-convert rdfa -i data.html --base http://example.org/ -o data.mdld

# Export (MD-LD → RDF)
cat data.mdld | mdld-convert --to turtle
mdld-convert --to turtle -i data.mdld -o data.ttl
mdld-convert --to jsonld -i data.mdld -o data.jsonld

# Quad-Target (RDF ↔ Quads, skip MD-LD)
cat data.ttl | mdld-convert quads | jq .
mdld-convert quads -i data.ttl -o quads.json
cat quads.json | mdld-convert --to quads -o data.ttl

CLI Options

  • -i, --input <file> - Read from file (default: stdin)
  • -o, --output <file> - Write to file (default: stdout)
  • --base <iri> - Base IRI for RDFa/JSON-LD
  • --vocab <iri> - Vocabulary IRI for RDFa

Supported Formats

| Format | Import | Export | Context | Quad-Target | |--------|--------|--------|---------|-------------| | Turtle | ✓ | ✓ | ✓ | ✓ | | TriG | ✓ | ✓ | ✓ | ✓ | | N-Triples | ✓ | ✓ | - | ✓ | | N-Quads | ✓ | ✓ | - | ✓ | | JSON-LD | ✓ | ✓ | ✓ | ✓ | | RDFa 1.1 | ✓ | - | ✓ | ✓ | | MD-LD | ✓ | ✓ | ✓ | ✓ | | Quads (JSON) | ✓ | ✓ | - | ✓ |

Complete Example

import { convert, quadsToJSON, jsonToQuads } from 'mdld-convert'

// Turtle → MD-LD
const turtle = `@prefix ex: <http://example.org/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .

ex:alice a foaf:Person ;
    ex:firstName "Alice" ;
    ex:lastName "Smith" .`

const mdld = await convert({ input: turtle, from: 'turtle', to: 'mdld' })
console.log(mdld)
// Output:
// [ex] <http://example.org/>
// [foaf] <http://xmlns.com/foaf/0.1/>
//
// # alice {=ex:alice .foaf:Person}
// [Alice] {ex:firstName}
// [Smith] {ex:lastName}

// MD-LD → Turtle (context preserved)
const turtle = await convert({ input: mdld, from: 'mdld', to: 'turtle' })
console.log(turtle.includes('@prefix ex:')) // true

// Turtle → Quads → Turtle (processing pipeline)
const { quads } = await convert({ 
  input: turtle, 
  from: 'turtle', 
  to: 'turtle',
  returnQuads: true 
})
const filtered = quads.filter(q => !q.predicate.value.includes('internal'))
const result = await convert({ 
  input: quadsToJSON(filtered), 
  from: 'quads', 
  to: 'turtle' 
})

Architecture

  • N3.js: Turtle/TriG/N-Triples/N-Quads parsing and serialization
  • jsonld.js: JSON-LD processing
  • rdfa-parse: RDFa 1.1 Core parsing
  • mdld-parse: MD-LD parsing and generation
  • Vite: Bundles all dependencies into single ESM file