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

Store and get Date objects #89

wants to merge 6 commits into
base: master


Copy link

commented Sep 10, 2019

Implementing a new feature described in issue sindresorhus/electron-store#18.
Type information is stored under ${INTERNAL_KEY}.type as suggested, the get method checks if there's a type key present, if there's it converts the value to the type before returning it.
The set methods checks if the value passed in is an instance of Date, if it is it stores it as an object like:

key: {
    __internal__.type: 'Date',
    val: valuePassedIn

I've also added a test to test.js to test for the setting and getting Date objects
Let me know if there's anything I could change. For example I chose to include type information only for Date objects, but it might be better to store type information for every key-value pair to be more consistent, but it would also make the object and the file larger.


This comment has been minimized.

Copy link

commented Sep 10, 2019

The travis CI tests/builds are passing, but node v12 on Windows failed to download node.js v12, so the code should be fine I think.


This comment has been minimized.

Copy link

commented Sep 10, 2019

This needs to be documented in the readme and index.d.ts. Also make sure that $ npm test passes locally.

sbencoding added 5 commits Sep 11, 2019
Made it easier to add extra types
Convert dates when in a nested object
Move conversion to store getter, setter
Test for getting, setting date within nested object
Add typescript tests for Date objects
Add typescript definition of extraTypes array

This comment has been minimized.

Copy link

commented Sep 11, 2019

Hi, sorry I've been busy yesterday, but here are the modifications.
I've updated the documentation in and in index.d.ts, I've added typescript tests for the Date serialization.
I've also refactored the code a bit, to handle Date objects within nested objects, moved serialization to the getter and setter directly instead of the user facing get and set method.
Adding new types/objects is also easier now, because the necessary information is stored in an array, instead of writing an if condition for every new type.
Let me know what you think

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.