Skip to content

Commit

Permalink
refactor(uint64.js): Move constants to constants.js
Browse files Browse the repository at this point in the history
  • Loading branch information
jwerle committed May 22, 2018
1 parent 3839b48 commit f89c51c
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions uint64.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ const isBuffer = require('is-buffer')
const uint64be = require('uint64be')
const alloc = require('buffer-alloc-unsafe')

const kMinUInt64Size = 8
const kDefaultUInt64Size = kMinUInt64Size
const {
kMinUInt64Size,
kDefaultUInt64Size,
} = require('./constants')

/**
* Encode an unsigned 64-bit big endian number into a buffer
Expand All @@ -19,11 +21,11 @@ const kDefaultUInt64Size = kMinUInt64Size
function encode(value, size) {
if (null == size) { size = kDefaultUInt64Size }
if ('number' != typeof size || size < kMinUInt64Size) {
throw new TypeError("uint64.encode: Expecting size to greater than 8.")
throw new TypeError("crypto.uint64.encode: Expecting size to greater than 8.")
} else if (value != value) {
throw new TypeError("uint64.encode: Cannot encode NaN.")
throw new TypeError("crypto.uint64.encode: Cannot encode NaN.")
} else if ('number' != typeof value) {
throw new TypeError("uint64.encode: Expecting number.")
throw new TypeError("crypto.uint64.encode: Expecting number.")
}
return uint64be.encode(value, alloc(size))
}
Expand All @@ -37,9 +39,9 @@ function encode(value, size) {
*/
function decode(buffer) {
if (false == isBuffer(buffer)) {
throw new TypeError("uint64.decode: Expecting buffer.")
throw new TypeError("crypto.uint64.decode: Expecting buffer.")
} else if (0 == buffer.length) {
throw new TypeError("uint64.decode: Cannot decode buffer of 0 length.")
throw new TypeError("crypto.uint64.decode: Cannot decode buffer of 0 length.")
}
return uint64be.decode(buffer)
}
Expand Down

0 comments on commit f89c51c

Please sign in to comment.