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

legal-docs-client

v1.0.0

Published

TypeScript client for accessing legal documents from the Case Law Explorer API

Readme

Legal Docs Client

A TypeScript client library for accessing legal documents from the Case Law Explorer API.

Each data source is exposed through its own typed endpoint: Rechtspraak (Dutch case law) and ECHR (European Court of Human Rights).

Installation

npm install legal-docs-client

Usage

Basic Setup

import { createLegalDocsClient } from 'legal-docs-client';

const client = createLegalDocsClient({
  apiKey: process.env.CITATIONS_API_KEY
});

Fetching Rechtspraak Documents

fetchRechtspraak queries Dutch case law (Rechtspraak) citation networks:

const documents = await client.fetchRechtspraak({
  degreesSource: 0,
  degreesTarget: 0,
  dateStart: "1900-01-01",
  dateEnd: "2026-03-10",
  docTypes: ["DEC"],
  attributesToFetch: "ALL",
  keywords: ["armenia"],
  selectedLawsIntersect: true,
});

console.log(documents);

Fetching Documents with Statistics

You can automatically compute statistics for the fetched documents by passing true as the second parameter:

const documents = await client.fetchRechtspraak({
  degreesSource: 1,
  degreesTarget: 1,
  dateStart: "2020-01-01",
  dateEnd: "2024-12-31",
  docTypes: ["DEC"],
  eclis: ["ECLI:NL:HR:2021:1234"],
}, true); // computeStatistics = true

// Each document will have a statistics property with centrality metrics
console.log(documents[0].data.statistics);
/*
{
  parent: "ECLI:NL:HR:2021:1234",
  degree: 5,
  inDegree: 2,
  outDegree: 3,
  degreeCentrality: 0.8,
  inDegreeCentrality: 0.4,
  outDegreeCentrality: 0.6,
  betweennessCentrality: 0.5,
  closenessCentrality: 0.7,
  relativeInDegree: 0.4,
  community: 0,
  year: 2021,
  pageRank: 0.25
}
*/

Computing Statistics

You can compute network statistics (centrality metrics) for a set of documents:

// First, fetch some documents
const documents = await client.fetchRechtspraak({
  degreesSource: 1,
  degreesTarget: 1,
  eclis: ["ECLI:NL:HR:2021:1234"],
});

// Then compute statistics
const statistics = await client.computeStatistics(documents);

console.log(statistics);
/*
[
  {
    id: "ECLI:NL:HR:2021:1234",
    parent: "ECLI:NL:HR:2020:5678",
    degree: 5,
    inDegree: 2,
    outDegree: 3,
    degreeCentrality: 0.8,
    inDegreeCentrality: 0.4,
    outDegreeCentrality: 0.6,
    betweennessCentrality: 0.5,
    closenessCentrality: 0.7,
    relativeInDegree: 0.4,
    community: 0,
    year: 2021,
    pageRank: 0.25
  },
  // ... more statistics for other documents
]
*/

The statistics include various centrality measures:

  • degree: Total number of connections (citations + cited by)
  • inDegree: Number of documents citing this one
  • outDegree: Number of documents this one cites
  • degreeCentrality: Normalized degree centrality
  • inDegreeCentrality: Normalized in-degree centrality
  • outDegreeCentrality: Normalized out-degree centrality
  • betweennessCentrality: Measure of how often a document lies on the shortest path between other documents
  • closenessCentrality: Measure of how close a document is to all other documents
  • relativeInDegree: Ratio of in-degree to total degree
  • pageRank: PageRank score indicating importance in the citation network
  • community: Community/cluster identifier
  • year: Year from the document's decision date

Getting Full Text

const fullTextDocs = await client.getRechtspraakFullText(['ECLI:NL:HR:2005:AO9006', 'ECLI:NL:RBSGR:2012:BY5532']);

console.log(fullTextDocs);
// [{ ecli, fullText, fullTextAvailable, message? }, ...]

Fetching ECHR Documents

fetchEchr queries HUDOC (European Court of Human Rights) citation networks. At least one search criterion (keyword, ECLI, application number, or article) is required:

const documents = await client.fetchEchr({
  degreesSource: 1,
  degreesTarget: 1,
  keywords: ["Armenia"],
  attributesToFetch: "MINIMAL",
});

console.log(documents);

Filter by violated/applied articles and respondent state:

const documents = await client.fetchEchr({
  degreesSource: 1,
  degreesTarget: 1,
  article_violated: ["6", "8"],
  article_violated_mode: "OR",
  respondent_state: ["GRC"],
  pageSize: 100,
});

Statistics can be computed the same way as for Rechtspraak, by passing true as the second parameter, or afterwards via client.computeStatistics(documents).

Getting ECHR Full Text

const fullTextDocs = await client.getEchrFullText(['ECLI:CE:ECHR:2000:1026JUD003098596']);

console.log(fullTextDocs);
// [{ ecli, language, itemid, fullText, fullTextAvailable, message?, languages? }, ...]

By default the API picks a language (English preferred, then French) and returns every available language version in languages. Request a specific language instead:

const fullTextDocs = await client.getEchrFullText(
  ['ECLI:CE:ECHR:2000:1026JUD003098596'],
  'FRE',
);

Fetching Laws

const laws = await client.fetchLaws('Art. 7:669 BW');

console.log(laws);

Environment Configuration

This package requires an API token from the Case Law Explorer API for document requests.

Setup Instructions

  1. Install dotenv (if working in Node.js):
npm install dotenv
  1. Create a .env file in your project root:
CITATIONS_API_KEY=your_api_token_here
  1. Load environment variables in your application:
import 'dotenv/config';
import { createLegalDocsClient } from 'legal-docs-client';

const client = createLegalDocsClient({
  apiKey: process.env.CITATIONS_API_KEY
});

Note: For Vite projects, use import.meta.env.VITE_CITATIONS_API_KEY instead and prefix your .env variable with VITE_.

Getting an API Token

New API keys can be generated at: https://api.caselawexplorer.tech/login.html?next=/account.html

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.