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

YAML validation method #226

Closed
stcalica opened this issue Feb 4, 2021 · 4 comments
Closed

YAML validation method #226

stcalica opened this issue Feb 4, 2021 · 4 comments
Labels
docs Documentation should be improved

Comments

@stcalica
Copy link

stcalica commented Feb 4, 2021

For YAML validation I have to do a classic try/catch.
But it would be cool if we can have a validator that returned a true or false if the YAML is valid.

@stcalica stcalica added the enhancement New feature or request label Feb 4, 2021
@eemeli eemeli added docs Documentation should be improved and removed enhancement New feature or request labels Feb 5, 2021
@eemeli
Copy link
Owner

eemeli commented Feb 5, 2021

Something like that is already available via parseDocument, but maybe the docs are not clear enough for this use case?

const doc = YAML.parseDocument(src)
if (doc.errors.length === 0) console.log('src is valid YAML')

@stcalica
Copy link
Author

stcalica commented Feb 5, 2021

@eemeli interesting and can YAML.parseDocuments read from memory? it does not have to be a binary file -- src can be an object not a filepath?

@eemeli
Copy link
Owner

eemeli commented Feb 5, 2021

With the current API, src is expected to be a string. Once #203 gets merged, there'll be an API also supporting Node.js streams.

@eemeli
Copy link
Owner

eemeli commented Feb 21, 2021

Had a read-through of my own docs, and essentially the place where I would've added a clearer mention about this already has that: https://eemeli.org/yaml/#parsing-documents

@eemeli eemeli closed this as completed Feb 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation should be improved
Projects
None yet
Development

No branches or pull requests

2 participants