localstorage-down
Advanced tools
Comparing version 0.5.0 to 0.5.1
44
index.js
@@ -16,19 +16,20 @@ 'use strict'; | ||
this._reverse = !!options.reverse; | ||
// Test for empty buffer in end | ||
if (options.end instanceof Buffer) { | ||
if (options.end.length === 0) { | ||
this._end = this.db.container.key(this._dbsize - 1); | ||
} | ||
} else { | ||
this._end = options.end; | ||
} | ||
this._end = options.end; | ||
this._start = options.start; | ||
this._gt = options.gt; | ||
this._gte = options.gte; | ||
this._lt = options.lt; | ||
this._lte = options.lte; | ||
this._exclusiveStart = options.exclusiveStart; | ||
this._limit = options.limit; | ||
this._count = 0; | ||
if (options.start) { | ||
this._pos = this.db.container.indexOfKey(options.start); | ||
if (this._reverse && this.db.container.key(this._pos) !== options.start) { | ||
this._pos--; | ||
if (this._start) { | ||
this._pos = this.db.container.indexOfKey(this._start); | ||
if (this._reverse) { | ||
if (this._exclusiveStart || this.db.container.key(this._pos) !== this._start) { | ||
this._pos--; | ||
} | ||
} else if (this._exclusiveStart && this.db.container.key(this._pos) === this._start) { | ||
this._pos++; | ||
} | ||
@@ -48,3 +49,2 @@ } else { | ||
var key = this.db.container.key(this._pos); | ||
var value; | ||
@@ -55,3 +55,2 @@ if (!!this._end && (this._reverse ? key < this._end : key > this._end)) { | ||
if (!!this._limit && this._limit > 0 && this._count++ >= this._limit) { | ||
@@ -61,6 +60,13 @@ return nextTick(callback); | ||
value = this.db.container.getItem(key); | ||
if ((this._lt && key >= this._lt) || | ||
(this._lte && key > this._lte) || | ||
(this._gt && key <= this._gt) || | ||
(this._gte && key < this._gte)) { | ||
return nextTick(callback); | ||
} | ||
var value = this.db.container.getItem(key); | ||
this._pos += this._reverse ? -1 : 1; | ||
nextTick(callback.bind(null, undefined, key, value)); | ||
nextTick(function () { callback(null, key, value); }); | ||
}; | ||
@@ -132,3 +138,3 @@ | ||
if (options.asBuffer !== false && !Buffer.isBuffer(value)) { | ||
value = new Buffer(String(value)); | ||
value = new Buffer(value); | ||
} | ||
@@ -135,0 +141,0 @@ |
@@ -74,3 +74,3 @@ 'use strict'; | ||
value = retval.substring(uintPrefix.length); | ||
retval = new Uint8Array(atob(value).split('').map(function(c) { | ||
retval = new Uint8Array(atob(value).split('').map(function (c) { | ||
return c.charCodeAt(0); | ||
@@ -77,0 +77,0 @@ })); |
@@ -15,3 +15,3 @@ { | ||
], | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"main": "index.js", | ||
@@ -18,0 +18,0 @@ "dependencies": { |
# localstorage-down | ||
localstorage implementation of leveldown for mobile and desktop browsers. | ||
Localstorage implementation of leveldown for mobile and desktop browsers. | ||
@@ -33,2 +33,3 @@ The idea is to be able to use the level stack on phone and desktops. | ||
npm install browserify -g | ||
npm install beefy -g | ||
``` | ||
@@ -39,25 +40,26 @@ | ||
``` | ||
var localstorage = require('localstorage-down') | ||
, levelup = require('levelup') | ||
, db = levelup('/does/not/matter', { db: localstorage }) | ||
var localstorage = require('localstorage-down'); | ||
var levelup = require('levelup'); | ||
var db = levelup('/does/not/matter', { db: localstorage }); | ||
db.put('name', 'Yuri Irsenovich Kim') | ||
db.put('dob', '16 February 1941') | ||
db.put('spouse', 'Kim Young-sook') | ||
db.put('occupation', 'Clown') | ||
db.put('name', 'Yuri Irsenovich Kim'); | ||
db.put('dob', '16 February 1941'); | ||
db.put('spouse', 'Kim Young-sook'); | ||
db.put('occupation', 'Clown'); | ||
db.readStream() | ||
.on('data', function (data) { | ||
if(typeof data.value !== 'undefined') | ||
console.log(data.key, '=', data.value) | ||
if (typeof data.value !== 'undefined') { | ||
console.log(data.key, '=', data.value); | ||
} | ||
}) | ||
.on('error', function (err) { | ||
console.log('Oh my!', err) | ||
console.log('Oh my!', err); | ||
}) | ||
.on('close', function () { | ||
console.log('Stream closed') | ||
console.log('Stream closed'); | ||
}) | ||
.on('end', function () { | ||
console.log('Stream ended') | ||
}) | ||
console.log('Stream ended'); | ||
}); | ||
``` | ||
@@ -85,3 +87,3 @@ | ||
Browse to http://localhost:9966/ | ||
Browse to [http://localhost:9966](http://localhost:9966). | ||
View console logs in the browser to see test output. | ||
@@ -88,0 +90,0 @@ |
@@ -6,5 +6,5 @@ 'use strict'; | ||
var testCommon = require('./testCommon'); | ||
var testBuffer = new Uint8Array('hello'.split('').map(function (c) { | ||
var testBuffer = new Buffer(new Uint8Array('hello'.split('').map(function (c) { | ||
return c.charCodeAt(0); | ||
})); | ||
}))); | ||
@@ -25,7 +25,4 @@ require('abstract-leveldown/abstract/leveldown-test').args(localstorage, tape); | ||
// | ||
// TODO: uncomment these when they're passing | ||
// | ||
//require('abstract-leveldown/abstract/ranges-test').all(localstorage, tape, testCommon) | ||
//require('abstract-leveldown/abstract/batch-test').all(localstorage, tape, testCommon) | ||
require('abstract-leveldown/abstract/ranges-test').all(localstorage, tape, testCommon); | ||
require('abstract-leveldown/abstract/batch-test').all(localstorage, tape, testCommon); | ||
@@ -32,0 +29,0 @@ require('./custom-tests.js').all(localstorage, tape, testCommon); |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
473
95
1
19844
11