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 🙏

© 2025 – Pkg Stats / Ryan Hefner

jsonld-recursive

v1.0.0

Published

Recursively expand and compact JSON-LD documents with caching and chained URL mappings

Readme

jsonld-recursive

Recursively expand and compact JSON-LD documents with caching and chained URL mappings.

Installation

npm install jsonld-recursive

Quick Start

CLI

# Standalone
ldr compact https://example.com/data.jsonld -d 3

# With server
ldr server start
ldr compact https://example.com/data.jsonld -d 3 --server
ldr server stop

Python

from lib.ldr_client import LdrClient

# Auto-start server
with LdrClient(auto_start_server=True) as client:
    result = client.compact("https://example.com/data.jsonld", depth=3)

Browser (CDN)

<script src="https://cdn.jsdelivr.net/npm/jsonld-recursive@1/lib/ldr-core.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jsonld-recursive@1/lib/ldr-browser.js"></script>

<script>
  await JsonLdExpand.compact('https://example.com/data.jsonld', {depth: 3});
</script>

Server Commands

# Start
ldr server start

# Start with port
ldr server start 8080

# Start with mappings file
ldr server start 3000 mappings.json

# Start with JSON mappings
ldr server start 3000 '{"cmip7:*":"https://example.com/${rest}"}'

# Stop
ldr server stop

# Status
ldr server status

# Or kill by name
pkill ldr-server

Chained URL Mappings

Apply multiple mappings in sequence:

{
  "cmip7:*": "https://wcrp-cmip.github.io/CMIP7-CVs/${rest}",
  "https://wcrp-cmip.github.io/CMIP7-CVs/*": "/home/user/local-cvs/${rest}"
}

Input: cmip7:experiment/graph.jsonld
Step 1: cmip7:*https://wcrp-cmip.github.io/CMIP7-CVs/experiment/graph.jsonld
Step 2: https://.../*/home/user/local-cvs/experiment/graph.jsonld
Result: Loads from local file

Set Mappings

CLI:

# From file
ldr mappings set mappings.json

# From JSON (no -m flag needed)
ldr mappings set '{"cmip7:*":"https://example.com/${rest}"}'

# Get current
ldr mappings get

# Clear
ldr mappings clear

Python:

with LdrClient(auto_start_server=True) as client:
    # Set chained mappings
    client.set_mappings({
        "cmip7:*": "https://wcrp-cmip.github.io/CMIP7-CVs/${rest}",
        "https://wcrp-cmip.github.io/CMIP7-CVs/*": "/home/user/local-cvs/${rest}"
    })
    
    result = client.compact("cmip7:experiment/graph.jsonld", depth=3)

Python Client

Basic Usage

from lib.ldr_client import LdrClient

with LdrClient() as client:
    result = client.compact("https://example.com/data.jsonld", depth=3)

Auto-start Server

# Server starts and stops automatically
with LdrClient(auto_start_server=True) as client:
    result = client.compact("https://example.com/data.jsonld", depth=3)

Multiple Requests

with LdrClient(auto_start_server=True) as client:
    urls = ["url1", "url2", "url3"]
    
    # Loop
    for url in urls:
        result = client.compact(url, depth=3)
    
    # Or batch
    results = client.compact_batch(urls, depth=3)

Runtime Mappings

with LdrClient(auto_start_server=True) as client:
    # Set mappings
    client.set_mappings({
        "cmip7:*": "https://wcrp-cmip.github.io/CMIP7-CVs/${rest}",
        "https://wcrp-cmip.github.io/CMIP7-CVs/*": "/home/user/local/${rest}"
    })
    
    result = client.compact("cmip7:experiment/graph.jsonld", depth=3)
    
    # Update
    client.set_mappings({"new:*": "https://new.com/${rest}"})
    
    # Clear
    client.clear_mappings()

CLI Usage

# Standalone (no server)
ldr compact <url> -d 3

# With server (caching)
ldr compact <url> -d 3 --server

# Server management
ldr server start [port] [mappings.json]
ldr server stop
ldr server status

# Mappings (server must be running)
ldr mappings get
ldr mappings set mappings.json
ldr mappings set '{"prefix:*":"https://example.com/${rest}"}'
ldr mappings clear

Documentation

Publishing

npm login
npm publish

After publishing, available via CDN:

  • https://cdn.jsdelivr.net/npm/jsonld-recursive@1/lib/ldr-core.js
  • https://unpkg.com/jsonld-recursive@1/lib/ldr-core.js

License

MIT