Skip to content

Commit

Permalink
Merge branch 'deprecate-old' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
karnthis committed May 30, 2019
2 parents 9b163af + beb97cf commit fa9ad38
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
language: node_js
node_js:
- "6"
- "stable"
6 changes: 6 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ExpandedNodes": [
""
],
"PreviewInSolutionExplorer": false
}
Binary file added .vs/make-random/v15/.suo
Binary file not shown.
Binary file added .vs/slnx.sqlite
Binary file not shown.
21 changes: 21 additions & 0 deletions deprecated/v1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict'
// Through v0.1.6

const Purify = require('purify-int')
const { deprecate } = require('../util')

function ceil(max) {
const safeMax = Purify.asInt(max);
deprecate("make-random.ceil()", "0.1.6");
return Math.ceil(Math.random() * safeMax);
}
function floor(max) {
const safeMax = Purify.asInt(max);
deprecate("make-random.floor()", "0.1.6");
return Math.floor(Math.random() * safeMax);
}

module.exports = {
floor,
ceil
}
21 changes: 4 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,9 @@
const Purify = require('purify-int')
const Crypto = require('crypto')

const makeRandom = {
ceil(max) {
const safeMax = Purify.asInt(max);
deprecate("make-random.ceil()", "0.1.6");
return Math.ceil(Math.random() * safeMax);
},
floor(max) {
const safeMax = Purify.asInt(max);
deprecate("make-random.floor()", "0.1.6");
return Math.floor(Math.random() * safeMax);
}
};
const { floor, ceil } = require('./deprecated/v1')

function deprecate(func, version) {
console.log(`${func} is deprecated as of ${version} and may be removed at any time.
Please convert to make-random-legacy if this function is still needed.`)
module.exports = {
floor,
ceil
}

module.exports = makeRandom;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "💯 Make a random number",
"main": "index.js",
"scripts": {
"test": "mocha"
"test": "mocha --recursive"
},
"repository": {
"type": "git",
Expand Down
34 changes: 0 additions & 34 deletions test.js

This file was deleted.

46 changes: 46 additions & 0 deletions test/main/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use strict';

const chai = require('chai');
const expect = chai.expect;
const { ceil, floor } = require('../../index');

describe('makeRandom ceil()', () => {
it(`should have the method 'ceil'`, ()=> {
expect(ceil).to.be.a('function');
});
it(`should return a number`, () => {
expect(ceil(10)).to.be.a('number');
expect(ceil('10')).to.be.an('number');
});
it(`should not return a negative zero`, () => {
expect(ceil(-0)).to.equal(0);
});

it(`should return 0 if a number or number string is not passed to ceil()`, () => {
expect(ceil('test')).to.equal(0);
expect(ceil(true)).to.equal(0);
expect(ceil({})).to.equal(0);
expect(ceil([])).to.equal(0);
expect(ceil(() => {})).to.equal(0);
});
});

describe('makeRandom floor()', () => {
it(`should have the method 'floor'`, ()=> {
expect(floor).to.be.a('function');
});
it(`should return a number`, () => {
expect(floor(10)).to.be.a('number');
expect(floor('10')).to.be.an('number');
});
it(`should not return a negative zero`, () => {
expect(floor(-0)).to.equal(0);
});
it(`should return 0 if a number or number string is not passed to ceil()`, () => {
expect(floor('test')).to.equal(0);
expect(floor(true)).to.equal(0);
expect(floor({})).to.equal(0);
expect(floor([])).to.equal(0);
expect(floor(() => {})).to.equal(0);
});
});
8 changes: 8 additions & 0 deletions util/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function deprecate(func, version) {
console.log(`${func} is deprecated as of ${version} and may be removed at any time.
Please convert to make-random-legacy if this function is still needed.`)
}

module.exports = {
deprecate
}

0 comments on commit fa9ad38

Please sign in to comment.