@lexbuild/usc 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +121 -0
- package/package.json +13 -13
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Chris Thomas
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# @lexbuild/usc
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@lexbuild/usc)
|
|
4
|
+
[](https://github.com/chris-c-thomas/lexbuild/blob/main/LICENSE)
|
|
5
|
+
|
|
6
|
+
This package is part of the [LexBuild](https://github.com/chris-c-thomas/lexbuild) monorepo, a tool that converts U.S. legislative XML into structured Markdown optimized for AI, RAG pipelines, and semantic search. See the monorepo for full documentation, architecture details, and contribution guidelines.
|
|
7
|
+
|
|
8
|
+
It converts official [USLM](https://uscode.house.gov/download/resources/USLM-User-Guide.pdf) XML from the [Office of the Law Revision Counsel](https://uscode.house.gov/) (OLRC) into structured Markdown. It also provides a downloader for fetching the XML directly from OLRC.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @lexbuild/usc
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
### Convert a Title
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { convertTitle } from "@lexbuild/usc";
|
|
22
|
+
|
|
23
|
+
const result = await convertTitle({
|
|
24
|
+
input: "./downloads/usc/xml/usc01.xml",
|
|
25
|
+
output: "./output",
|
|
26
|
+
granularity: "section",
|
|
27
|
+
linkStyle: "plaintext",
|
|
28
|
+
includeSourceCredits: true,
|
|
29
|
+
includeNotes: true,
|
|
30
|
+
includeEditorialNotes: false,
|
|
31
|
+
includeStatutoryNotes: false,
|
|
32
|
+
includeAmendments: false,
|
|
33
|
+
dryRun: false,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
console.log(`Wrote ${result.sectionsWritten} sections`);
|
|
37
|
+
console.log(`Chapters: ${result.chapterCount}`);
|
|
38
|
+
console.log(`Estimated tokens: ${result.totalTokenEstimate}`);
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Download Titles from OLRC
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import { downloadTitles } from "@lexbuild/usc";
|
|
45
|
+
|
|
46
|
+
// Download specific titles
|
|
47
|
+
const result = await downloadTitles({
|
|
48
|
+
outputDir: "./downloads/usc/xml",
|
|
49
|
+
titles: [1, 5, 26],
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// Download all 54 titles (uses a single bulk zip)
|
|
53
|
+
const all = await downloadTitles({
|
|
54
|
+
outputDir: "./downloads/usc/xml",
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
console.log(`Downloaded ${result.files.length} files`);
|
|
58
|
+
console.log(`Release point: ${result.releasePoint}`);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## API Reference
|
|
62
|
+
|
|
63
|
+
### Functions
|
|
64
|
+
|
|
65
|
+
| Export | Description |
|
|
66
|
+
|--------|-------------|
|
|
67
|
+
| `convertTitle(options)` | Convert a USC XML file to section-level Markdown |
|
|
68
|
+
| `downloadTitles(options)` | Download USC XML from OLRC |
|
|
69
|
+
| `buildDownloadUrl(titleNumber, releasePoint)` | Build URL for a single title zip |
|
|
70
|
+
| `buildAllTitlesUrl(releasePoint)` | Build URL for the bulk zip |
|
|
71
|
+
| `releasePointToPath(releasePoint)` | Convert release point to URL path segment |
|
|
72
|
+
| `isAllTitles(titles)` | Check if a title list covers all 54 titles |
|
|
73
|
+
|
|
74
|
+
### Types
|
|
75
|
+
|
|
76
|
+
| Export | Description |
|
|
77
|
+
|--------|-------------|
|
|
78
|
+
| `ConvertOptions` | Options for `convertTitle()` |
|
|
79
|
+
| `ConvertResult` | Result of a conversion (sections, chapters, tokens, files) |
|
|
80
|
+
| `DownloadOptions` | Options for `downloadTitles()` |
|
|
81
|
+
| `DownloadResult` | Result of a download (files, errors, release point) |
|
|
82
|
+
| `DownloadedFile` | Info about a downloaded file (title, path, size) |
|
|
83
|
+
| `DownloadError` | Info about a failed download |
|
|
84
|
+
|
|
85
|
+
### Constants
|
|
86
|
+
|
|
87
|
+
| Export | Description |
|
|
88
|
+
|--------|-------------|
|
|
89
|
+
| `CURRENT_RELEASE_POINT` | Current OLRC release point (e.g., `"119-73not60"`) |
|
|
90
|
+
| `USC_TITLE_NUMBERS` | Array of valid title numbers (1-54) |
|
|
91
|
+
|
|
92
|
+
## Output
|
|
93
|
+
|
|
94
|
+
Each title produces a directory tree of Markdown files with YAML frontmatter and JSON metadata indexes:
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
output/usc/title-01/
|
|
98
|
+
README.md
|
|
99
|
+
_meta.json
|
|
100
|
+
chapter-01/
|
|
101
|
+
_meta.json
|
|
102
|
+
section-1.md
|
|
103
|
+
section-2.md
|
|
104
|
+
chapter-02/
|
|
105
|
+
_meta.json
|
|
106
|
+
section-101.md
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
See the [output format specification](https://github.com/chris-c-thomas/lexbuild/blob/main/docs/output-format.md) for details.
|
|
110
|
+
|
|
111
|
+
## Documentation
|
|
112
|
+
|
|
113
|
+
- [Monorepo README](https://github.com/chris-c-thomas/lexbuild#readme)
|
|
114
|
+
- [Architecture](https://github.com/chris-c-thomas/lexbuild/blob/main/docs/architecture.md)
|
|
115
|
+
- [Output Format](https://github.com/chris-c-thomas/lexbuild/blob/main/docs/output-format.md)
|
|
116
|
+
- [XML Element Reference](https://github.com/chris-c-thomas/lexbuild/blob/main/docs/xml-element-reference.md)
|
|
117
|
+
- [Extending](https://github.com/chris-c-thomas/lexbuild/blob/main/docs/extending.md)
|
|
118
|
+
|
|
119
|
+
## License
|
|
120
|
+
|
|
121
|
+
[MIT](https://github.com/chris-c-thomas/lexbuild/blob/main/LICENSE)
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lexbuild/usc",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Federal U.S. Code specific element handlers and downloader for lexbuild",
|
|
5
5
|
"author": "Chris Thomas",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"homepage": "https://github.com/chris-c-thomas/lexbuild#readme",
|
|
7
|
+
"homepage": "https://github.com/chris-c-thomas/lexbuild/tree/main/packages/usc#readme",
|
|
8
8
|
"bugs": {
|
|
9
9
|
"url": "https://github.com/chris-c-thomas/lexbuild/issues"
|
|
10
10
|
},
|
|
@@ -41,18 +41,9 @@
|
|
|
41
41
|
"files": [
|
|
42
42
|
"dist"
|
|
43
43
|
],
|
|
44
|
-
"scripts": {
|
|
45
|
-
"build": "tsup",
|
|
46
|
-
"dev": "tsup --watch",
|
|
47
|
-
"typecheck": "tsc --noEmit",
|
|
48
|
-
"test": "vitest run",
|
|
49
|
-
"test:watch": "vitest",
|
|
50
|
-
"lint": "eslint src",
|
|
51
|
-
"lint:fix": "eslint src --fix"
|
|
52
|
-
},
|
|
53
44
|
"dependencies": {
|
|
54
|
-
"
|
|
55
|
-
"
|
|
45
|
+
"yauzl": "^3.2.0",
|
|
46
|
+
"@lexbuild/core": "1.0.2"
|
|
56
47
|
},
|
|
57
48
|
"devDependencies": {
|
|
58
49
|
"@types/node": "^25.3.2",
|
|
@@ -66,5 +57,14 @@
|
|
|
66
57
|
},
|
|
67
58
|
"publishConfig": {
|
|
68
59
|
"access": "public"
|
|
60
|
+
},
|
|
61
|
+
"scripts": {
|
|
62
|
+
"build": "tsup",
|
|
63
|
+
"dev": "tsup --watch",
|
|
64
|
+
"typecheck": "tsc --noEmit",
|
|
65
|
+
"test": "vitest run",
|
|
66
|
+
"test:watch": "vitest",
|
|
67
|
+
"lint": "eslint src",
|
|
68
|
+
"lint:fix": "eslint src --fix"
|
|
69
69
|
}
|
|
70
70
|
}
|