Skip to content

Commit 0da8f0d

Browse files
committed
Age 2.1.0
1 parent 1d50db2 commit 0da8f0d

File tree

6 files changed

+47
-25
lines changed

6 files changed

+47
-25
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
<a name="2.1.0"></a>
2+
# [2.1.0](https://github.com/faker-javascript/age) (2022-01-11)
3+
* Added xo, tsd, c8.
4+
* Improved tests.
5+
16
<a name="2.0.0"></a>
27
# [2.0.0](https://github.com/faker-javascript/age) (2022-01-09)
38

index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
interface Options {
2+
type: string;
3+
}
4+
export default function age(options?: Options): number;

index.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,32 @@ export default function age(options) {
44
let max = 100;
55
switch (options.type) {
66
case 'child':
7-
min = 0;
7+
min = 0;
88
max = 12;
99
break;
1010
case 'teen':
11-
min = 13;
11+
min = 13;
1212
max = 19;
1313
break;
1414
case 'adult':
15-
min = 18;
15+
min = 18;
1616
max = 65;
1717
break;
1818
case 'senior':
19-
min = 65;
19+
min = 65;
2020
max = 100;
2121
break;
2222
case 'all':
23-
min = 0;
23+
min = 0;
2424
max = 100;
2525
break;
2626
default:
27-
min = 0;
27+
min = 0;
2828
max = 100;
2929
break;
3030
}
31+
3132
min = Math.ceil(min);
3233
max = Math.floor(max);
3334
return Math.floor(Math.random() * (max - min + 1)) + min;
34-
};
35+
}

index.test-d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {expectType} from 'tsd';
2+
import age from './index.js';
3+
4+
expectType<number>(age());
5+
expectType<number>(age({type: 'child'}));
6+
expectType<number>(age({type: 'teen'}));
7+
expectType<number>(age({type: 'adult'}));
8+
expectType<number>(age({type: 'senior'}));
9+
expectType<number>(age({type: 'all'}));

package.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fakerjs/age",
3-
"version": "2.0.0",
3+
"version": "2.1.0",
44
"description": "Age package provides functionality to generate a fake age value.",
55
"license": "MIT",
66
"repository": "faker-javascript/age",
@@ -15,14 +15,17 @@
1515
"node": ">=12"
1616
},
1717
"scripts": {
18-
"test": "c8 ava"
18+
"test": "c8 ava; xo --space 4; tsd;"
1919
},
2020
"devDependencies": {
21-
"ava": "^3.15.0",
22-
"c8": "^7.11.0"
21+
"ava": "^4.0.0",
22+
"c8": "^7.11.0",
23+
"tsd": "^0.19.1",
24+
"xo": "^0.47.0"
2325
},
2426
"files": [
25-
"index.js"
27+
"index.js",
28+
"index.d.ts"
2629
],
2730
"keywords": [
2831
"fakerjs",

test.js

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

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

88
test('age with type child less than 13 and more than -1', t => {
9-
t.true(age({type: 'child'}) < 13);
10-
t.true(age({type: 'child'}) > -1);
9+
t.true(age({type: 'child'}) < 13);
10+
t.true(age({type: 'child'}) > -1);
1111
});
1212

1313
test('age with type teen less than 20 and more than 12', t => {
14-
t.true(age({type: 'teen'}) < 20);
15-
t.true(age({type: 'teen'}) > 12);
14+
t.true(age({type: 'teen'}) < 20);
15+
t.true(age({type: 'teen'}) > 12);
1616
});
1717

1818
test('age with type adult less than 69 and more than 17', t => {
19-
t.true(age({type: 'adult'}) < 69);
20-
t.true(age({type: 'adult'}) > 17);
19+
t.true(age({type: 'adult'}) < 69);
20+
t.true(age({type: 'adult'}) > 17);
2121
});
2222

2323
test('age with type senior less than 101 and more than 64', t => {
24-
t.true(age({type: 'senior'}) < 101);
25-
t.true(age({type: 'senior'}) > 64);
24+
t.true(age({type: 'senior'}) < 101);
25+
t.true(age({type: 'senior'}) > 64);
2626
});
2727

2828
test('age with type all less than 101 and more than -1', t => {
29-
t.true(age({type: 'all'}) < 101);
30-
t.true(age({type: 'all'}) > -1);
31-
});
29+
t.true(age({type: 'all'}) < 101);
30+
t.true(age({type: 'all'}) > -1);
31+
});

0 commit comments

Comments
 (0)