level-path
sensible key / range generator for levelup
Installing
npm install level-path
Example
var path = ; var users = ;var index = ; var user = id: 1 username: 'john' ; console; // => users/\xff1console; // => users/\xfffoo console; // => index/users/\xff/username/john/\xff1 console;// => index/users/\xff/username/john/\xff1 console;// => { start: 'users/\xff5', end: 'users/\xff\xff' } var last = id: 15 username: 'mary' ; console; // => { start: 'users/\xff1', end: 'users/\xff15' } console;// =>// { start: 'index/users/\xff/username/john/\xff',// end: 'index/users/\xff/username/john/\xff\xff' }
API
key = path(str[, defaults])
Creates a key / range generator function for str
.
Keys are defined using sinatra style some/:random/:key
paths.
The last key is considered the range key and will be prefixed
accordingly so ranges can be generated for it later with .range()
.
Optionally pass defaults
to bind an object
to always be evaluated first.
key([any[, ...]])
Generates a key using attributes found in passed values.
key.range([{ start: [any], end: [any] }])
Generates a key range using optional start
/ end
attributes.
They can be ommitted for the full key range.
License
MIT