yaml-transmute
TypeScript icon, indicating that this package has built-in type declarations

0.0.7 • Public • Published

Yaml Transmute Logo

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

Package Sidebar

Install

npm i yaml-transmute

Weekly Downloads

293

Version

0.0.7

License

ISC

Unpacked Size

10.8 kB

Total Files

4

Last publish

Collaborators

  • costinsin