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

Commit

Permalink
Use module.exports syntax in util files (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
s1na committed Jun 24, 2019
1 parent cf40000 commit 3f795c7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
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
}

0 comments on commit 3f795c7

Please sign in to comment.