{"_id":"level-option-wrap","_rev":"239247","name":"level-option-wrap","description":"wrap `opts.{{g,l}{t,e,te},start,end}` arguments with functions","dist-tags":{"latest":"1.1.0"},"maintainers":[{"name":"nopersonsmodules","email":"nopersonsmodules@gmail.com"}],"time":{"modified":"2023-03-24T16:53:12.000Z","created":"2014-10-16T09:10:33.323Z","1.1.0":"2014-10-16T10:12:54.055Z","1.0.0":"2014-10-16T09:10:33.323Z"},"users":{},"author":{"name":"James Halliday","email":"mail@substack.net","url":"http://substack.net"},"repository":{"type":"git","url":"git://github.com/substack/level-option-wrap.git"},"versions":{"1.1.0":{"name":"level-option-wrap","version":"1.1.0","description":"wrap `opts.{{g,l}{t,e,te},start,end}` arguments with functions","main":"index.js","dependencies":{"defined":"~0.0.0"},"devDependencies":{"covert":"^1.0.1","tape":"^3.0.0"},"scripts":{"test":"tape test/*.js","coverage":"covert test/*.js"},"repository":{"type":"git","url":"git://github.com/substack/level-option-wrap.git"},"homepage":"https://github.com/substack/level-option-wrap","keywords":["level","database","options","createReadStream","opts","prefix","wrapper"],"author":{"name":"James Halliday","email":"mail@substack.net","url":"http://substack.net"},"license":"MIT","gitHead":"5be2c556b7ccf1f1dd5341076d29a4616a1eb371","bugs":{"url":"https://github.com/substack/level-option-wrap/issues"},"_id":"level-option-wrap@1.1.0","_shasum":"ad20e68d9f3c22c8897531cc6aa7af596b1ed129","_from":".","_npmVersion":"2.1.3","_nodeVersion":"0.10.31","_npmUser":{"name":"substack","email":"mail@substack.net"},"maintainers":[{"name":"nopersonsmodules","email":"nopersonsmodules@gmail.com"}],"dist":{"shasum":"ad20e68d9f3c22c8897531cc6aa7af596b1ed129","size":3159,"noattachment":false,"key":"/level-option-wrap/-/level-option-wrap-1.1.0.tgz","tarball":"http://name.csiicloud.com:7001/level-option-wrap/download/level-option-wrap-1.1.0.tgz"},"directories":{},"publish_time":1413454374055,"_hasShrinkwrap":false,"_cnpm_publish_time":1413454374055,"_cnpmcore_publish_time":"2021-12-18T20:42:10.676Z"},"1.0.0":{"name":"level-option-wrap","version":"1.0.0","description":"wrap `opts.{{g,l}{t,e,te},start,end}` arguments with functions","main":"index.js","dependencies":{"defined":"~0.0.0"},"devDependencies":{"covert":"^1.0.1","tape":"^3.0.0"},"scripts":{"test":"tape test/*.js","coverage":"covert test/*.js"},"repository":{"type":"git","url":"git://github.com/substack/level-option-wrap.git"},"homepage":"https://github.com/substack/level-option-wrap","keywords":["level","database","options","createReadStream","opts","prefix","wrapper"],"author":{"name":"James Halliday","email":"mail@substack.net","url":"http://substack.net"},"license":"MIT","gitHead":"9cba4c6ca4b2c941b034e488f8ab1ee826d4b891","bugs":{"url":"https://github.com/substack/level-option-wrap/issues"},"_id":"level-option-wrap@1.0.0","_shasum":"f1493ba373e4798012693045463584b45c10f3d7","_from":".","_npmVersion":"2.1.3","_nodeVersion":"0.10.31","_npmUser":{"name":"substack","email":"mail@substack.net"},"maintainers":[{"name":"nopersonsmodules","email":"nopersonsmodules@gmail.com"}],"dist":{"shasum":"f1493ba373e4798012693045463584b45c10f3d7","size":2978,"noattachment":false,"key":"/level-option-wrap/-/level-option-wrap-1.0.0.tgz","tarball":"http://name.csiicloud.com:7001/level-option-wrap/download/level-option-wrap-1.0.0.tgz"},"directories":{},"publish_time":1413450633323,"_hasShrinkwrap":false,"_cnpm_publish_time":1413450633323,"_cnpmcore_publish_time":"2021-12-18T20:42:10.902Z"}},"readme":"# level-option-wrap\n\nwrap `opts.{{g,l}{t,e,te},start,end}` arguments with functions\n\nWith this package you can expose familiar `db.createReadStream()` options like\nfrom leveldb but without leaking information about your internal key\nrepresentations.\n\n[![build status](https://secure.travis-ci.org/substack/level-option-wrap.png)](http://travis-ci.org/substack/level-option-wrap)\n\n# example\n\nFor example, suppose you have a list of users using a bytewise keyEncoding and\nyou want to let api consumers constrain the output. If you pass through\n`opts.gt`/`opts.lt` arguments directly, you must communicate to api consumers\nthe internal structure of your keys, which breaks encapsulation.\n\nHowever, implementing `opts.{{g,l}{t,e,te},start,end}` yourself inside your library\nor application code is madness! This library lets you do that: \n\n``` js\nvar wrap = require('level-option-wrap');\nvar minimist = require('minimist');\nvar defined = require('defined');\n\nvar argv = minimist(process.argv.slice(2));\nvar opts = wrap(argv, {\n    gt: function (x) { return [ 'user', defined(x, null) ] },\n    lt: function (x) { return [ 'user', defined(x, undefined) ] }\n});\nconsole.log(opts);\n```\n\nNow to get all users `>= 'mafintosh'` and `< 'maxogden'` we can just do:\n\n```\n$ node example/prefix.js --gte mafintosh --lt maxogden\n{ gte: [ 'user', 'mafintosh' ], lt: [ 'user', 'maxogden' ] }\n```\n\nThis works even though we only specified `gt` and `lt` as our prefix functions,\nbecause narrower ranges take precedence.\n\n# methods\n\n``` js\nvar wrap = require('level-option-wrap')\n```\n\n## var newOpts = wrap(opts, fns)\n\nGenerate `newOpts` given some leveldb createReadStream-style options `opts` and\nan object `fns` mapping key contraints `{g,l}{t,e,te}` to functions. Each\nfunction gets the relevant constraint (whether exclusive or not) and should\nreturn the new key bound. Exclusivity for each key is determined by the\ncorresponding `opts` key.\n\n`opts.limit` values will be passed through and can be modified by defining an\n`fns.limit(n)` function.\n\n# install\n\nWith [npm](https://npmjs.org) do:\n\n```\nnpm install level-option-wrap\n```\n\n# license\n\nMIT\n","_attachments":{},"homepage":"https://github.com/substack/level-option-wrap","bugs":{"url":"https://github.com/substack/level-option-wrap/issues"},"license":"MIT"}