Skip to content

Commit d29b5ba

Browse files
committed
Float 2.0.0
1 parent 38600c2 commit d29b5ba

File tree

5 files changed

+31
-26
lines changed

5 files changed

+31
-26
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
<a name="2.0.0"></a>
2+
# [2.0.0](https://github.com/faker-javascript/float) (2022-01-09)
3+
4+
### BREAKING CHANGES
5+
6+
* New function `float` istead of `fakeFloat`
7+
18
<a name="1.0.2"></a>
29
# [1.0.2](https://github.com/faker-javascript/float) (2022-01-08)
310
* Package fixes

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ $ npm install --save @fakerjs/float
1515
## Usage
1616

1717
```js
18-
import fakeFloat from '@fakerjs/float';
18+
import float from '@fakerjs/float';
1919

20-
fakeFloat();
20+
float();
2121
//=> -120920142888.5024
2222

23-
fakeFloat(0, 10);
23+
float({min: 0, max: 10});
2424
//=> 7.6913
2525

26-
fakeFloat(0, 10, 6);
26+
float({min: 0, max: 10, fixed: 6);
2727
//=> 7.691312
2828
```
2929

index.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
export default function fakeFloat(min, max, fixed) {
2-
fixed = Math.pow(10, ((fixed === undefined) ? 4 : fixed));
3-
if (max === undefined) {
4-
max = Number.MAX_SAFE_INTEGER / fixed;
5-
}
6-
if (min === undefined) {
7-
min = Number.MIN_SAFE_INTEGER / fixed;
8-
}
1+
export default function fakeFloat(options) {
2+
options = options || {};
3+
let fixed = Math.pow(10, ((options.fixed === undefined) ? 4 : options.fixed));
4+
let max = (options.max === undefined) ? Number.MAX_SAFE_INTEGER / fixed : options.max;
5+
let min = (options.min === undefined) ? Number.MIN_SAFE_INTEGER / fixed : options.min;
96
if (typeof min !== 'number' || typeof max !== 'number') {
107
throw new TypeError('Expected all arguments to be numbers.');
118
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fakerjs/float",
3-
"version": "1.0.2",
3+
"version": "2.0.0",
44
"description": "Float package provides functionality to generate a fake float value.",
55
"license": "MIT",
66
"repository": "faker-javascript/float",
@@ -26,6 +26,7 @@
2626
"keywords": [
2727
"fakerjs",
2828
"faker",
29+
"fake",
2930
"random",
3031
"float",
3132
"number"

test.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
import fakeFloat from './index.js';
1+
import float from './index.js';
22
import test from 'ava';
33

4-
test('fakeFloat return type to be number', t => {
5-
t.is(typeof fakeFloat(), 'number');
4+
test('float return type to be number', t => {
5+
t.is(typeof float(), 'number');
66
});
77

8-
test('fakeFloat with number min 0 return type to be number', t => {
9-
t.is(typeof fakeFloat(0), 'number');
8+
test('float with number min 0 return type to be number', t => {
9+
t.is(typeof float({min: 0}), 'number');
1010
});
1111

12-
test('fakeFloat with number min 0 and max 10 return type to be number', t => {
13-
t.is(typeof fakeFloat(0, 10), 'number');
12+
test('float with number min 0 and max 10 return type to be number', t => {
13+
t.is(typeof float({min: 0, max: 10}), 'number');
1414
});
1515

16-
test('fakeFloat with number min 0 and max 10 less than 11', t => {
17-
t.true(fakeFloat(0, 10) < 11);
16+
test('float with number min 0 and max 10 less than 11', t => {
17+
t.true(float({min: 0, max: 10}) < 11);
1818
});
1919

20-
test('fakeFloat with string to thow error on string', t => {
20+
test('float with string to thow error on string', t => {
2121
const error = t.throws(() => {
22-
fakeFloat('string', 'string', 'string')
22+
float({min: 'string', max: 'string', fixed: 'string'})
2323
}, {instanceOf: TypeError});
2424

2525
t.is(error.message, 'Expected all arguments to be numbers.');
2626
});
2727

28-
test('fakeFloat with min and max to thow error on min > max', t => {
28+
test('float with min and max to thow error on min > max', t => {
2929
const error = t.throws(() => {
30-
fakeFloat(10, 0)
30+
float({min: 10, max: 0})
3131
}, {instanceOf: TypeError});
3232

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

0 commit comments

Comments
 (0)