Socket
Socket
Sign inDemoInstall

level-option-wrap

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

level-option-wrap

wrap `opts.{{g,l}{t,e,te},start,end}` arguments with functions


Version published
Weekly downloads
74K
increased by7.48%
Maintainers
1
Weekly downloads
 
Created
Source

level-option-wrap

wrap opts.{{g,l}{t,e,te},start,end} arguments with functions

With this package you can expose familiar db.createReadStream() options like from leveldb but without leaking information about your internal key representations.

build status

example

For example, suppose you have a list of users using a bytewise keyEncoding and you want to let api consumers constrain the output. If you pass through opts.gt/opts.lt arguments directly, you must communicate to api consumers the internal structure of your keys, which breaks encapsulation.

However, implementing opts.{{g,l}{t,e,te},start,end} yourself inside your library or application code is madness! This library lets you do that:

var wrap = require('level-option-wrap');
var minimist = require('minimist');
var defined = require('defined');

var argv = minimist(process.argv.slice(2));
var opts = wrap(argv, {
    gt: function (x) { return [ 'user', defined(x, null) ] },
    lt: function (x) { return [ 'user', defined(x, undefined) ] }
});
console.log(opts);

Now to get all users >= 'mafintosh' and < 'maxogden' we can just do:

$ node example/prefix.js --gte mafintosh --lt maxogden
{ gte: [ 'user', 'mafintosh' ], lt: [ 'user', 'maxogden' ] }

This works even though we only specified gt and lt as our prefix functions, because narrower ranges take precedence.

methods

var wrap = require('level-option-wrap')

var newOpts = wrap(opts, fns)

Generate newOpts given some leveldb createReadStream-style options opts and an object fns mapping key contraints {g,l}{t,e,te} to functions. Each function gets the relevant constraint (whether exclusive or not) and should return the new key bound. Exclusivity for each key is determined by the corresponding opts key.

opts.limit values will be passed through and can be modified by defining an fns.limit(n) function.

install

With npm do:

npm install level-option-wrap

license

MIT

Keywords

FAQs

Package last updated on 16 Oct 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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