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
merged 2 commits into from
Mar 27, 2023
Merged

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

merged 2 commits into from
Mar 27, 2023

Conversation

eemeli
Copy link
Owner

@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
  world:
    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fully resolving Alias nodes
1 participant