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

Commit 9fed84d

Browse files
committed
deprecate .encoding
1 parent dbe5700 commit 9fed84d

8 files changed

Lines changed: 10 additions & 26 deletions

File tree

lib/decode-key.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var encodings = require('./encodings');
22
var walk = require('./walk');
33

44
module.exports = function decodeKey(key, optionObjects){
5-
var encoding = walk(optionObjects, ['keyEncoding']) || 'utf8';
5+
var encoding = walk(optionObjects, 'keyEncoding') || 'utf8';
66
if (typeof encoding == 'string') encoding = encodings[encoding];
77
return encoding.decode(key);
88
};

lib/decode-value.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var encodings = require('./encodings');
22
var walk = require('./walk');
33

44
module.exports = function decodeValue(value, optionObjects){
5-
var encoding = walk(optionObjects, ['valueEncoding', 'encoding']) || 'utf8';
5+
var encoding = walk(optionObjects, 'valueEncoding') || 'utf8';
66
if (typeof encoding == 'string') encoding = encodings[encoding];
77
return encoding.decode(value);
88
};

lib/encode-key.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var encodings = require('./encodings');
22
var walk = require('./walk');
33

44
module.exports = function encodeKey(key, optionObjects){
5-
var encoding = walk(optionObjects, ['keyEncoding']) || 'utf8';
5+
var encoding = walk(optionObjects, 'keyEncoding') || 'utf8';
66
if (typeof encoding == 'string') encoding = encodings[encoding];
77
return encoding.encode(key);
88
};

lib/encode-value.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var encodings = require('./encodings');
22
var walk = require('./walk');
33

44
module.exports = function encodeValue(value, optionObjects){
5-
var encoding = walk(optionObjects, ['valueEncoding', 'encoding']) || 'utf8';
5+
var encoding = walk(optionObjects, 'valueEncoding') || 'utf8';
66
if (typeof encoding == 'string') encoding = encodings[encoding];
77
return encoding.encode(value);
88
};

lib/key-as-buffer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var encodings = require('./encodings');
22
var walk = require('./walk');
33

44
module.exports = function keyAsBuffer(optionObjects){
5-
var encoding = walk(optionObjects, ['keyEncoding']) || 'utf8';
5+
var encoding = walk(optionObjects, 'keyEncoding') || 'utf8';
66
if (typeof encoding == 'string') encoding = encodings[encoding];
77
return encoding.buffer;
88
};

lib/value-as-buffer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var encodings = require('./encodings');
22
var walk = require('./walk');
33

44
module.exports = function valueAsBuffer(optionObjects){
5-
var encoding = walk(optionObjects, ['valueEncoding', 'encoding']) || 'utf8';
5+
var encoding = walk(optionObjects, 'valueEncoding') || 'utf8';
66
if (typeof encoding == 'string') encoding = encodings[encoding];
77
return encoding.buffer;
88
};

lib/walk.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11

2-
module.exports = function walk(objects, keys){
2+
module.exports = function walk(objects, key){
33
var value;
4-
var key;
5-
var object;
64
for (var i = objects.length - 1; i >= 0; i--) {
7-
object = objects[i];
8-
for (var j = keys.length - 1; j >= 0; j--) {
9-
key = keys[j];
10-
if (object[key]) value = object[key];
11-
}
5+
if (objects[i][key]) value = objects[i][key];
126
}
137
return value;
148
};

test/walk.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,14 @@ var walk = require('../lib/walk');
44
test('walk', function(t){
55
t.equal(walk(
66
[{ keyEncoding: 'utf8' }],
7-
['keyEncoding', 'encoding']
7+
'keyEncoding'
88
), 'utf8');
99

1010
t.equal(walk(
1111
[{ keyEncoding: 'binary' }, { keyEncoding: 'utf8' }],
12-
['keyEncoding', 'encoding']
12+
'keyEncoding'
1313
), 'binary');
1414

15-
t.equal(walk(
16-
[{ keyEncoding: 'utf8', encoding: 'buffer' }],
17-
['keyEncoding', 'encoding']
18-
), 'utf8');
19-
20-
t.equal(walk(
21-
[{ encoding: 'utf8' }, { keyEncoding: 'buffer', encoding: 'hex' }],
22-
['keyEncoding', 'encoding']
23-
), 'utf8');
24-
2515
t.end();
2616
});
2717

0 commit comments

Comments
 (0)