diff --git a/README.md b/README.md index e8dc3a7..1692199 100644 --- a/README.md +++ b/README.md @@ -284,6 +284,16 @@ await db.put('key', 'value') +### `events` (boolean or object) + +Is db an event emitter, as indicated by a truthy value? And does it support specific events as indicated by nested properties? + +```js +if (db.supports.events && db.supports.events.open) { + db.once('open', () => { /* .. */}) +} +``` + ### `streams` (boolean) Does db have the methods `createReadStream`, `createKeyStream` and `createValueStream`, following the API currently documented in `levelup`? diff --git a/index.js b/index.js index 45967ef..6e3cfb4 100644 --- a/index.js +++ b/index.js @@ -29,8 +29,13 @@ module.exports = function supports (...manifests) { promises: manifest.promises || false, streams: manifest.streams || false, encodings: manifest.encodings || false, + events: maybeObject(manifest.events), // Methods that are not part of abstract-leveldown or levelup additionalMethods: Object.assign({}, manifest.additionalMethods) }) } + +function maybeObject (value) { + return !value ? false : Object.assign({}, value) +}