@ai-sdk-tool/rxml 0.1.0
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 +13 -0
- package/README.md +53 -0
- package/dist/index.cjs +2124 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +295 -0
- package/dist/index.d.ts +295 -0
- package/dist/index.js +2068 -0
- package/dist/index.js.map +1 -0
- package/index.d.ts +12 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2025 Woonggi Min (https://github.com/minpeter)
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# @ai-sdk-tool/rxml
|
|
2
|
+
|
|
3
|
+
Robust XML parser/streamer/builder for AI-generated and real-world XML. RXML focuses on resilience (lenient parsing when possible), JSON Schema–based coercion, efficient streaming, and clean stringification.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @ai-sdk-tool/rxml
|
|
9
|
+
# or
|
|
10
|
+
npm i @ai-sdk-tool/rxml
|
|
11
|
+
# or
|
|
12
|
+
yarn add @ai-sdk-tool/rxml
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick usage
|
|
16
|
+
|
|
17
|
+
- Parse with JSON Schema coercion
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { parse } from "@ai-sdk-tool/rxml";
|
|
21
|
+
|
|
22
|
+
const schema = {
|
|
23
|
+
type: "object",
|
|
24
|
+
properties: { title: { type: "string" } },
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const out = parse("<title>Hello</title>", schema);
|
|
28
|
+
// => { title: "Hello" }
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
- Stream large XML
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { createReadStream } from "node:fs";
|
|
35
|
+
import { processXMLStream } from "@ai-sdk-tool/rxml";
|
|
36
|
+
|
|
37
|
+
const stream = createReadStream("./large.xml", "utf8");
|
|
38
|
+
for await (const node of processXMLStream(stream)) {
|
|
39
|
+
// node is an RXMLNode or a comment string
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
- Stringify objects to XML
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { stringify } from "@ai-sdk-tool/rxml";
|
|
47
|
+
|
|
48
|
+
const xml = stringify("root", { title: "Hello" });
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## More docs
|
|
52
|
+
|
|
53
|
+
See full documentation at `docs/rxml.md` (in the repository root).
|