connec/yaml-js

How to add a field with variables in yaml using yaml-js ?

sourcevault opened this issue · 1 comments

I am quite new to using yaml-js.

I have a field :

var:
  file: dist/main.js

that I would like to merge/add to another yaml file that may look like this :

var:
  file: &file
    dist/main.js
foo:
  - vitamin D
bar: *file

or just :

foo:
  - vitamin D
bar: much text

Essentially, how to "edit" yaml file before parsing.

Closing since the repository is going to be archived. yaml-js has been unmaintained for some time, so it would be best to use something else.


It's been ages since you posted your issue, but patching is out of scope for this library (and probably many YAML libraries). You could probably parse both documents and merge them as JS though:

const docA = yaml.load("hello: 1")
const docB = yaml.load("world: 2")

const merged = { ...docA, ...docB }
console.log(yaml.dump(merged))

As noted above, if this is still relevant to you at all I'd recommend using a different library!