Skip to content

Commit 187cb78

Browse files
committed
feat(core): initial code commit
1 parent dc02e5b commit 187cb78

File tree

9 files changed

+205
-1
lines changed

9 files changed

+205
-1
lines changed

.editorconfig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# EditorConfig: http://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
# Unix-style newlines with a newline ending every file
7+
[*]
8+
charset = utf-8
9+
end_of_line = lf
10+
trim_trailing_whitespace = true
11+
insert_final_newline = true
12+
indent_style = space
13+
indent_size = 4
14+
15+
# 2 space indentation
16+
[*.yaml, *.yml]
17+
indent_style = space
18+
indent_size = 2

.github/workflows/tests.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Tests
2+
on: ['push', 'pull_request']
3+
jobs:
4+
test:
5+
name: Node.js ${{ matrix.node-version }}
6+
runs-on: ubuntu-latest
7+
strategy:
8+
fail-fast: false
9+
matrix:
10+
node-version: [^12, ^14, ^16, ^17]
11+
steps:
12+
- uses: actions/checkout@v2
13+
- uses: actions/setup-node@v2
14+
with:
15+
node-version: ${{ matrix.node-version }}
16+
- run: npm install
17+
- run: npm test

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Global
2+
node_modules/
3+
4+
# OS Generated
5+
.DS_Store*
6+
ehthumbs.db
7+
Icon?
8+
Thumbs.db
9+
*.swp
10+
11+
# phpstorm
12+
.idea/*

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<a name="1.0.0"></a>
2+
# [1.0.0](https://github.com/faker-javascript/age) (2022-01-08)
3+
* Initial release

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Sergey Romanenko
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,38 @@
1-
# age
1+
<h1 align="center">Age</h1>
2+
<p align="center">
23
Age package provides functionality to generate a fake age value.
4+
</p>
5+
6+
<p align="center">
7+
<a href="https://github.com/faker-javascript/age/releases"><img alt="Version" src="https://img.shields.io/github/release/faker-javascript/age.svg?label=version&color=green"></a> <a href="https://github.com/faker-javascript/age"><img src="https://img.shields.io/badge/license-MIT-blue.svg?color=green" alt="License"></a> <img src="https://github.com/faker-javascript/age/actions/workflows/tests.yml/badge.svg">
8+
9+
## Install
10+
11+
```
12+
$ npm install --save @fakerjs/age
13+
```
14+
15+
## Usage
16+
17+
```js
18+
import fakeAge from '@fakerjs/age';
19+
20+
fakeAge();
21+
//=> 42
22+
23+
fakeAge({type: 'child'});
24+
//=> 10
25+
// Allowed types are: child, teen, adult, senior
26+
```
27+
28+
## Tests
29+
30+
Run tests
31+
32+
```
33+
npm run test
34+
```
35+
36+
## License
37+
[The MIT License (MIT)](https://github.com/faker-javascript/age/blob/master/LICENSE.txt)
38+
Copyright (c) [Sergey Romanenko](https://github.com/Awilum)

index.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
export default function fakeAge(options) {
2+
options = options || {};
3+
let min = 0;
4+
let max = 100;
5+
switch (options.type) {
6+
case 'child':
7+
min = 0;
8+
max = 12;
9+
break;
10+
case 'teen':
11+
min = 13;
12+
max = 19;
13+
break;
14+
case 'adult':
15+
min = 18;
16+
max = 65;
17+
break;
18+
case 'senior':
19+
min = 65;
20+
max = 100;
21+
break;
22+
case 'all':
23+
min = 0;
24+
max = 100;
25+
break;
26+
default:
27+
min = 0;
28+
max = 100;
29+
break;
30+
}
31+
min = Math.ceil(min);
32+
max = Math.floor(max);
33+
return Math.floor(Math.random() * (max - min + 1)) + min;
34+
};

package.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "@fakerjs/age",
3+
"version": "1.0.0",
4+
"description": "Age package provides functionality to generate a fake age value.",
5+
"license": "MIT",
6+
"repository": "faker-javascript/age",
7+
"author": {
8+
"name": "Sergey Romanenko",
9+
"email": "awilum@msn.com",
10+
"url": "https://github.com/Awilum"
11+
},
12+
"type": "module",
13+
"exports": "./index.js",
14+
"engines": {
15+
"node": ">=12"
16+
},
17+
"scripts": {
18+
"test": "ava"
19+
},
20+
"devDependencies": {
21+
"ava": "^3.15.0"
22+
},
23+
"files": [
24+
"index.js"
25+
],
26+
"keywords": [
27+
"fakerjs",
28+
"fake",
29+
"random",
30+
"age"
31+
]
32+
}

test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import fakeAge from './index.js';
2+
import test from 'ava';
3+
4+
test('fakeAge return type to be number', t => {
5+
t.is(typeof fakeAge(), 'number');
6+
});
7+
8+
test('fakeAge with type child less than 13 and more than -1', t => {
9+
t.true(fakeAge({type: 'child'}) < 13);
10+
t.true(fakeAge({type: 'child'}) > -1);
11+
});
12+
13+
test('fakeAge with type teen less than 20 and more than 12', t => {
14+
t.true(fakeAge({type: 'teen'}) < 20);
15+
t.true(fakeAge({type: 'teen'}) > 12);
16+
});
17+
18+
test('fakeAge with type adult less than 69 and more than 17', t => {
19+
t.true(fakeAge({type: 'adult'}) < 69);
20+
t.true(fakeAge({type: 'adult'}) > 17);
21+
});
22+
23+
test('fakeAge with type senior less than 101 and more than 64', t => {
24+
t.true(fakeAge({type: 'senior'}) < 101);
25+
t.true(fakeAge({type: 'senior'}) > 64);
26+
});
27+
28+
test('fakeAge with type all less than 101 and more than -1', t => {
29+
t.true(fakeAge({type: 'all'}) < 101);
30+
t.true(fakeAge({type: 'all'}) > -1);
31+
});

0 commit comments

Comments
 (0)