Comparing version 2.0.2 to 3.0.0
14
index.js
@@ -1,5 +0,3 @@ | ||
var bufferAlloc = require('buffer-alloc') | ||
const UINT_32_MAX = Math.pow(2, 32) | ||
var UINT_32_MAX = Math.pow(2, 32) | ||
exports.encodingLength = function () { | ||
@@ -10,7 +8,7 @@ return 8 | ||
exports.encode = function (num, buf, offset) { | ||
if (!buf) buf = bufferAlloc(8) | ||
if (!buf) buf = Buffer.allocUnsafe(8) | ||
if (!offset) offset = 0 | ||
var top = Math.floor(num / UINT_32_MAX) | ||
var rem = num - top * UINT_32_MAX | ||
const top = Math.floor(num / UINT_32_MAX) | ||
const rem = num - top * UINT_32_MAX | ||
@@ -25,4 +23,4 @@ buf.writeUInt32BE(top, offset) | ||
var top = buf.readUInt32BE(offset) | ||
var rem = buf.readUInt32BE(offset + 4) | ||
const top = buf.readUInt32BE(offset) | ||
const rem = buf.readUInt32BE(offset + 4) | ||
@@ -29,0 +27,0 @@ return top * UINT_32_MAX + rem |
{ | ||
"name": "uint64be", | ||
"version": "2.0.2", | ||
"version": "3.0.0", | ||
"description": "Encode / decode big endian unsigned 64 bit integers", | ||
"main": "index.js", | ||
"dependencies": { | ||
"buffer-alloc": "^1.1.0" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"standard": "^5.0.0", | ||
"tape": "^4.0.2", | ||
"buffer-from": "^1.0.0" | ||
"standard": "^14.3.3", | ||
"tape": "^5.0.0" | ||
}, | ||
@@ -14,0 +11,0 @@ "repository": { |
21
test.js
var uint64be = require('./') | ||
var tape = require('tape') | ||
var bufferFrom = require('buffer-from') | ||
@@ -9,7 +8,7 @@ var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1 | ||
t.same(uint64be.encodingLength(42), 8) | ||
t.same(uint64be.encode(Math.pow(2, 32)), bufferFrom([0, 0, 0, 1, 0, 0, 0, 0])) | ||
t.same(uint64be.encode(Math.pow(2, 32) + 1), bufferFrom([0, 0, 0, 1, 0, 0, 0, 1])) | ||
t.same(uint64be.encode(42), bufferFrom([0, 0, 0, 0, 0, 0, 0, 42])) | ||
t.same(uint64be.encode(42424242424242), bufferFrom([0x0, 0x0, 0x26, 0x95, 0xa9, 0xe6, 0x49, 0xb2])) | ||
t.same(uint64be.encode(MAX_SAFE_INTEGER), bufferFrom([0x0, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff])) | ||
t.same(uint64be.encode(Math.pow(2, 32)), Buffer.from([0, 0, 0, 1, 0, 0, 0, 0])) | ||
t.same(uint64be.encode(Math.pow(2, 32) + 1), Buffer.from([0, 0, 0, 1, 0, 0, 0, 1])) | ||
t.same(uint64be.encode(42), Buffer.from([0, 0, 0, 0, 0, 0, 0, 42])) | ||
t.same(uint64be.encode(42424242424242), Buffer.from([0x0, 0x0, 0x26, 0x95, 0xa9, 0xe6, 0x49, 0xb2])) | ||
t.same(uint64be.encode(MAX_SAFE_INTEGER), Buffer.from([0x0, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff])) | ||
t.same(uint64be.encode.bytes, 8) | ||
@@ -20,9 +19,9 @@ t.end() | ||
tape('decode', function (t) { | ||
t.same(uint64be.decode(bufferFrom([0, 0, 0, 1, 0, 0, 0, 0])), Math.pow(2, 32)) | ||
t.same(uint64be.decode(bufferFrom([0, 0, 0, 1, 0, 0, 0, 1])), Math.pow(2, 32) + 1) | ||
t.same(uint64be.decode(bufferFrom([0, 0, 0, 0, 0, 0, 0, 42])), 42) | ||
t.same(uint64be.decode(bufferFrom([0x0, 0x0, 0x26, 0x95, 0xa9, 0xe6, 0x49, 0xb2])), 42424242424242) | ||
t.same(uint64be.decode(bufferFrom([0x0, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff])), MAX_SAFE_INTEGER) | ||
t.same(uint64be.decode(Buffer.from([0, 0, 0, 1, 0, 0, 0, 0])), Math.pow(2, 32)) | ||
t.same(uint64be.decode(Buffer.from([0, 0, 0, 1, 0, 0, 0, 1])), Math.pow(2, 32) + 1) | ||
t.same(uint64be.decode(Buffer.from([0, 0, 0, 0, 0, 0, 0, 42])), 42) | ||
t.same(uint64be.decode(Buffer.from([0x0, 0x0, 0x26, 0x95, 0xa9, 0xe6, 0x49, 0xb2])), 42424242424242) | ||
t.same(uint64be.decode(Buffer.from([0x0, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff])), MAX_SAFE_INTEGER) | ||
t.same(uint64be.decode.bytes, 8) | ||
t.end() | ||
}) |
Sorry, the diff of this file is not supported yet
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
0
2
4669
43
- Removedbuffer-alloc@^1.1.0
- Removedbuffer-alloc@1.2.0(transitive)
- Removedbuffer-alloc-unsafe@1.1.0(transitive)
- Removedbuffer-fill@1.0.0(transitive)