@lexbuild/core 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.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +102 -0
  3. package/package.json +11 -11
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,102 @@
1
+ # @lexbuild/core
2
+
3
+ [![npm](https://img.shields.io/npm/v/%40lexbuild%2Fcore?style=flat-square)](https://www.npmjs.com/package/@lexbuild/core)
4
+ [![license](https://img.shields.io/github/license/chris-c-thomas/lexbuild?style=flat-square)](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 provides the foundational building blocks for XML parsing infrastructure, AST definitions, and Markdown rendering for use by [`@lexbuild/usc`](https://www.npmjs.com/package/@lexbuild/usc) and [`@lexbuild/cli`](https://www.npmjs.com/package/@lexbuild/cli).
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ npm install @lexbuild/core
14
+ ```
15
+
16
+ ## What's Included
17
+
18
+ ### XML Parser
19
+
20
+ Streaming SAX parser with namespace normalization for USLM documents.
21
+
22
+ ```ts
23
+ import { XMLParser } from "@lexbuild/core";
24
+
25
+ const parser = new XMLParser();
26
+ parser.on("openElement", (name, attrs) => { /* ... */ });
27
+ parser.on("closeElement", (name) => { /* ... */ });
28
+ parser.on("text", (text) => { /* ... */ });
29
+
30
+ await parser.parseStream(readableStream);
31
+ ```
32
+
33
+ ### AST Builder
34
+
35
+ Stack-based XML-to-AST construction with a section-emit pattern for bounded memory usage.
36
+
37
+ ```ts
38
+ import { ASTBuilder } from "@lexbuild/core";
39
+
40
+ const builder = new ASTBuilder({
41
+ emitAt: "section",
42
+ onEmit: (node, context) => {
43
+ // Called with each completed section subtree
44
+ },
45
+ });
46
+ ```
47
+
48
+ ### Markdown Renderer
49
+
50
+ Stateless AST-to-Markdown conversion with YAML frontmatter, cross-reference link resolution, and notes filtering.
51
+
52
+ ```ts
53
+ import { renderDocument, generateFrontmatter, createLinkResolver } from "@lexbuild/core";
54
+
55
+ const markdown = renderDocument(sectionNode, frontmatterData, {
56
+ linkStyle: "relative",
57
+ resolveLink: resolver.resolve,
58
+ });
59
+ ```
60
+
61
+ ### AST Node Types
62
+
63
+ Full type definitions for the legislative document AST: `LevelNode`, `ContentNode`, `InlineNode`, `NoteNode`, `TableNode`, and more.
64
+
65
+ ```ts
66
+ import type { ASTNode, LevelNode, FrontmatterData, RenderOptions } from "@lexbuild/core";
67
+ ```
68
+
69
+ ### Namespace Constants
70
+
71
+ USLM, XHTML, Dublin Core namespace URIs and element classification sets.
72
+
73
+ ```ts
74
+ import { USLM_NS, XHTML_NS, LEVEL_ELEMENTS, CONTENT_ELEMENTS } from "@lexbuild/core";
75
+ ```
76
+
77
+ ## API Reference
78
+
79
+ | Export | Description |
80
+ |--------|-------------|
81
+ | `XMLParser` | Streaming SAX parser with namespace normalization |
82
+ | `ASTBuilder` | XML events to AST with section-emit pattern |
83
+ | `renderDocument()` | Render a section node with frontmatter to Markdown |
84
+ | `renderSection()` | Render a section-level node to Markdown |
85
+ | `renderNode()` | Render any AST node to Markdown |
86
+ | `generateFrontmatter()` | Generate YAML frontmatter block |
87
+ | `createLinkResolver()` | Create a cross-reference link resolver |
88
+ | `parseIdentifier()` | Parse a USLM identifier into components |
89
+ | `FORMAT_VERSION` | Output format version (`"1.0.0"`) |
90
+ | `GENERATOR` | Generator string for frontmatter |
91
+
92
+ ## Documentation
93
+
94
+ - [Monorepo README](https://github.com/chris-c-thomas/lexbuild#readme)
95
+ - [Architecture](https://github.com/chris-c-thomas/lexbuild/blob/main/docs/architecture.md)
96
+ - [Output Format](https://github.com/chris-c-thomas/lexbuild/blob/main/docs/output-format.md)
97
+ - [XML Element Reference](https://github.com/chris-c-thomas/lexbuild/blob/main/docs/xml-element-reference.md)
98
+ - [Extending](https://github.com/chris-c-thomas/lexbuild/blob/main/docs/extending.md)
99
+
100
+ ## License
101
+
102
+ [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/core",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Core AST definitions, parsing infrastructure, and format-agnostic renderers for the lexbuild ecosystem.",
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/core#readme",
8
8
  "bugs": {
9
9
  "url": "https://github.com/chris-c-thomas/lexbuild/issues"
10
10
  },
@@ -40,15 +40,6 @@
40
40
  "files": [
41
41
  "dist"
42
42
  ],
43
- "scripts": {
44
- "build": "tsup",
45
- "dev": "tsup --watch",
46
- "typecheck": "tsc --noEmit",
47
- "test": "vitest run",
48
- "test:watch": "vitest",
49
- "lint": "eslint src",
50
- "lint:fix": "eslint src --fix"
51
- },
52
43
  "dependencies": {
53
44
  "saxes": "^6.0.0",
54
45
  "yaml": "^2.7.0",
@@ -65,5 +56,14 @@
65
56
  },
66
57
  "publishConfig": {
67
58
  "access": "public"
59
+ },
60
+ "scripts": {
61
+ "build": "tsup",
62
+ "dev": "tsup --watch",
63
+ "typecheck": "tsc --noEmit",
64
+ "test": "vitest run",
65
+ "test:watch": "vitest",
66
+ "lint": "eslint src",
67
+ "lint:fix": "eslint src --fix"
68
68
  }
69
69
  }