abstract-leveldown
Advanced tools
Comparing version 2.7.1 to 2.7.2
{ | ||
"name": "abstract-leveldown", | ||
"description": "An abstract prototype matching the LevelDOWN API", | ||
"version": "2.7.1", | ||
"version": "2.7.2", | ||
"contributors": [ | ||
@@ -6,0 +6,0 @@ "Rod Vagg <r@va.gg> (https://github.com/rvagg)", |
@@ -1,29 +0,24 @@ | ||
# Abstract LevelDOWN | ||
# abstract-leveldown | ||
<img alt="LevelDB Logo" height="100" src="http://leveldb.org/img/logo.svg"> | ||
> An abstract prototype matching the [`leveldown`](https://github.com/level/leveldown/) API. Useful for extending [`levelup`](https://github.com/level/levelup) functionality by providing a replacement to `leveldown`. | ||
[![Build Status](https://travis-ci.org/Level/abstract-leveldown.svg?branch=master)](http://travis-ci.org/Level/abstract-leveldown) | ||
[![dependencies](https://david-dm.org/Level/abstract-leveldown.svg)](https://david-dm.org/level/abstract-leveldown) | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/Level/abstract-leveldown.svg)](https://greenkeeper.io/) | ||
[![level badge][level-badge]](https://github.com/level/awesome) | ||
[![npm](https://img.shields.io/npm/v/abstract-leveldown.svg)](https://www.npmjs.com/package/abstract-leveldown) | ||
[![Travis](https://travis-ci.org/Level/abstract-leveldown.svg?branch=master)](http://travis-ci.org/Level/abstract-leveldown) | ||
[![david](https://david-dm.org/Level/abstract-leveldown.svg)](https://david-dm.org/level/abstract-leveldown) | ||
[![npm](https://img.shields.io/npm/dm/abstract-leveldown.svg)](https://www.npmjs.com/package/abstract-leveldown) | ||
[![NPM](https://nodei.co/npm/abstract-leveldown.png?downloads=true&downloadRank=true)](https://nodei.co/npm/abstract-leveldown/) | ||
[![NPM](https://nodei.co/npm-dl/abstract-leveldown.png?months=6&height=3)](https://nodei.co/npm/abstract-leveldown/) | ||
`abstract-leveldown` provides a simple, operational *noop* base prototype that's ready for extending. By default, all operations have sensible "noops" (operations that essentially do nothing). For example, simple operations such as `.open(callback)` and `.close(callback)` will simply invoke the callback (on a *next tick*). More complex operations perform sensible actions, for example: `.get(key, callback)` will always return a `'NotFound'` `Error` on the callback. | ||
An abstract prototype matching the **[LevelDOWN](https://github.com/level/leveldown/)** API. Useful for extending **[LevelUP](https://github.com/level/levelup)** functionality by providing a replacement to LevelDOWN. | ||
As of version 0.7, LevelUP allows you to pass a `'db'` option when you create a new instance. This will override the default LevelDOWN store with a LevelDOWN API compatible object. | ||
**Abstract LevelDOWN** provides a simple, operational *noop* base prototype that's ready for extending. By default, all operations have sensible "noops" (operations that essentially do nothing). For example, simple operations such as `.open(callback)` and `.close(callback)` will simply invoke the callback (on a *next tick*). More complex operations perform sensible actions, for example: `.get(key, callback)` will always return a `'NotFound'` `Error` on the callback. | ||
You add functionality by implementing the underscore versions of the operations. For example, to implement a `put()` operation you add a `_put()` method to your object. Each of these underscore methods override the default *noop* operations and are always provided with **consistent arguments**, regardless of what is passed in by the client. | ||
Additionally, all methods provide argument checking and sensible defaults for optional arguments. All bad-argument errors are compatible with LevelDOWN (they pass the LevelDOWN method arguments tests). For example, if you call `.open()` without a callback argument you'll get an `Error('open() requires a callback argument')`. Where optional arguments are involved, your underscore methods will receive sensible defaults. A `.get(key, callback)` will pass through to a `._get(key, options, callback)` where the `options` argument is an empty object. | ||
Additionally, all methods provide argument checking and sensible defaults for optional arguments. All bad-argument errors are compatible with `leveldown` (they pass the `leveldown` method arguments tests). For example, if you call `.open()` without a callback argument you'll get an `Error('open() requires a callback argument')`. Where optional arguments are involved, your underscore methods will receive sensible defaults. A `.get(key, callback)` will pass through to a `._get(key, options, callback)` where the `options` argument is an empty object. | ||
## Example | ||
A simplistic in-memory LevelDOWN replacement | ||
A simplistic in-memory `leveldown` replacement | ||
```js | ||
var util = require('util') | ||
, AbstractLevelDOWN = require('./').AbstractLevelDOWN | ||
var AbstractLevelDOWN = require('./').AbstractLevelDOWN | ||
@@ -48,3 +43,3 @@ // constructor, passes through the 'location' argument to the AbstractLevelDOWN constructor | ||
FakeLevelDOWN.prototype._put = function (key, value, options, callback) { | ||
key = '_' + key // safety, to avoid key='__proto__'-type skullduggery | ||
key = '_' + key // safety, to avoid key='__proto__'-type skullduggery | ||
this._store[key] = value | ||
@@ -70,10 +65,7 @@ process.nextTick(callback) | ||
// now use it in LevelUP | ||
// Now use it with levelup | ||
var levelup = require('levelup') | ||
var db = levelup('/who/cares/', { | ||
// the 'db' option replaces LevelDOWN | ||
db: function (location) { return new FakeLevelDOWN(location) } | ||
}) | ||
var db = levelup(new FakeLevelDOWN('/who/cares')) | ||
@@ -89,3 +81,3 @@ db.put('foo', 'bar', function (err) { | ||
See [MemDOWN](https://github.com/Level/memdown/) if you are looking for a complete in-memory replacement for LevelDOWN. | ||
See [`memdown`](https://github.com/Level/memdown/) if you are looking for a complete in-memory replacement for `leveldown`. | ||
@@ -148,3 +140,3 @@ ## Extensible API | ||
Returns `true` if `db` has the same public api as `AbstractLevelDOWN`, otherwise `false`. This is a utility function and it's not part of the extensible api. | ||
Returns `true` if `db` has the same public api as `abstract-leveldown`, otherwise `false`. This is a utility function and it's not part of the extensible api. | ||
@@ -155,3 +147,3 @@ <a name="contributing"></a> | ||
AbstractLevelDOWN is an **OPEN Open Source Project**. This means that: | ||
`abstract-leveldown` is an **OPEN Open Source Project**. This means that: | ||
@@ -166,4 +158,6 @@ > Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project. | ||
Copyright © 2013-2017 **AbstractLevelDOWN** [contributors](https://github.com/level/community#contributors). | ||
Copyright © 2013-2017 `abstract-leveldown` [contributors](https://github.com/level/community#contributors). | ||
**AbstractLevelDOWN** is licensed under the MIT license. All rights not explicitly granted in the MIT license are reserved. See the included `LICENSE.md` file for more details. | ||
`abstract-leveldown` is licensed under the MIT license. All rights not explicitly granted in the MIT license are reserved. See the included `LICENSE.md` file for more details. | ||
[level-badge]: http://leveldb.org/img/badge.svg |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
134210
158