Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

abstract-leveldown

Package Overview
Dependencies
Maintainers
1
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

abstract-leveldown - npm Package Compare versions

Comparing version 0.2.3 to 0.3.0

51

abstract-leveldown.js
/* Copyright (c) 2013 Rod Vagg, MIT License */
function checkKeyValue (obj, type) {
if (obj === null || obj === undefined)
return new Error(type + ' cannot be `null` or `undefined`')
if (obj === null || obj === undefined)
return new Error(type + ' cannot be `null` or `undefined`')
if (Buffer.isBuffer(obj)) {
if (obj.length === 0)
return new Error(type + ' cannot be an empty Buffer')
} else if (String(obj) === '')
return new Error(type + ' cannot be an empty String')
}
function AbstractIterator (db) {

@@ -98,5 +86,5 @@ this.db = db

throw new Error('get() requires a callback argument')
var err = checkKeyValue(key, 'key')
var err = this._checkKeyValue(key, 'key', this._isBuffer)
if (err) return callback(err)
if (!Buffer.isBuffer(key)) key = String(key)
if (!this._isBuffer(key)) key = String(key)
if (typeof options != 'object')

@@ -116,8 +104,8 @@ options = {}

throw new Error('put() requires a callback argument')
var err = checkKeyValue(value, 'value')
var err = this._checkKeyValue(value, 'value', this._isBuffer)
if (err) return callback(err)
err = checkKeyValue(key, 'key')
err = this._checkKeyValue(key, 'key', this._isBuffer)
if (err) return callback(err)
if (!Buffer.isBuffer(key)) key = String(key)
if (!Buffer.isBuffer(value)) value = String(value)
if (!this._isBuffer(key)) key = String(key)
if (!this._isBuffer(value)) value = String(value)
if (typeof options != 'object')

@@ -137,5 +125,5 @@ options = {}

throw new Error('del() requires a callback argument')
var err = checkKeyValue(key, 'key')
var err = this._checkKeyValue(key, 'key', this._isBuffer)
if (err) return callback(err)
if (!Buffer.isBuffer(key)) key = String(key)
if (!this._isBuffer(key)) key = String(key)
if (typeof options != 'object')

@@ -175,4 +163,4 @@ options = {}

if (!Buffer.isBuffer(start)) start = String(start)
if (!Buffer.isBuffer(end)) end = String(end)
if (!this._isBuffer(start)) start = String(start)
if (!this._isBuffer(end)) end = String(end)
if (typeof this._approximateSize == 'function')

@@ -194,4 +182,19 @@ return this._approximateSize(start, end, callback)

AbstractLevelDOWN.prototype._isBuffer = function (obj) {
return Buffer.isBuffer(obj)
}
AbstractLevelDOWN.prototype._checkKeyValue = function (obj, type) {
if (obj === null || obj === undefined)
return new Error(type + ' cannot be `null` or `undefined`')
if (obj === null || obj === undefined)
return new Error(type + ' cannot be `null` or `undefined`')
if (this._isBuffer(obj)) {
if (obj.length === 0)
return new Error(type + ' cannot be an empty Buffer')
} else if (String(obj) === '')
return new Error(type + ' cannot be an empty String')
}
module.exports.AbstractLevelDOWN = AbstractLevelDOWN
module.exports.AbstractIterator = AbstractIterator
module.exports.checkKeyValue = checkKeyValue
module.exports.AbstractIterator = AbstractIterator

@@ -28,2 +28,14 @@ module.exports.setUp = function (test, testCommon) {

module.exports.open = function (leveldown, test, testCommon) {
test('test database open, no options', function (t) {
var db = leveldown(testCommon.location())
// default createIfMissing=true, errorIfExists=false
db.open(function (err) {
t.notOk(err, 'no error')
db.close(function () {
t.end()
})
})
})
test('test database open, options and callback', function (t) {

@@ -30,0 +42,0 @@ var db = leveldown(testCommon.location())

{
"name" : "abstract-leveldown"
, "description" : "An abstract prototype matching the LevelDOWN API"
, "version" : "0.2.3"
, "version" : "0.3.0"
, "homepage" : "https://github.com/rvagg/node-abstract-leveldown"

@@ -6,0 +6,0 @@ , "contributors" : [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc