Skip to content

Commit

Permalink
Migrate to BigInteger library
Browse files Browse the repository at this point in the history
  • Loading branch information
dlackty committed Dec 17, 2018
1 parent 0c2b64f commit 20b3683
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Module dependencies.
*/

var bignum = require('bignum');
var bigInteger = require('big-integer');

/**
* The offset from which druuid UUIDs are generated (in milliseconds).
Expand All @@ -28,7 +28,7 @@ exports.epoch = 0;
exports.gen = function gen(date, epoch){
if (!date) date = new Date();
if (!epoch) epoch = exports.epoch;
var id = bignum(date - epoch).shiftLeft(64 - 41);
var id = bigInteger(date - epoch).shiftLeft(64 - 41);
return id.or(Math.round(Math.random() * 1e16) % Math.pow(2, 64 - 41));
};

Expand All @@ -48,6 +48,6 @@ exports.gen = function gen(date, epoch){

exports.time = function(uuid, epoch){
if (!epoch) epoch = exports.epoch;
var ms = bignum(uuid).shiftRight(64 - 41).toNumber();
var ms = bigInteger(uuid).shiftRight(64 - 41).toJSNumber();
return new Date(ms + epoch);
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"test": "make test"
},
"dependencies": {
"bignum": "^0.12.5"
"big-integer": "^1.6.40"
},
"devDependencies": {
"mocha": "1.16.0",
Expand Down
4 changes: 2 additions & 2 deletions test/druuid.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

var druuid = require('..')
, bignum = require('bignum');
, bigInteger = require('big-integer');

describe('druuid', function(){
describe('.gen', function(){
it('generates a UUID', function(){
var uuid = druuid.gen();
uuid.should.be.instanceOf(bignum);
uuid.should.be.instanceOf(bigInteger);
uuid.should.not.equal(druuid.gen());
});

Expand Down

0 comments on commit 20b3683

Please sign in to comment.