Files: 3a87ab0f145263cab848f87d3125febdc5561b9a / util.js
776 bytesRaw
1 | var Map = require('pull-stream/throughs/map') |
2 | |
3 | // opts standardized to work like levelup api |
4 | function stdopts (opts) { |
5 | opts = opts || {} |
6 | opts.keys = opts.keys !== false //default keys to true |
7 | opts.values = opts.values !== false //default values to true |
8 | return opts |
9 | } |
10 | |
11 | function msgFmt (keys, values, obj) { |
12 | if (keys && values) |
13 | return obj |
14 | if (keys) |
15 | return obj.key |
16 | if (values) |
17 | return obj.value |
18 | return null // i guess? |
19 | } |
20 | |
21 | exports.options = stdopts |
22 | exports.format = msgFmt |
23 | |
24 | exports.lo = null |
25 | exports.hi = undefined |
26 | |
27 | exports.formatStream = function (keys, values) { |
28 | return Map(function (data) { |
29 | if(data.sync) return data |
30 | return keys && values ? data.value : keys ? data.value.key : data.value.value |
31 | }) |
32 | } |
33 | |
34 | |
35 |
Built with git-ssb-web