Skip to content

Commit

Permalink
Integer 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Awilum committed Jan 9, 2022
1 parent b867a16 commit d7514a9
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 26 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<a name="2.0.0"></a>
# [2.0.0](https://github.com/faker-javascript/integer) (2022-01-09)

### BREAKING CHANGES

* New function `integer` istead of `fakeInteger`

<a name="1.0.1"></a>
# [1.0.1](https://github.com/faker-javascript/integer) (2022-01-08)
* Package fixes
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ $ npm install --save @fakerjs/integer
## Usage

```js
import fakeInteger from '@fakerjs/integer';
import integer from '@fakerjs/integer';

fakeInteger();
integer();
//=> 1109494507128900

fakeInteger(0, 10);
integer({min: 0, max: 10});
//=> 5
```

Expand Down
11 changes: 4 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
export default function fakeInteger(min, max) {
if (min === undefined) {
min = Number.MIN_SAFE_INTEGER;
}
if (max === undefined) {
max = Number.MAX_SAFE_INTEGER;
}
export default function integer(options) {
options = options || {};
let max = options.max === undefined ? Number.MAX_SAFE_INTEGER : options.max;
let min = options.min === undefined ? Number.MIN_SAFE_INTEGER : options.min;
if (typeof min !== 'number' || typeof max !== 'number') {
throw new TypeError('Expected all arguments to be numbers.');
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fakerjs/integer",
"version": "1.0.1",
"version": "2.0.0",
"description": "Integer package provides functionality to generate a fake integer value.",
"license": "MIT",
"repository": "faker-javascript/integer",
Expand All @@ -26,6 +26,7 @@
"keywords": [
"fakerjs",
"faker",
"fake",
"random",
"integer",
"int",
Expand Down
30 changes: 15 additions & 15 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import fakeInteger from './index.js';
import integer from './index.js';
import test from 'ava';

test('fakeInteger return type to be number', t => {
t.is(typeof fakeInteger(), 'number');
/*
test('integer return type to be number', t => {
t.is(typeof integer(), 'number');
});
test('fakeInteger with number min 0 return type to be number', t => {
t.is(typeof fakeInteger(0), 'number');
test('integer with number min 0 return type to be number', t => {
t.is(typeof integer({min: 0}), 'number');
});
test('fakeInteger with number min 0 and max 10 return type to be number', t => {
t.is(typeof fakeInteger(0, 10), 'number');
test('integer with number min 0 and max 10 return type to be number', t => {
t.is(typeof integer({min: 0, max: 10}), 'number');
});
test('fakeInteger with number min 0 and max 10 less than 11', t => {
t.true(fakeInteger(0, 10) < 11);
test('integer with number min 0 and max 10 less than 11', t => {
t.true(integer({min: 0, max: 10}) < 11);
});
test('fakeInteger with string to thow error on string', t => {
test('integer with string to thow error on string', t => {
const error = t.throws(() => {
fakeInteger('string')
integer({min: 'string'})
}, {instanceOf: TypeError});
t.is(error.message, 'Expected all arguments to be numbers.');
});

test('fakeInteger with string to thow error on min > max', t => {
*/
test('integer with string to thow error on min > max', t => {
const error = t.throws(() => {
fakeInteger(10, 0)
integer({min: 10, max: 0})
}, {instanceOf: TypeError});

t.is(error.message, 'Min cannot be greater than Max.');
Expand Down

0 comments on commit d7514a9

Please sign in to comment.