@ac-kit/format-yaml 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 +28 -0
- package/README.md +34 -0
- package/dist/document-parse-stream.d.ts +11 -0
- package/dist/document-parse-stream.d.ts.map +1 -0
- package/dist/document-parse-stream.js +13 -0
- package/dist/document-parse-stream.js.map +1 -0
- package/dist/document-print-stream.d.ts +6 -0
- package/dist/document-print-stream.d.ts.map +1 -0
- package/dist/document-print-stream.js +8 -0
- package/dist/document-print-stream.js.map +1 -0
- package/dist/documents-parse-stream.d.ts +14 -0
- package/dist/documents-parse-stream.d.ts.map +1 -0
- package/dist/documents-parse-stream.js +28 -0
- package/dist/documents-parse-stream.js.map +1 -0
- package/dist/documents-print-stream.d.ts +6 -0
- package/dist/documents-print-stream.d.ts.map +1 -0
- package/dist/documents-print-stream.js +8 -0
- package/dist/documents-print-stream.js.map +1 -0
- package/dist/edit.d.ts +18 -0
- package/dist/edit.d.ts.map +1 -0
- package/dist/edit.js +24 -0
- package/dist/edit.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/parse-stream.d.ts +7 -0
- package/dist/parse-stream.d.ts.map +1 -0
- package/dist/parse-stream.js +9 -0
- package/dist/parse-stream.js.map +1 -0
- package/dist/parse.d.ts +9 -0
- package/dist/parse.d.ts.map +1 -0
- package/dist/parse.js +19 -0
- package/dist/parse.js.map +1 -0
- package/dist/print-stream.d.ts +7 -0
- package/dist/print-stream.d.ts.map +1 -0
- package/dist/print-stream.js +9 -0
- package/dist/print-stream.js.map +1 -0
- package/dist/print.d.ts +7 -0
- package/dist/print.d.ts.map +1 -0
- package/dist/print.js +15 -0
- package/dist/print.js.map +1 -0
- package/package.json +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2026 Anthony Champagne and contributors
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# @ac-kit/format-yaml
|
|
2
|
+
|
|
3
|
+
YAML — including the part most parsers gloss over: a single file may hold
|
|
4
|
+
several documents, separated by `---`, and a Kubernetes manifest or a CI config
|
|
5
|
+
usually does.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { parseAllYamlDocuments, parseYaml, printYaml } from "@ac-kit/format-yaml";
|
|
9
|
+
|
|
10
|
+
parseYaml("port: 8080");
|
|
11
|
+
|
|
12
|
+
// A multi-document file, as one value per document.
|
|
13
|
+
for (const document of parseAllYamlDocuments(manifestSource)) {
|
|
14
|
+
deploy(document);
|
|
15
|
+
}
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## What it exposes
|
|
19
|
+
|
|
20
|
+
- `parseYaml` / `printYaml` — a single document.
|
|
21
|
+
- `parseYamlDocument` / `printYamlDocument` — the document node, when you need
|
|
22
|
+
its metadata rather than only its value.
|
|
23
|
+
- `parseAllYamlDocuments` — every document in a multi-document stream.
|
|
24
|
+
- `editYaml` / `createYamlEdits` — change one value, leaving the rest of the
|
|
25
|
+
source as it was.
|
|
26
|
+
- `YamlParseStream`, `YamlPrintStream`, and the document-oriented stream
|
|
27
|
+
variants — `TransformStream`s over `@ac-kit/format-core`.
|
|
28
|
+
|
|
29
|
+
Portable: no Node.js built-ins, so it runs unchanged in browsers, Deno, Bun and
|
|
30
|
+
edge runtimes.
|
|
31
|
+
|
|
32
|
+
See the
|
|
33
|
+
[generated API docs](https://anthochamp.github.io/node-essentials/api/format-yaml/)
|
|
34
|
+
for the full reference.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as yaml from "yaml";
|
|
2
|
+
export type YamlDocumentParseStreamOptions = {
|
|
3
|
+
parseOptions?: yaml.ParseOptions;
|
|
4
|
+
documentOptions?: yaml.DocumentOptions;
|
|
5
|
+
schemaOptions?: yaml.SchemaOptions;
|
|
6
|
+
};
|
|
7
|
+
/** Buffers a byte stream and emits one {@link yaml.Document} on flush. */
|
|
8
|
+
export declare class YamlDocumentParseStream extends TransformStream<Uint8Array, yaml.Document> {
|
|
9
|
+
constructor(options?: YamlDocumentParseStreamOptions);
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=document-parse-stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document-parse-stream.d.ts","sourceRoot":"","sources":["../src/document-parse-stream.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,MAAM,MAAM,8BAA8B,GAAG;IAC5C,YAAY,CAAC,EAAE,IAAI,CAAC,YAAY,CAAC;IACjC,eAAe,CAAC,EAAE,IAAI,CAAC,eAAe,CAAC;IACvC,aAAa,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC;CACnC,CAAC;AAEF,0EAA0E;AAC1E,qBAAa,uBAAwB,SAAQ,eAAe,CAC3D,UAAU,EACV,IAAI,CAAC,QAAQ,CACb;IACA,YAAY,OAAO,GAAE,8BAAmC,EAYvD;CACD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { wholeTextParseTransformer } from "@ac-kit/format-core";
|
|
2
|
+
import * as yaml from "yaml";
|
|
3
|
+
/** Buffers a byte stream and emits one {@link yaml.Document} on flush. */
|
|
4
|
+
export class YamlDocumentParseStream extends TransformStream {
|
|
5
|
+
constructor(options = {}) {
|
|
6
|
+
super(wholeTextParseTransformer((source) => yaml.parseDocument(source, {
|
|
7
|
+
...options.parseOptions,
|
|
8
|
+
...options.documentOptions,
|
|
9
|
+
...options.schemaOptions,
|
|
10
|
+
}), "YAML document"));
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=document-parse-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document-parse-stream.js","sourceRoot":"","sources":["../src/document-parse-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAQ7B,0EAA0E;AAC1E,MAAM,OAAO,uBAAwB,SAAQ,eAG5C;IACA,YAAY,OAAO,GAAmC,EAAE;QACvD,KAAK,CACJ,yBAAyB,CACxB,CAAC,MAAM,EAAE,EAAE,CACV,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE;YAC1B,GAAG,OAAO,CAAC,YAAY;YACvB,GAAG,OAAO,CAAC,eAAe;YAC1B,GAAG,OAAO,CAAC,aAAa;SACxB,CAAC,EACH,eAAe,CACf,CACD,CAAC;IACH,CAAC;CACD"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as yaml from "yaml";
|
|
2
|
+
/** Emits each incoming {@link yaml.Document} as UTF-8 encoded YAML. */
|
|
3
|
+
export declare class YamlDocumentPrintStream extends TransformStream<yaml.Document, Uint8Array> {
|
|
4
|
+
constructor(options?: yaml.ToStringOptions);
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=document-print-stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document-print-stream.d.ts","sourceRoot":"","sources":["../src/document-print-stream.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,uEAAuE;AACvE,qBAAa,uBAAwB,SAAQ,eAAe,CAC3D,IAAI,CAAC,QAAQ,EACb,UAAU,CACV;IACA,YAAY,OAAO,GAAE,IAAI,CAAC,eAAoB,EAO7C;CACD"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { textPrintTransformer } from "@ac-kit/format-core";
|
|
2
|
+
/** Emits each incoming {@link yaml.Document} as UTF-8 encoded YAML. */
|
|
3
|
+
export class YamlDocumentPrintStream extends TransformStream {
|
|
4
|
+
constructor(options = {}) {
|
|
5
|
+
super(textPrintTransformer((document) => document.toString(options), "YAML document"));
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=document-print-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document-print-stream.js","sourceRoot":"","sources":["../src/document-print-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAG3D,uEAAuE;AACvE,MAAM,OAAO,uBAAwB,SAAQ,eAG5C;IACA,YAAY,OAAO,GAAyB,EAAE;QAC7C,KAAK,CACJ,oBAAoB,CACnB,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,EACxC,eAAe,CACf,CACD,CAAC;IACH,CAAC;CACD"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as yaml from "yaml";
|
|
2
|
+
export type YamlDocumentsParseStreamOptions = {
|
|
3
|
+
customTags?: yaml.SchemaOptions["customTags"];
|
|
4
|
+
version?: yaml.DocumentOptions["version"];
|
|
5
|
+
schema?: yaml.SchemaOptions["schema"];
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Buffers a byte stream and emits every {@link yaml.Document} it contains on
|
|
9
|
+
* flush.
|
|
10
|
+
*/
|
|
11
|
+
export declare class YamlDocumentsParseStream extends TransformStream<Uint8Array, yaml.Document> {
|
|
12
|
+
constructor(options?: YamlDocumentsParseStreamOptions);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=documents-parse-stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documents-parse-stream.d.ts","sourceRoot":"","sources":["../src/documents-parse-stream.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,MAAM,MAAM,+BAA+B,GAAG;IAC7C,UAAU,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;IAC9C,OAAO,CAAC,EAAE,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;IAC1C,MAAM,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;CACtC,CAAC;AAEF;;;GAGG;AACH,qBAAa,wBAAyB,SAAQ,eAAe,CAC5D,UAAU,EACV,IAAI,CAAC,QAAQ,CACb;IACA,YAAY,OAAO,GAAE,+BAAoC,EAkBxD;CACD"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { concatBytes, decodeText } from "@ac-kit/core";
|
|
2
|
+
import * as yaml from "yaml";
|
|
3
|
+
/**
|
|
4
|
+
* Buffers a byte stream and emits every {@link yaml.Document} it contains on
|
|
5
|
+
* flush.
|
|
6
|
+
*/
|
|
7
|
+
export class YamlDocumentsParseStream extends TransformStream {
|
|
8
|
+
constructor(options = {}) {
|
|
9
|
+
const chunks = [];
|
|
10
|
+
super({
|
|
11
|
+
transform(chunk) {
|
|
12
|
+
chunks.push(chunk);
|
|
13
|
+
},
|
|
14
|
+
flush(controller) {
|
|
15
|
+
const source = decodeText(concatBytes(chunks), "utf-8");
|
|
16
|
+
try {
|
|
17
|
+
for (const document of yaml.parseAllDocuments(source, options)) {
|
|
18
|
+
controller.enqueue(document);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
throw new Error("parse YAML documents", { cause: error });
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=documents-parse-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documents-parse-stream.js","sourceRoot":"","sources":["../src/documents-parse-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAQ7B;;;GAGG;AACH,MAAM,OAAO,wBAAyB,SAAQ,eAG7C;IACA,YAAY,OAAO,GAAoC,EAAE;QACxD,MAAM,MAAM,GAAiB,EAAE,CAAC;QAChC,KAAK,CAAC;YACL,SAAS,CAAC,KAAK;gBACd,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACpB,CAAC;YACD,KAAK,CAAC,UAAU;gBACf,MAAM,MAAM,GAAG,UAAU,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC;gBAExD,IAAI,CAAC;oBACJ,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,iBAAiB,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;wBAChE,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;oBAC9B,CAAC;gBACF,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBAChB,MAAM,IAAI,KAAK,CAAC,sBAAsB,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;gBAC3D,CAAC;YACF,CAAC;SACD,CAAC,CAAC;IACJ,CAAC;CACD"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as yaml from "yaml";
|
|
2
|
+
/** Emits each incoming {@link yaml.Document} as UTF-8 encoded YAML. */
|
|
3
|
+
export declare class YamlDocumentsPrintStream extends TransformStream<yaml.Document, Uint8Array> {
|
|
4
|
+
constructor(options?: yaml.ToStringOptions);
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=documents-print-stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documents-print-stream.d.ts","sourceRoot":"","sources":["../src/documents-print-stream.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,uEAAuE;AACvE,qBAAa,wBAAyB,SAAQ,eAAe,CAC5D,IAAI,CAAC,QAAQ,EACb,UAAU,CACV;IACA,YAAY,OAAO,GAAE,IAAI,CAAC,eAAoB,EAO7C;CACD"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { textPrintTransformer } from "@ac-kit/format-core";
|
|
2
|
+
/** Emits each incoming {@link yaml.Document} as UTF-8 encoded YAML. */
|
|
3
|
+
export class YamlDocumentsPrintStream extends TransformStream {
|
|
4
|
+
constructor(options = {}) {
|
|
5
|
+
super(textPrintTransformer((document) => document.toString(options), "YAML documents"));
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=documents-print-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documents-print-stream.js","sourceRoot":"","sources":["../src/documents-print-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAG3D,uEAAuE;AACvE,MAAM,OAAO,wBAAyB,SAAQ,eAG7C;IACA,YAAY,OAAO,GAAyB,EAAE;QAC7C,KAAK,CACJ,oBAAoB,CACnB,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,EACxC,gBAAgB,CAChB,CACD,CAAC;IACH,CAAC;CACD"}
|
package/dist/edit.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PropertyPath, TextEdit } from "@ac-kit/core";
|
|
2
|
+
import * as yaml from "yaml";
|
|
3
|
+
import { type YamlPrintOptions } from "./print.js";
|
|
4
|
+
/**
|
|
5
|
+
* Returns the {@link TextEdit} needed to set `value` at `path`.
|
|
6
|
+
*
|
|
7
|
+
* Medium-fidelity: uses `yaml.Document` mutation then reprints — a single
|
|
8
|
+
* full-replace edit.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createYamlEdits(source: string, path: PropertyPath, value: unknown, options?: yaml.ToStringOptions): TextEdit[];
|
|
11
|
+
/**
|
|
12
|
+
* Sets `value` at `path` in a YAML string and returns the updated source.
|
|
13
|
+
*
|
|
14
|
+
* Medium-fidelity: uses `yaml.Document` mutation then reprints — preserves
|
|
15
|
+
* structure outside the patched section but discards comments near it.
|
|
16
|
+
*/
|
|
17
|
+
export declare function editYaml(source: string, path: PropertyPath, value: unknown, options?: YamlPrintOptions): string;
|
|
18
|
+
//# sourceMappingURL=edit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../src/edit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAkB,MAAM,cAAc,CAAC;AACtE,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD;;;;;GAKG;AACH,wBAAgB,eAAe,CAC9B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,YAAY,EAClB,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,IAAI,CAAC,eAAe,GAC5B,QAAQ,EAAE,CAKZ;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CACvB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,YAAY,EAClB,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,gBAAgB,GACxB,MAAM,CAER"}
|
package/dist/edit.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { applyTextEdits } from "@ac-kit/core";
|
|
2
|
+
import * as yaml from "yaml";
|
|
3
|
+
/**
|
|
4
|
+
* Returns the {@link TextEdit} needed to set `value` at `path`.
|
|
5
|
+
*
|
|
6
|
+
* Medium-fidelity: uses `yaml.Document` mutation then reprints — a single
|
|
7
|
+
* full-replace edit.
|
|
8
|
+
*/
|
|
9
|
+
export function createYamlEdits(source, path, value, options) {
|
|
10
|
+
const doc = yaml.parseDocument(source);
|
|
11
|
+
doc.setIn(path, value);
|
|
12
|
+
const newSource = doc.toString(options);
|
|
13
|
+
return [{ offset: 0, length: source.length, content: newSource }];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Sets `value` at `path` in a YAML string and returns the updated source.
|
|
17
|
+
*
|
|
18
|
+
* Medium-fidelity: uses `yaml.Document` mutation then reprints — preserves
|
|
19
|
+
* structure outside the patched section but discards comments near it.
|
|
20
|
+
*/
|
|
21
|
+
export function editYaml(source, path, value, options) {
|
|
22
|
+
return applyTextEdits(source, createYamlEdits(source, path, value, options));
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=edit.js.map
|
package/dist/edit.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"edit.js","sourceRoot":"","sources":["../src/edit.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,cAAc,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAI7B;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAC9B,MAAc,EACd,IAAkB,EAClB,KAAc,EACd,OAA8B;IAE9B,MAAM,GAAG,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IACvC,GAAG,CAAC,KAAK,CAAC,IAA2B,EAAE,KAAK,CAAC,CAAC;IAC9C,MAAM,SAAS,GAAG,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACxC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;AACnE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CACvB,MAAc,EACd,IAAkB,EAClB,KAAc,EACd,OAA0B;IAE1B,OAAO,cAAc,CAAC,MAAM,EAAE,eAAe,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;AAC9E,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./document-parse-stream.js";
|
|
2
|
+
export * from "./document-print-stream.js";
|
|
3
|
+
export * from "./documents-parse-stream.js";
|
|
4
|
+
export * from "./documents-print-stream.js";
|
|
5
|
+
export * from "./edit.js";
|
|
6
|
+
export * from "./parse-stream.js";
|
|
7
|
+
export * from "./parse.js";
|
|
8
|
+
export * from "./print-stream.js";
|
|
9
|
+
export * from "./print.js";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./document-parse-stream.js";
|
|
2
|
+
export * from "./document-print-stream.js";
|
|
3
|
+
export * from "./documents-parse-stream.js";
|
|
4
|
+
export * from "./documents-print-stream.js";
|
|
5
|
+
export * from "./edit.js";
|
|
6
|
+
export * from "./parse-stream.js";
|
|
7
|
+
export * from "./parse.js";
|
|
8
|
+
export * from "./print-stream.js";
|
|
9
|
+
export * from "./print.js";
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as yaml from "yaml";
|
|
2
|
+
export type YamlParseStreamOptions = yaml.ParseOptions & yaml.DocumentOptions & yaml.SchemaOptions;
|
|
3
|
+
/** Buffers a byte stream and emits one parsed YAML value on flush. */
|
|
4
|
+
export declare class YamlParseStream extends TransformStream<Uint8Array, unknown> {
|
|
5
|
+
constructor(options?: YamlParseStreamOptions);
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=parse-stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-stream.d.ts","sourceRoot":"","sources":["../src/parse-stream.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,MAAM,MAAM,sBAAsB,GAAG,IAAI,CAAC,YAAY,GACrD,IAAI,CAAC,eAAe,GACpB,IAAI,CAAC,aAAa,CAAC;AAEpB,sEAAsE;AACtE,qBAAa,eAAgB,SAAQ,eAAe,CAAC,UAAU,EAAE,OAAO,CAAC;IACxE,YAAY,OAAO,GAAE,sBAA2B,EAO/C;CACD"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { wholeTextParseTransformer } from "@ac-kit/format-core";
|
|
2
|
+
import * as yaml from "yaml";
|
|
3
|
+
/** Buffers a byte stream and emits one parsed YAML value on flush. */
|
|
4
|
+
export class YamlParseStream extends TransformStream {
|
|
5
|
+
constructor(options = {}) {
|
|
6
|
+
super(wholeTextParseTransformer((source) => yaml.parse(source, options), "YAML"));
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=parse-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-stream.js","sourceRoot":"","sources":["../src/parse-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAM7B,sEAAsE;AACtE,MAAM,OAAO,eAAgB,SAAQ,eAAoC;IACxE,YAAY,OAAO,GAA2B,EAAE;QAC/C,KAAK,CACJ,yBAAyB,CACxB,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,CAAY,EAClD,MAAM,CACN,CACD,CAAC;IACH,CAAC;CACD"}
|
package/dist/parse.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as yaml from "yaml";
|
|
2
|
+
export type YamlParseOptions = yaml.ParseOptions & yaml.DocumentOptions & yaml.SchemaOptions & yaml.ToJSOptions;
|
|
3
|
+
/** Parses a YAML string into a plain JS value. */
|
|
4
|
+
export declare function parseYaml(source: string, options?: YamlParseOptions): unknown;
|
|
5
|
+
/** Parses a YAML string into a {@link yaml.Document} (CST-level). */
|
|
6
|
+
export declare function parseYamlDocument(source: string, options?: yaml.ParseOptions & yaml.DocumentOptions & yaml.SchemaOptions): yaml.Document;
|
|
7
|
+
/** Parses all YAML documents from a multi-document string. */
|
|
8
|
+
export declare function parseAllYamlDocuments(source: string, options?: yaml.ParseOptions & yaml.DocumentOptions & yaml.SchemaOptions): yaml.Document[];
|
|
9
|
+
//# sourceMappingURL=parse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,YAAY,GAC/C,IAAI,CAAC,eAAe,GACpB,IAAI,CAAC,aAAa,GAClB,IAAI,CAAC,WAAW,CAAC;AAElB,kDAAkD;AAClD,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAM7E;AAED,qEAAqE;AACrE,wBAAgB,iBAAiB,CAChC,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,aAAa,GACrE,IAAI,CAAC,QAAQ,CAEf;AAED,8DAA8D;AAC9D,wBAAgB,qBAAqB,CACpC,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,aAAa,GACrE,IAAI,CAAC,QAAQ,EAAE,CAEjB"}
|
package/dist/parse.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as yaml from "yaml";
|
|
2
|
+
/** Parses a YAML string into a plain JS value. */
|
|
3
|
+
export function parseYaml(source, options) {
|
|
4
|
+
try {
|
|
5
|
+
return yaml.parse(source, options);
|
|
6
|
+
}
|
|
7
|
+
catch (error) {
|
|
8
|
+
throw new Error("parse YAML", { cause: error });
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
/** Parses a YAML string into a {@link yaml.Document} (CST-level). */
|
|
12
|
+
export function parseYamlDocument(source, options) {
|
|
13
|
+
return yaml.parseDocument(source, options);
|
|
14
|
+
}
|
|
15
|
+
/** Parses all YAML documents from a multi-document string. */
|
|
16
|
+
export function parseAllYamlDocuments(source, options) {
|
|
17
|
+
return yaml.parseAllDocuments(source, options);
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=parse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAO7B,kDAAkD;AAClD,MAAM,UAAU,SAAS,CAAC,MAAc,EAAE,OAA0B;IACnE,IAAI,CAAC;QACJ,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,YAAY,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IACjD,CAAC;AACF,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,iBAAiB,CAChC,MAAc,EACd,OAAuE;IAEvE,OAAO,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC5C,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,qBAAqB,CACpC,MAAc,EACd,OAAuE;IAEvE,OAAO,IAAI,CAAC,iBAAiB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as yaml from "yaml";
|
|
2
|
+
export type YamlPrintStreamOptions = yaml.DocumentOptions & yaml.SchemaOptions & yaml.ParseOptions & yaml.CreateNodeOptions & yaml.ToStringOptions;
|
|
3
|
+
/** Emits each incoming value as a UTF-8 encoded YAML document. */
|
|
4
|
+
export declare class YamlPrintStream extends TransformStream<unknown, Uint8Array> {
|
|
5
|
+
constructor(options?: YamlPrintStreamOptions);
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=print-stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"print-stream.d.ts","sourceRoot":"","sources":["../src/print-stream.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,MAAM,MAAM,sBAAsB,GAAG,IAAI,CAAC,eAAe,GACxD,IAAI,CAAC,aAAa,GAClB,IAAI,CAAC,YAAY,GACjB,IAAI,CAAC,iBAAiB,GACtB,IAAI,CAAC,eAAe,CAAC;AAEtB,kEAAkE;AAClE,qBAAa,eAAgB,SAAQ,eAAe,CAAC,OAAO,EAAE,UAAU,CAAC;IACxE,YAAY,OAAO,GAAE,sBAA2B,EAI/C;CACD"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { textPrintTransformer } from "@ac-kit/format-core";
|
|
2
|
+
import * as yaml from "yaml";
|
|
3
|
+
/** Emits each incoming value as a UTF-8 encoded YAML document. */
|
|
4
|
+
export class YamlPrintStream extends TransformStream {
|
|
5
|
+
constructor(options = {}) {
|
|
6
|
+
super(textPrintTransformer((value) => yaml.stringify(value, options), "YAML"));
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=print-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"print-stream.js","sourceRoot":"","sources":["../src/print-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAQ7B,kEAAkE;AAClE,MAAM,OAAO,eAAgB,SAAQ,eAAoC;IACxE,YAAY,OAAO,GAA2B,EAAE;QAC/C,KAAK,CACJ,oBAAoB,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,CACvE,CAAC;IACH,CAAC;CACD"}
|
package/dist/print.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as yaml from "yaml";
|
|
2
|
+
export type YamlPrintOptions = yaml.DocumentOptions & yaml.SchemaOptions & yaml.CreateNodeOptions & yaml.ToStringOptions;
|
|
3
|
+
/** Serializes a value to a YAML string. */
|
|
4
|
+
export declare function printYaml(value: unknown, options?: YamlPrintOptions): string;
|
|
5
|
+
/** Serializes a {@link yaml.Document} to a YAML string. */
|
|
6
|
+
export declare function printYamlDocument(doc: yaml.Document, options?: yaml.ToStringOptions): string;
|
|
7
|
+
//# sourceMappingURL=print.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"print.d.ts","sourceRoot":"","sources":["../src/print.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,eAAe,GAClD,IAAI,CAAC,aAAa,GAClB,IAAI,CAAC,iBAAiB,GACtB,IAAI,CAAC,eAAe,CAAC;AAEtB,2CAA2C;AAC3C,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,MAAM,CAM5E;AAED,2DAA2D;AAC3D,wBAAgB,iBAAiB,CAChC,GAAG,EAAE,IAAI,CAAC,QAAQ,EAClB,OAAO,CAAC,EAAE,IAAI,CAAC,eAAe,GAC5B,MAAM,CAER"}
|
package/dist/print.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as yaml from "yaml";
|
|
2
|
+
/** Serializes a value to a YAML string. */
|
|
3
|
+
export function printYaml(value, options) {
|
|
4
|
+
try {
|
|
5
|
+
return yaml.stringify(value, options);
|
|
6
|
+
}
|
|
7
|
+
catch (error) {
|
|
8
|
+
throw new Error("print YAML", { cause: error });
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
/** Serializes a {@link yaml.Document} to a YAML string. */
|
|
12
|
+
export function printYamlDocument(doc, options) {
|
|
13
|
+
return doc.toString(options);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=print.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"print.js","sourceRoot":"","sources":["../src/print.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAO7B,2CAA2C;AAC3C,MAAM,UAAU,SAAS,CAAC,KAAc,EAAE,OAA0B;IACnE,IAAI,CAAC;QACJ,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACvC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,YAAY,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IACjD,CAAC;AACF,CAAC;AAED,2DAA2D;AAC3D,MAAM,UAAU,iBAAiB,CAChC,GAAkB,EAClB,OAA8B;IAE9B,OAAO,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AAC9B,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ac-kit/format-yaml",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "YAML parse and print streams over @ac-kit/format-core.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"config",
|
|
7
|
+
"parser",
|
|
8
|
+
"streams",
|
|
9
|
+
"yaml"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://anthochamp.github.io/node-essentials/api/format-yaml/",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/anthochamp/node-essentials/issues"
|
|
14
|
+
},
|
|
15
|
+
"license": "BSD-3-Clause",
|
|
16
|
+
"author": "Anthony Champagne <dev@anthonychampagne.fr>",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/anthochamp/node-essentials.git",
|
|
20
|
+
"directory": "packages/format-yaml"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"type": "module",
|
|
26
|
+
"sideEffects": false,
|
|
27
|
+
"main": "./dist/index.js",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": "./dist/index.js",
|
|
30
|
+
"./file": "./dist/file.js"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"main": "./dist/index.js",
|
|
34
|
+
"exports": {
|
|
35
|
+
".": "./dist/index.js",
|
|
36
|
+
"./file": "./dist/file.js"
|
|
37
|
+
},
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"compile": "tsc -p ./tsconfig.build.json -outDir dist",
|
|
42
|
+
"compile:check": "tsc -noEmit -p ./tsconfig.json",
|
|
43
|
+
"clean": "rimraf dist",
|
|
44
|
+
"build": "yarn clean && yarn compile",
|
|
45
|
+
"test": "yarn run -T vitest run",
|
|
46
|
+
"prepack": "yarn build"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@ac-kit/core": "^0.1.0",
|
|
50
|
+
"@ac-kit/format-core": "^0.1.0",
|
|
51
|
+
"@types/node": "^26.5.1",
|
|
52
|
+
"yaml": "^2.9.0"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@ac-kit/tsconfig": "0.1.0",
|
|
56
|
+
"@ac-kit/typedoc-config": "0.1.0",
|
|
57
|
+
"@ac-kit/vitest-config": "0.1.0",
|
|
58
|
+
"@typescript/native": "typescript@7.0.2",
|
|
59
|
+
"rimraf": "6.1.3",
|
|
60
|
+
"typedoc": "0.28.20",
|
|
61
|
+
"typescript": "@typescript/typescript6@6.0.2"
|
|
62
|
+
},
|
|
63
|
+
"engines": {
|
|
64
|
+
"node": ">=24"
|
|
65
|
+
}
|
|
66
|
+
}
|