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 support for traversing native Map objects like objects #96

Open
Fryuni opened this issue Oct 10, 2023 · 0 comments
Open

Add support for traversing native Map objects like objects #96

Fryuni opened this issue Oct 10, 2023 · 0 comments
Labels
enhancement Improvement of existing features

Comments

@Fryuni
Copy link
Member

Fryuni commented Oct 10, 2023

✨ Feature request

JSON pointers should traverse native Map objects like plain and objects.

Motivation

Plain objects are inefficient and ill advised when dealing with large number of keys or when handling dynamic, possibly untrusted, keys.

To allow an application to traverse a path using keys provided by the user requires a lot of care and consideration to create an appropriate object.

Example

The API would remain the same, but now also support maps.

const map = new Map([
  ['foo', 'bar']
]);

JsonPointer.parse('/foo').get(map)
// => 'bar'

Alternatives

The safe and correct alternative to handle user-provided keys is to construct a prototype-free object using Object.create(null) and populating it iteratively. Besides inconvenient and unergonomic, such operation is linear at best and linearithmic at worst due to how the representation of plain objects are optimized to have few, statically known, unchanging keys.

Additional context

https://www.builder.io/blog/maps

@Fryuni Fryuni added the enhancement Improvement of existing features label Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement of existing features
Projects
None yet
Development

No branches or pull requests

1 participant