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

@lexbuild/ecfr

v1.10.0

Published

Electronic Code of Federal Regulations (eCFR) to Markdown converter for LexBuild

Readme

@lexbuild/ecfr

npm license

Converts Electronic Code of Federal Regulations (eCFR) XML into structured Markdown optimized for AI, RAG pipelines, and semantic search. Supports two download sources: the ecfr.gov API (daily-updated, default) and govinfo.gov bulk data (fallback).

Tip: For command-line usage, install @lexbuild/cli instead. This package is the programmatic API.

Install

npm install @lexbuild/ecfr
# or
pnpm add @lexbuild/ecfr

Peer dependency: @lexbuild/core (installed automatically via workspace protocol in the monorepo).

Quick Start

Download and Convert

import { downloadEcfrTitlesFromApi, convertEcfrTitle } from "@lexbuild/ecfr";

// Download Title 17 from the eCFR API (daily-updated)
const download = await downloadEcfrTitlesFromApi({
  output: "./downloads/ecfr/xml",
  titles: [17],
});
console.log(`As of: ${download.asOfDate}`);

// Convert to section-level Markdown
const result = await convertEcfrTitle({
  input: "./downloads/ecfr/xml/ECFR-title17.xml",
  output: "./output",
  granularity: "section",
  linkStyle: "plaintext",
  includeSourceCredits: true,
  includeNotes: true,
  includeEditorialNotes: false,
  includeStatutoryNotes: false,
  includeAmendments: false,
  dryRun: false,
});

console.log(`${result.sectionsWritten} sections, ${result.totalTokenEstimate} est. tokens`);

Point-in-Time Downloads

import { downloadEcfrTitlesFromApi } from "@lexbuild/ecfr";

// Download the CFR as it existed on a specific date
const result = await downloadEcfrTitlesFromApi({
  output: "./downloads/ecfr/xml",
  titles: [17],
  date: "2025-01-01",
});

Title Metadata

import { fetchEcfrTitlesMeta } from "@lexbuild/ecfr";

const meta = await fetchEcfrTitlesMeta();
console.log(`Data current as of: ${meta.date}`);
for (const title of meta.titles) {
  console.log(`Title ${title.number}: ${title.name} (amended ${title.latestAmendedOn})`);
}

Govinfo Bulk Data (Fallback)

import { downloadEcfrTitles } from "@lexbuild/ecfr";

const result = await downloadEcfrTitles({
  output: "./downloads/ecfr/xml",
  titles: [1, 17],
});

API Reference

Functions

| Export | Description | |--------|-------------| | convertEcfrTitle(options) | Convert an eCFR XML file to Markdown at any granularity | | downloadEcfrTitlesFromApi(options) | Download from ecfr.gov API (daily-updated, point-in-time) | | downloadEcfrTitles(options) | Download from govinfo.gov bulk data (fallback) | | fetchEcfrTitlesMeta() | Fetch title metadata and currency dates from the eCFR API | | buildEcfrApiDownloadUrl(titleNumber, date) | Build ecfr.gov API download URL | | buildEcfrDownloadUrl(titleNumber) | Build govinfo bulk download URL |

Types

| Export | Description | |--------|-------------| | EcfrConvertOptions | Options for convertEcfrTitle() — input, output, granularity, link style, note filters | | EcfrConvertResult | Conversion result — sections written, parts, files, token estimate | | EcfrApiDownloadOptions | Options for downloadEcfrTitlesFromApi() — output, titles, optional date | | EcfrApiDownloadResult | API download result — files, bytes, as-of date | | EcfrApiDownloadedFile | Single API-downloaded file metadata | | EcfrDownloadOptions | Options for downloadEcfrTitles() (govinfo) | | EcfrDownloadResult | Govinfo download result | | EcfrDownloadedFile | Single govinfo-downloaded file metadata | | EcfrTitleMeta | Per-title metadata from the eCFR API | | EcfrTitlesResponse | Full response from the titles metadata endpoint |

Classes

| Export | Description | |--------|-------------| | EcfrASTBuilder | SAX-to-AST builder for eCFR GPO/SGML XML. Handles both ecfr.gov API and govinfo bulk XML formats transparently. |

Constants

| Export | Description | |--------|-------------| | ECFR_TITLE_COUNT | Total number of CFR titles (50) | | ECFR_TITLE_NUMBERS | Array of valid title numbers [1, 2, ..., 50] | | ECFR_TYPE_TO_LEVEL | Map from DIV TYPE attributes to LexBuild level types | | ECFR_EMPHASIS_MAP | Map from E element T attribute to inline formatting types |

Output

Each title produces Markdown files with YAML frontmatter. The structure depends on granularity:

| Granularity | Output Path | Sidecar Files | |---|---|---| | section (default) | ecfr/title-17/chapter-IV/part-240/section-240.10b-5.md | _meta.json per part + title, README.md per title | | part | ecfr/title-17/chapter-IV/part-240.md | — | | chapter | ecfr/title-17/chapter-IV/chapter-IV.md | — | | title | ecfr/title-17.md | — |

Frontmatter

eCFR sections include source-specific metadata alongside standard LexBuild fields:

---
identifier: "/us/cfr/t17/s240.10b-5"
source: "ecfr"
legal_status: "authoritative_unofficial"
title: "17 CFR § 240.10b-5 - Employment of manipulative and deceptive devices"
title_number: 17
section_number: "240.10b-5"
positive_law: false
authority: "15 U.S.C. 78a et seq., ..."
cfr_part: "240"
---

Data Sources

| Source | URL | Update Frequency | Point-in-Time | |--------|-----|-----------------|---------------| | eCFR API (default) | ecfr.gov/api/versioner/v1/ | Daily | Yes | | govinfo bulk (fallback) | govinfo.gov/bulkdata/ECFR/ | Irregular | No |

Both sources produce the same GPO/SGML-derived XML element vocabulary. The builder handles format differences (wrapper elements, attribute variations) transparently — the converter works identically regardless of source.

Title 35 (Panama Canal) is reserved and has no data from either source.

Compatibility

  • Node.js >= 22
  • ESM only — no CommonJS build
  • TypeScript — ships .d.ts type declarations

Monorepo Context

Part of the LexBuild monorepo. Depends on @lexbuild/core for XML parsing, AST types, and Markdown rendering.

pnpm turbo build --filter=@lexbuild/ecfr
pnpm turbo test --filter=@lexbuild/ecfr

Related Packages

| Package | Description | |---------|-------------| | @lexbuild/cli | CLI tool — the easiest way to use LexBuild | | @lexbuild/core | Shared parsing, AST, and rendering infrastructure | | @lexbuild/usc | U.S. Code (USLM XML) converter |

License

MIT