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 option to output JS Maps, add generic support for iterables #51

Closed
wants to merge 4 commits into from

Conversation

eemeli
Copy link
Owner

@eemeli eemeli commented Nov 28, 2018

Fixes #46, fixes #49, fixes #50

On the YAML -> JS side, this adds a new option mapAsMap, with which YAML mappings are represented in JS as Map rather than Object instances:

YAML.parse('{[1, 2]: many}')
// { '[1,2]': 'many' }

YAML.parse('{[1, 2]: many}', { mapAsMap: true })
// Map { [ 1, 2 ] => 'many' }

The specific benefit of this is the ability to natively use non-string keys in mappings.

Then on the JS -> YAML side, iterable values are now supported by createNode(). The default is to parse them as sequences, but Map and its descendants are parsed as mappings.

@eemeli
Copy link
Owner Author

eemeli commented Nov 28, 2018

I'm considering adding a detector for Immutable.js maps as well, with something like iterable.constructor.isMap && iterable.constructor.isMap(iterable) as an alternative for iterable instanceof Map. Any thoughts on whether that would make sense, or would it be too specific? Checking iterable[Symbol.iterator].name === 'entries' might work as well, but it's a bit flaky.

@eemeli eemeli closed this in f17e7b8 Dec 1, 2018
@eemeli eemeli deleted the iterable branch December 1, 2018 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant