Skip to content

Commit edd426d

Browse files
committed
chore: address reviewer feedback
1 parent 80cbb7a commit edd426d

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
"author": "Kubernetes Authors",
5656
"license": "Apache-2.0",
5757
"dependencies": {
58-
"@types/js-yaml": "^4.0.1",
5958
"@types/node": "^24.0.0",
6059
"@types/node-fetch": "^2.6.9",
6160
"@types/stream-buffers": "^3.0.3",

src/yaml.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
1-
import YAML from 'yaml';
1+
import yaml from 'yaml';
22
import { getSerializationType } from './util.js';
33
import { KubernetesObject } from './types.js';
44
import { ObjectSerializer } from './serializer.js';
55

66
/**
7-
* Load a Kubernetes object from YAML.
7+
* Load a single Kubernetes object from YAML.
88
* @param data - The YAML string to load.
9-
* @param opts - Optional YAML load options.
9+
* @param opts - Optional YAML parse options.
1010
* @returns The deserialized Kubernetes object.
1111
*/
12-
export function loadYaml<T>(data: string): T {
13-
const yml = YAML.parse(data, { version: '1.1' }) as any as KubernetesObject;
12+
export function loadYaml<T>(data: string, opts?: yaml.ParseOptions): T {
13+
const yml = yaml.parse(data, { version: '1.1', ...opts }) as any as KubernetesObject;
1414
if (!yml) {
15-
throw new Error('Failed to load YAML');
15+
throw new Error('Failed to load yaml');
1616
}
1717
const type = getSerializationType(yml.apiVersion, yml.kind);
1818
return ObjectSerializer.deserialize(yml, type) as T;
1919
}
2020

2121
/**
22-
* Load all Kubernetes objects from YAML.
22+
* Load all Kubernetes objects from a multi-document YAML string.
2323
* @param data - The YAML string to load.
24-
* @param opts - Optional YAML load options.
24+
* @param opts - Optional YAML parse options.
2525
* @returns An array of deserialized Kubernetes objects.
2626
*/
27-
export function loadAllYaml(data: string): any[] {
28-
const ymls = YAML.parseAllDocuments(data, { version: '1.1' });
27+
export function loadAllYaml(data: string, opts?: yaml.ParseOptions): KubernetesObject[] {
28+
const ymls = yaml.parseAllDocuments(data, { version: '1.1', ...opts });
2929
return ymls.map((doc) => {
30-
const obj = doc.toJS() as KubernetesObject;
30+
const obj = doc.toJSON() as KubernetesObject;
3131
const type = getSerializationType(obj.apiVersion, obj.kind);
3232
return ObjectSerializer.deserialize(obj, type);
3333
});
3434
}
3535

3636
/**
37-
* Dump a Kubernetes object to YAML.
37+
* Dump a Kubernetes object to a YAML string.
3838
* @param object - The Kubernetes object to dump.
39-
* @param opts - Optional YAML dump options.
40-
* @returns The YAML string representation of the serialized Kubernetes object.
39+
* @param opts - Optional YAML stringify options.
40+
* @returns The YAML string representation of the serialized object.
4141
*/
42-
export function dumpYaml(object: any): string {
42+
export function dumpYaml(object: any, opts?: yaml.ToStringOptions): string {
4343
const kubeObject = object as KubernetesObject;
4444
const type = getSerializationType(kubeObject.apiVersion, kubeObject.kind);
4545
const serialized = ObjectSerializer.serialize(kubeObject, type);
46-
return YAML.stringify(serialized);
46+
return yaml.stringify(serialized, opts);
4747
}

0 commit comments

Comments
 (0)