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

level-post

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

level-post - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

test/encoding_cmp.js

34

index.js
var sr = require('string-range')
var defined = require('defined')
var beq = require('buffer-equal')
function eq (a, b) {
if (Buffer.isBuffer(a) && Buffer.isBuffer(b)) {
return beq(a, b)
}
else return a === b
}
module.exports = function post (db, opts, each) {

@@ -11,6 +20,23 @@ if(!each)

var checker = sr.checker(opts)
var encode = (opts && opts.keyEncoding && opts.keyEncoding.encode)
|| (db.options && db.options.keyEncoding && db.options.keyEncoding.encode)
|| function (x) { return x }
var min = defined(opts.min, opts.gt, opts.gte, opts.start)
var max = defined(opts.max, opts.lt, opts.lte, opts.end)
var copts = {}
if (min !== undefined) copts.min = encode(min)
if (max !== undefined) copts.max = encode(max)
var checker = sr.checker(copts)
function cmp (key) {
var ek = encode(key)
if (opts.gt && eq(ek, copts.min)) return false
if (opts.lt && eq(ek, copts.max)) return false
return checker(ek)
}
function onPut (key, val) {
if(checker(key))
if(cmp(key))
each({type: 'put', key: key, value: val})

@@ -20,3 +46,3 @@ }

function onDel (key, val) {
if(checker(key))
if(cmp(key))
each({type: 'del', key: key, value: val})

@@ -27,3 +53,3 @@ }

ary.forEach(function (op) {
if(checker(op.key))
if(cmp(op.key))
each(op)

@@ -30,0 +56,0 @@ })

9

package.json
{
"name": "level-post",
"description": "",
"version": "1.0.3",
"version": "1.0.4",
"homepage": "https://github.com/dominictarr/level-post",

@@ -11,7 +11,10 @@ "repository": {

"dependencies": {
"buffer-equal": "~0.0.1",
"defined": "~0.0.0",
"string-range": "~1.2.1"
},
"devDependencies": {
"tape": "~1.0.4",
"level-test": "~1.3.0"
"bytewise": "~0.7.1",
"level-test": "^1.6.3",
"tape": "^2.13.3"
},

@@ -18,0 +21,0 @@ "scripts": {

@@ -26,4 +26,23 @@ # level-post

# methods
## post(db, opts={}, cb)
Create a hook to listen for database events matching the constraints in `opts`.
`cb(op)` fires for each matching operation for `op`, an object with `type`,
`key`, and `value` properties.
You can use these keys as constraints, just like level core:
* `opts.gte`, `opts.start`, `opts.min` - greater than or equal to
* `opts.gt` - greater than
* `opts.lte`, `opts.end`, `opts.max` - less than or equal to
* `opts.lt` - less than
You can also specify a keyEncoding with `opts.keyEncoding`. If there was a
keyEncoding set up by leveldb in the constructor (at `db.options.keyEncoding`),
that one will be used.
## License
MIT
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