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

Are schemas broken? #706

Open
mjgs opened this issue May 5, 2023 · 1 comment
Open

Are schemas broken? #706

mjgs opened this issue May 5, 2023 · 1 comment

Comments

@mjgs
Copy link

mjgs commented May 5, 2023

I have been having an issue where date strings are being converted to date objects but I want to keep them as strings.

The load function works without a schema specified. I tried using the various schemas hoping I could get just plain old strings but specifying any schema results in the error:

TypeError: Cannot read properties of undefined (reading 'length')
[46](https://github.com/mjgs/convert-data-using-scripts/actions/runs/4892166937/jobs/8733596341#step:17:47)
    at composeNode (/home/runner/work/convert-data-using-scripts/convert-data-using-scripts/main/node_modules/js-yaml/lib/loader.js:1492:60)

I specified the schema like so:

const jsYaml = require('js-yaml');
const { fm, content } = extractFrontmatter(contents);
const extractedData = jsYaml.load(fm, {
  schema: 'FAILSAFE_SCHEMA'
});

Are schemas broken? Is there another way to prevent date strings being converted into date objects?

@mjgs
Copy link
Author

mjgs commented May 6, 2023

I figured this out, adding single quotes around the value ensures it gets parsed into a string rather than into a date object.

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

No branches or pull requests

1 participant