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

Remember source string for empty/null nodes #170

Closed
kasp1 opened this issue May 11, 2020 · 4 comments
Closed

Remember source string for empty/null nodes #170

kasp1 opened this issue May 11, 2020 · 4 comments
Labels
enhancement New feature or request
Milestone

Comments

@kasp1
Copy link

kasp1 commented May 11, 2020

Hi there, I can't seem to be able to stringify null as expected, any idea what can be wrong?

repro:

const YAML = require('yaml')

let doc = YAML.parse('hi:')

console.log(doc) // 'Object {hi: null}'

// expected string: 'hi:'
console.log(YAML.stringify(doc)) // '? hi'

YAML.scalarOptions.null.nullStr = ''

console.log(YAML.stringify(doc)) // '? hi'

YAML.scalarOptions.null.nullStr = '~'

console.log(YAML.stringify(doc)) // '? hi'
@eemeli
Copy link
Owner

eemeli commented May 12, 2020

The option to do what you want is { simpleKeys: true }. This isn't the first time this is asked, so I think I need to find a way to improve the docs on this, to make it clearer/more discoverable.

@eemeli eemeli added the docs Documentation should be improved label May 12, 2020
@eemeli
Copy link
Owner

eemeli commented May 12, 2020

Also, this is a bit besides what you're reporting, but the string representation of the null value isn't being retained at the AST level like it really ought to. Should fix that too.

@eemeli eemeli added the enhancement New feature or request label May 12, 2020
@kasp1
Copy link
Author

kasp1 commented May 13, 2020

Hi, thanks for your advice and for your library. :-)

@eemeli eemeli removed the docs Documentation should be improved label May 16, 2020
@eemeli eemeli changed the title Stringifying null Remember source string for empty/null nodes May 16, 2020
@eemeli eemeli added this to the yaml 2 milestone May 16, 2020
@eemeli
Copy link
Owner

eemeli commented Sep 16, 2020

Fixed in #193.

@eemeli eemeli closed this as completed Sep 16, 2020
@eemeli eemeli mentioned this issue Oct 5, 2020
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants