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

Adding support for Maps #23

Open
luzlab opened this issue Sep 7, 2017 · 1 comment
Open

Adding support for Maps #23

luzlab opened this issue Sep 7, 2017 · 1 comment

Comments

@luzlab
Copy link

luzlab commented Sep 7, 2017

I'd like to add support for Map objects. I have some working code, but it's not clear where I should add code for new types. I also saw an issue on the meteor repo for this, and would like to submit a PR here so I can EJSON Maps in plain Node apps as well.

Any thoughts on how to add additional types?

import { Meteor } from 'meteor/meteor';
import { EJSON } from 'meteor/ejson';

Map.prototype.toJSONValue = function () {
  return JSON.stringify([...this]);
};

Map.prototype.typeName = function () {
  return 'Map';
};

EJSON.addType('Map', (jsonStr) => {
  return new Map(JSON.parse(jsonStr));
});
@luzlab
Copy link
Author

luzlab commented Dec 1, 2017

I created an npm module ejson-extras that extends EJSON to support Maps (and more) types.

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