Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Use module.exports syntax in util files #90

Merged
merged 1 commit into from
Jun 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/util/hex.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @param {Array} Array of nibbles
* @returns {Array} - returns buffer of encoded data
**/
export function addHexPrefix (key, terminator) {
function addHexPrefix (key, terminator) {
// odd
if (key.length % 2) {
key.unshift(1)
Expand All @@ -27,7 +27,7 @@ export function addHexPrefix (key, terminator) {
* @param {Array} Array of nibbles
* @private
*/
export function removeHexPrefix (val) {
function removeHexPrefix (val) {
if (val[0] % 2) {
val = val.slice(1)
} else {
Expand All @@ -43,6 +43,12 @@ export function removeHexPrefix (val) {
* @param {Array} key - an hexprefixed array of nibbles
* @private
*/
export function isTerminator (key) {
function isTerminator (key) {
return key[0] > 1
}

module.exports = {
addHexPrefix,
removeHexPrefix,
isTerminator
}
15 changes: 11 additions & 4 deletions src/util/nibbles.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @param {Buffer| String} key
* @private
*/
export function stringToNibbles (key) {
function stringToNibbles (key) {
const bkey = new Buffer(key)
let nibbles = []

Expand All @@ -24,7 +24,7 @@ export function stringToNibbles (key) {
* @param {Array} Nibble array
* @private
*/
export function nibblesToBuffer (arr) {
function nibblesToBuffer (arr) {
let buf = new Buffer(arr.length / 2)
for (let i = 0; i < buf.length; i++) {
let q = i * 2
Expand All @@ -40,7 +40,7 @@ export function nibblesToBuffer (arr) {
* @param {Array} nib2
* @private
*/
export function matchingNibbleLength (nib1, nib2) {
function matchingNibbleLength (nib1, nib2) {
let i = 0
while (nib1[i] === nib2[i] && nib1.length > i) {
i++
Expand All @@ -53,7 +53,14 @@ export function matchingNibbleLength (nib1, nib2) {
* @param {Array} keyA
* @param {Array} keyB
*/
export function doKeysMatch (keyA, keyB) {
function doKeysMatch (keyA, keyB) {
const length = matchingNibbleLength(keyA, keyB)
return length === keyA.length && length === keyB.length
}

module.exports = {
stringToNibbles,
nibblesToBuffer,
matchingNibbleLength,
doKeysMatch
}