Skip to content

Commit

Permalink
Add makeNonce method
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonTian committed Sep 21, 2016
1 parent 506e0ea commit e0bf18f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/index.js
Expand Up @@ -79,6 +79,14 @@ exports.random = function (min, max) {
return Math.floor(min + Math.random() * (max - min));
};

/**
* Generate a nonce string
* @return {String} a nonce string.
*/
exports.makeNonce = function () {
return '' + Math.floor(Math.random() * 1000000000000);
};

/**
* Pad a number as \d\d format
* @param {Number} num a number that less than 100.
Expand Down
6 changes: 6 additions & 0 deletions test/index.test.js
Expand Up @@ -58,6 +58,12 @@ describe('kitx', function () {
expect(value).be.below(10);
});

it('makeNonce', function () {
var nonce = kit.makeNonce();
expect(nonce.length).to.be.above(10);
expect(nonce).not.to.be(kit.makeNonce());
});

it('pad2', function () {
expect(kit.pad2(0)).to.be('00');
expect(kit.pad2(99)).to.be('99');
Expand Down

0 comments on commit e0bf18f

Please sign in to comment.