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

Commit 0c98ccb

Browse files
committed
make member options optional
1 parent e5e0742 commit 0c98ccb

File tree

5 files changed

+29
-9
lines changed

5 files changed

+29
-9
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,31 @@
1919
var codec = new Codec(db.options);
2020
```
2121

22-
### #encodeKey(key, opts)
22+
### #encodeKey(key[, opts])
2323

2424
Encode `key` with given `opts`.
2525

26-
### #encodeValue(value, opts)
26+
### #encodeValue(value[, opts])
2727

2828
Encode `value` with given `opts`.
2929

30-
### #encodeBatch(batch, opts)
30+
### #encodeBatch(batch[, opts])
3131

3232
Encode `batch` ops with given `opts`.
3333

34-
### #decodeKey(key, opts)
34+
### #decodeKey(key[, opts])
3535

3636
Decode `key` with given `opts`.
3737

38-
### #decodeValue(value, opts)
38+
### #decodeValue(value[, opts])
3939

4040
Decode `value` with given `opts`.
4141

42-
### #keyAsBuffer(opts)
42+
### #keyAsBuffer([opts])
4343

4444
Check whether `opts` and the global `opts` call for a binary key encoding.
4545

46-
### #valueAsBuffer(opts)
46+
### #valueAsBuffer([opts])
4747

4848
Check whether `opts` and the global `opts` call for a binary value encoding.
4949

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ Codec.prototype._encoding = function(encoding){
1515

1616
Codec.prototype._keyEncoding = function(opts, batchOpts){
1717
return this._encoding(batchOpts && batchOpts.keyEncoding
18-
|| opts.keyEncoding
18+
|| opts && opts.keyEncoding
1919
|| this.opts.keyEncoding);
2020
};
2121

2222
Codec.prototype._valueEncoding = function(opts, batchOpts){
2323
return this._encoding(batchOpts && batchOpts.valueEncoding
24-
|| opts.valueEncoding
24+
|| opts && opts.valueEncoding
2525
|| this.opts.valueEncoding);
2626
};
2727

test/as-buffer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ var Codec = require('..');
44
test('key as buffer', function(t){
55
var codec = new Codec({ keyEncoding: 'hex' });
66
t.ok(codec.keyAsBuffer({}));
7+
t.ok(codec.keyAsBuffer());
78
t.notOk(codec.keyAsBuffer({ keyEncoding: 'utf8' }));
89
t.end();
910
});
1011

1112
test('value as buffer', function(t){
1213
var codec = new Codec({ valueEncoding: 'hex' });
1314
t.ok(codec.valueAsBuffer({}));
15+
t.ok(codec.valueAsBuffer());
1416
t.notOk(codec.valueAsBuffer({ valueEncoding: 'utf8' }));
1517
t.end();
1618
});

test/batch.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ test('batch', function(t){
1818
{ type: 'put', key: 'json', value: '{}' }
1919
]);
2020

21+
encoded = codec.encodeBatch(ops);
22+
t.deepEqual(encoded, [
23+
{ type: 'put', key: 'string', value: 'string' },
24+
{ type: 'put', key: 'json', value: {} }
25+
]);
26+
2127
t.end();
2228
});
2329

test/kv.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ test('encode key', function(t){
77
var buf = codec.encodeKey('686579', {});
88
t.equal(buf.toString(), 'hey');
99

10+
buf = codec.encodeKey('686579');
11+
t.equal(buf.toString(), 'hey');
12+
1013
buf = codec.encodeKey('686579', {
1114
keyEncoding: 'binary'
1215
});
@@ -21,6 +24,9 @@ test('encode value', function(t){
2124
var buf = codec.encodeValue('686579', {});
2225
t.equal(buf.toString(), 'hey');
2326

27+
buf = codec.encodeValue('686579');
28+
t.equal(buf.toString(), 'hey');
29+
2430
buf = codec.encodeValue('686579', {
2531
valueEncoding: 'binary'
2632
});
@@ -35,6 +41,9 @@ test('decode key', function(t){
3541
var buf = codec.decodeKey(new Buffer('hey'), {});
3642
t.equal(buf, '686579');
3743

44+
buf = codec.decodeKey(new Buffer('hey'));
45+
t.equal(buf, '686579');
46+
3847
buf = codec.decodeKey(new Buffer('hey'), {
3948
keyEncoding: 'binary'
4049
});
@@ -49,6 +58,9 @@ test('decode value', function(t){
4958
var buf = codec.decodeValue(new Buffer('hey'), {});
5059
t.equal(buf, '686579');
5160

61+
buf = codec.decodeValue(new Buffer('hey'));
62+
t.equal(buf, '686579');
63+
5264
buf = codec.decodeValue(new Buffer('hey'), {
5365
valueEncoding: 'binary'
5466
});

0 commit comments

Comments
 (0)