PathKey
Generate keys from objects and parse keys back into objects. Useful for working with kv stores like leveldb and redis.
Example
var PathKey = var pk = var obj = _path: 'companyId/email/name' companyId: 'stock-market' email: 'vincent@adultman.com' name: 'Vincent Adultman' var key = pkconsole// 'companyId/email/nameÿstock-marketÿvincent@adultman.comÿVincent Adultman' var parsed = pkconsole // { _path: 'companyId/email/name',// companyId: 'stock-market',// email: 'vincent@adultman.com',// name: 'Vincent Adultman' }
API
Pathkey(options)
// defaultsvar pk =
Options
pathKey
: the attribute of the object (when used withpathSep
) determines the format of the created key.pathSep
: this is used to split the value ofpathKey
.keySep
: this is used to join/split the created/parsed key.
pk.create(obj)
var key = pk// 'companyId/email/nameÿstock-marketÿvincent@adultman.comÿVincent Adultman'// ^ keySep: 'ÿ'
pk.parse(key)
var key = 'companyId/email/nameÿstock-marketÿvincent@adultman.comÿVincent Adultman'var parsed = pk // { _path: 'companyId/email/name',// companyId: 'stock-market',// email: 'vincent@adultman.com',// name: 'Vincent Adultman' }
pk.range(obj)
var range = pkconsole// {// gte: 'companyId/email/nameÿstock-marketÿ',// lte: 'companyId/email/nameÿstock-marketÿÿÿ',// }
License
MIT