level-codec
Advanced tools
Comparing version 2.0.1 to 3.0.0
@@ -5,5 +5,5 @@ var encodings = require('./encodings'); | ||
module.exports = function decodeKey(key, optionObjects){ | ||
var encoding = walk(optionObjects, ['keyEncoding']) || 'utf8'; | ||
var encoding = walk(optionObjects, 'keyEncoding') || 'utf8'; | ||
if (typeof encoding == 'string') encoding = encodings[encoding]; | ||
return encoding.decode(key); | ||
}; |
@@ -5,3 +5,3 @@ var encodings = require('./encodings'); | ||
module.exports = function decodeValue(value, optionObjects){ | ||
var encoding = walk(optionObjects, ['valueEncoding', 'encoding']) || 'utf8'; | ||
var encoding = walk(optionObjects, 'valueEncoding') || 'utf8'; | ||
if (typeof encoding == 'string') encoding = encodings[encoding]; | ||
@@ -8,0 +8,0 @@ return encoding.decode(value); |
@@ -5,5 +5,5 @@ var encodings = require('./encodings'); | ||
module.exports = function encodeKey(key, optionObjects){ | ||
var encoding = walk(optionObjects, ['keyEncoding']) || 'utf8'; | ||
var encoding = walk(optionObjects, 'keyEncoding') || 'utf8'; | ||
if (typeof encoding == 'string') encoding = encodings[encoding]; | ||
return encoding.encode(key); | ||
}; |
@@ -5,3 +5,3 @@ var encodings = require('./encodings'); | ||
module.exports = function encodeValue(value, optionObjects){ | ||
var encoding = walk(optionObjects, ['valueEncoding', 'encoding']) || 'utf8'; | ||
var encoding = walk(optionObjects, 'valueEncoding') || 'utf8'; | ||
if (typeof encoding == 'string') encoding = encodings[encoding]; | ||
@@ -8,0 +8,0 @@ return encoding.encode(value); |
@@ -5,5 +5,5 @@ var encodings = require('./encodings'); | ||
module.exports = function keyAsBuffer(optionObjects){ | ||
var encoding = walk(optionObjects, ['keyEncoding']) || 'utf8'; | ||
var encoding = walk(optionObjects, 'keyEncoding') || 'utf8'; | ||
if (typeof encoding == 'string') encoding = encodings[encoding]; | ||
return encoding.buffer; | ||
}; |
@@ -5,5 +5,5 @@ var encodings = require('./encodings'); | ||
module.exports = function valueAsBuffer(optionObjects){ | ||
var encoding = walk(optionObjects, ['valueEncoding', 'encoding']) || 'utf8'; | ||
var encoding = walk(optionObjects, 'valueEncoding') || 'utf8'; | ||
if (typeof encoding == 'string') encoding = encodings[encoding]; | ||
return encoding.buffer; | ||
}; |
module.exports = function walk(objects, keys){ | ||
module.exports = function walk(objects, key){ | ||
var value; | ||
var key; | ||
var object; | ||
for (var i = objects.length - 1; i >= 0; i--) { | ||
object = objects[i]; | ||
for (var j = keys.length - 1; j >= 0; j--) { | ||
key = keys[j]; | ||
if (object[key]) value = object[key]; | ||
} | ||
if (objects[i][key]) value = objects[i][key]; | ||
} | ||
return value; | ||
}; |
{ | ||
"name": "level-codec", | ||
"repository": "Level/codec", | ||
"version": "2.0.1", | ||
"version": "3.0.0", | ||
"description": "Levelup's encoding logic", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
@@ -7,3 +7,3 @@ var test = require('tape'); | ||
[{ keyEncoding: 'utf8' }], | ||
['keyEncoding', 'encoding'] | ||
'keyEncoding' | ||
), 'utf8'); | ||
@@ -13,17 +13,7 @@ | ||
[{ keyEncoding: 'binary' }, { keyEncoding: 'utf8' }], | ||
['keyEncoding', 'encoding'] | ||
'keyEncoding' | ||
), 'binary'); | ||
t.equal(walk( | ||
[{ keyEncoding: 'utf8', encoding: 'buffer' }], | ||
['keyEncoding', 'encoding'] | ||
), 'utf8'); | ||
t.equal(walk( | ||
[{ encoding: 'utf8' }, { keyEncoding: 'buffer', encoding: 'hex' }], | ||
['keyEncoding', 'encoding'] | ||
), 'utf8'); | ||
t.end(); | ||
}); | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5281
158