Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
simplify encodeLtgt api
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangruber committed Apr 17, 2015
1 parent e4080a4 commit 24f3817
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ var codec = new Codec(db.options);

Encode `batch` ops with given `opts`.

### #encodeLtgt(ltgt[, opts])
### #encodeLtgt(ltgt)

Encode the ltgt values of option object `ltgt` with given `opts`.
Encode the ltgt values of option object `ltgt`.

### #decodeKey(key[, opts])

Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ Codec.prototype.encodeBatch = function(ops, opts){

var ltgtKeys = ['lt', 'gt', 'lte', 'gte', 'start', 'end'];

Codec.prototype.encodeLtgt = function(ltgt, opts){
Codec.prototype.encodeLtgt = function(ltgt){
var self = this;
var ret = {};
Object.keys(ltgt).forEach(function(key){
ret[key] = ltgtKeys.indexOf(key) > -1
? self.encodeKey(ltgt[key], opts)
? self.encodeKey(ltgt[key], ltgt)
: ltgt[key]
});
return ret;
Expand Down
11 changes: 8 additions & 3 deletions test/ltgt.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@ var test = require('tape');
var Codec = require('..');

test('encode ltgt', function(t){
var codec = new Codec({ keyEncoding: 'hex' });

var ltgt = {
start: '686579',
lte: '686579'
};
var codec = new Codec({ keyEncoding: 'hex' });

var encoded = codec.encodeLtgt(ltgt);
t.equal(encoded.start.toString(), 'hey');
t.equal(encoded.lte.toString(), 'hey');

var encoded = codec.encodeLtgt(ltgt, { keyEncoding: 'json' });
ltgt = {
start: '686579',
lte: '686579',
keyEncoding: 'json'
};
encoded = codec.encodeLtgt(ltgt);
t.equal(encoded.start, '"686579"');
t.equal(encoded.lte, '"686579"');

Expand Down

0 comments on commit 24f3817

Please sign in to comment.