Skip to content

How do I edit a yaml file and keep new lines? #473

Closed Answered by KungWaz
KungWaz asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks for pointing me to the right place in the docs.

This seems to do what I want:

import { parseDocument } from "yaml";
import fs from "fs";

const path = "test.yaml";

const file = fs.readFileSync(path, "utf8");
const yaml = parseDocument(file);

yaml.setIn(["devices", "laptop", "name"], "asus");
yaml.deleteIn(["items", "mouse"]);

fs.writeFileSync(path, yaml.toString(), "utf-8");

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@KungWaz
Comment options

@eemeli
Comment options

@KungWaz
Comment options

Answer selected by KungWaz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants