Last active
April 30, 2017 20:45
-
-
Save tomprogers/8b0269f7d3ef2c63cb249554ba107b64 to your computer and use it in GitHub Desktop.
I wish this existed so I could use it in my Electron app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Path from 'path'; | |
import AppPaths from 'app-paths'; | |
import Persist from 'auto-persister'; | |
let settings = Persist.manageFile({ | |
path: Path.join(ApPaths.ConfigFile, 'default.myapp-settings'), | |
json: true, // read & write will marshall JSON automatically | |
autocreate: true, // file (and parent dirs) will be immediately created if they don't already exist | |
initialData: DefaultSettings, // value that will be returned if file doesn't exist, and that will be written if autocreate true | |
// all other options are passed to underlying FS methods | |
encoding: 'utf8', | |
... | |
}); | |
// invoke whenever to write data into the file | |
settings.write({ data: someObj, async: true }) | |
// invoke whenever to read data from file | |
settings.read({ async: true }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment