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

Serializer too #70

Open
peterbe opened this issue May 21, 2020 · 1 comment
Open

Serializer too #70

peterbe opened this issue May 21, 2020 · 1 comment

Comments

@peterbe
Copy link
Contributor

peterbe commented May 21, 2020

I'd love to be able to do fm.serialize(attributes, body).

This should work:

const metadata = {foo: "bar"}
const payload = "Hi there!"
const combined = fm.serialize(metadata, payload)
const parsed = fm(combined);
assert(JSON.stringify(parsed.attributes) === JSON.stringify(metadata))
assert(parsed.body === payload)
@peterbe
Copy link
Contributor Author

peterbe commented May 21, 2020

And, it should use yaml.safeDump.
So, perhaps to be complete, this should work too:

const metadata = {match: "!!js/regexp /pattern/gim"}
const payload = "Hi there!"
const combined = fm.serialize(metadata, payload, {unsafe: true} ) // Or something
const parsed = fm(combined);
assert(JSON.stringify(parsed.attributes) === JSON.stringify(metadata))
assert(parsed.body === payload)

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