Skip to content

Commit 9c82e75

Browse files
committed
{doc} update v1-compat text in README
1 parent 91aedda commit 9c82e75

File tree

1 file changed

+3
-31
lines changed

1 file changed

+3
-31
lines changed

README.md

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -137,38 +137,10 @@ assert.deepEqual(
137137
138138
The package exports two functions from `@bgotink/kdl/v1-compat` to support documents written in KDL v1:
139139
140-
- `parseWithoutFormatting` parses a KDL v1 document without storing any formatting information.
141-
If the resulting document is passed to `format()`, a fresh KDL v2 document will be produced and any comments or formatting added by the original document's author will be lost.
142-
- `parseAndTransform` parses a KDL v1 document and transforms all linked formatting information to turn it into a valid KDL v2 document.
140+
- `parse` parses a KDL v1 document and transforms all linked formatting information to turn it into a valid KDL v2 document.
143141
If the resulting document is passed to `format()`, the resulting string will be the same document but in KDL v2 syntax. It will include all comments and formatting applied by the original document's author.
144-
145-
These functions embed the 0.1.x version of this package as parser for KDL v1.
146-
This old parser is many times larger and a lot slower than the parser written for KDL v2.
147-
As such, it is advised to lazy-load the KDL v1 support only if needed.
148-
For example, if you want to read configuration that can be KDL v2 or v1:
149-
150-
```js example
151-
import {readFile} from "node:fs/promises";
152-
import {parse} from "@bgotink/kdl";
153-
154-
export async function loadConfiguration(path) {
155-
const content = await readFile(path);
156-
157-
try {
158-
return parse(content);
159-
} catch (e) {
160-
const {parseWithoutFormatting} = await import("@bgotink/kdl/v1-compat");
161-
try {
162-
return parseWithoutFormatting(content);
163-
} catch (e2) {
164-
throw new AggregateError(
165-
[e, e2],
166-
`Failed to parse configuration at ${path}`,
167-
);
168-
}
169-
}
170-
}
171-
```
142+
- `parseCompat` parses a document that's either KDL v2 or KDL v1 and returns a valid KDL v2 document.
143+
This is a helper function that combines the regular `parse` function with the v1-compat `parse` function into a single function that supports both formats.
172144
173145
## Quirks
174146

0 commit comments

Comments
 (0)