Skip to content

Commit

Permalink
Age 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Awilum committed Jan 11, 2022
1 parent 1d50db2 commit 0da8f0d
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 25 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<a name="2.1.0"></a>
# [2.1.0](https://github.com/faker-javascript/age) (2022-01-11)
* Added xo, tsd, c8.
* Improved tests.

<a name="2.0.0"></a>
# [2.0.0](https://github.com/faker-javascript/age) (2022-01-09)

Expand Down
4 changes: 4 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
interface Options {
type: string;
}
export default function age(options?: Options): number;
15 changes: 8 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,32 @@ export default function age(options) {
let max = 100;
switch (options.type) {
case 'child':
min = 0;
min = 0;
max = 12;
break;
case 'teen':
min = 13;
min = 13;
max = 19;
break;
case 'adult':
min = 18;
min = 18;
max = 65;
break;
case 'senior':
min = 65;
min = 65;
max = 100;
break;
case 'all':
min = 0;
min = 0;
max = 100;
break;
default:
min = 0;
min = 0;
max = 100;
break;
}

min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
};
}
9 changes: 9 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {expectType} from 'tsd';
import age from './index.js';

expectType<number>(age());
expectType<number>(age({type: 'child'}));
expectType<number>(age({type: 'teen'}));
expectType<number>(age({type: 'adult'}));
expectType<number>(age({type: 'senior'}));
expectType<number>(age({type: 'all'}));
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fakerjs/age",
"version": "2.0.0",
"version": "2.1.0",
"description": "Age package provides functionality to generate a fake age value.",
"license": "MIT",
"repository": "faker-javascript/age",
Expand All @@ -15,14 +15,17 @@
"node": ">=12"
},
"scripts": {
"test": "c8 ava"
"test": "c8 ava; xo --space 4; tsd;"
},
"devDependencies": {
"ava": "^3.15.0",
"c8": "^7.11.0"
"ava": "^4.0.0",
"c8": "^7.11.0",
"tsd": "^0.19.1",
"xo": "^0.47.0"
},
"files": [
"index.js"
"index.js",
"index.d.ts"
],
"keywords": [
"fakerjs",
Expand Down
26 changes: 13 additions & 13 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import age from './index.js';
import test from 'ava';
import age from './index.js';

test('age return type to be number', t => {
t.is(typeof age(), 'number');
t.is(typeof age(), 'number');
});

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

test('age with type teen less than 20 and more than 12', t => {
t.true(age({type: 'teen'}) < 20);
t.true(age({type: 'teen'}) > 12);
t.true(age({type: 'teen'}) < 20);
t.true(age({type: 'teen'}) > 12);
});

test('age with type adult less than 69 and more than 17', t => {
t.true(age({type: 'adult'}) < 69);
t.true(age({type: 'adult'}) > 17);
t.true(age({type: 'adult'}) < 69);
t.true(age({type: 'adult'}) > 17);
});

test('age with type senior less than 101 and more than 64', t => {
t.true(age({type: 'senior'}) < 101);
t.true(age({type: 'senior'}) > 64);
t.true(age({type: 'senior'}) < 101);
t.true(age({type: 'senior'}) > 64);
});

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

0 comments on commit 0da8f0d

Please sign in to comment.