Simple storage for workshopper-adventure
Originally included as part of workshopper-adventure, mostly written by Martin Heidegger
Based on prior work of: @substack @rvagg
npm install workshopper-adventure-storage --save
const createStorage = require('workshopper-adventure-storage')
A default path to store data in.
Accepts a sequence of paths for path.resolve
to use as the storage directory.
const createStorage = require('workshopper-adventure-storage')
const storage = createStorage(createStorage.userDir, 'my-workshopper')
The path to store data in.
JSON encodes and writes a file to the storage directory. The following will
save the file as index.json
.
const data = {
foo: 'bar'
}
storage.save('index', data)
Retrieves and unserializes a file from storage.
var data = storage.get('index')
Clears the storage directory.
storage.reset()
This module seamlessly supports async operations using the .promises
object.
const storage =
createStorage(createStorage.userDir, 'promise-workshop')
.promises;
storage.dir // works synchronously
await storage.save('name', {})
await storage.get('name')
await storage.reset()