0.0.7 • Published 2 months ago

yaml-transmute v0.0.7

Weekly downloads
-
License
ISC
Repository
github
Last release
2 months ago

Build Status

Yaml Transmute

If you need to change the content of a YAML file, without losing the key order or field comments, this is the right package for you.

While parsing, yaml-transmute builds a context (key order + comments) that is returned to the caller and can be later used to stringify the original object that was slightly modified.

This package is based on Eemeli's YAML npm package.

Example

import { parse, stringify, YAMLContext } from "yaml-transmute";

const [obj, ctx]: [unknown, YAMLContext] = parse(`# Comment
foo:
  bar: a # Inline comment
  baz: b
qux: 0
`);

console.log(obj); // { foo: {bar: "a", baz: "b" }, qux: 0 }

// Create a new object, similar to the original one
const newObj = { foo: { bar: 1 }, qux: true, quux: false };

// Stringify the new object, using the context gathered from `parse`
const stringifiedYaml = stringify(newObj, ctx);

console.log(stringifiedYaml);
// # Comment
// foo:
//   bar: 1 # Inline comment
// qux: true
// quux: false
0.0.7

2 months ago

0.0.5

2 months ago

0.0.6

2 months ago

0.0.4

3 months ago

0.0.3

3 months ago

0.0.2

3 months ago

0.0.1

3 months ago