Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a toJS(doc, options?) method to nodes #451

merged 2 commits into from Mar 27, 2023

Add a toJS(doc, options?) method to nodes #451

merged 2 commits into from Mar 27, 2023


Copy link

@eemeli eemeli commented Mar 15, 2023

Fixes #449
CC @MikeRalphson

This makes it easy to JS-ify parts of a YAML document, for example like this:

import { Alias, parseDocument } from 'yaml'

const doc = parseDocument(`
hello: &a
    message: Hello, world
outputs: *a

doc.getIn(['hello', 'world']).toJS(doc)
// { message: 'Hello, world' }

new Alias('a').toJS(doc)
// { world: { message: 'Hello, world' } }

The doc argument is required here to use the right schema, and for resolving aliases. A second options argument is also supported, with the same options as provided for doc.toJS().

Some of the utility functions previously defined in nodes/Node.ts need to be split off into their own nodes/identity.ts here to avoid circular dependencies.

@eemeli eemeli merged commit eda2d8a into main Mar 27, 2023
11 checks passed
@eemeli eemeli deleted the node-to-js branch March 27, 2023 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

Fully resolving Alias nodes
1 participant