-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
205 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# EditorConfig: http://EditorConfig.org | ||
|
||
# top-most EditorConfig file | ||
root = true | ||
|
||
# Unix-style newlines with a newline ending every file | ||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
# 2 space indentation | ||
[*.yaml, *.yml] | ||
indent_style = space | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: Tests | ||
on: ['push', 'pull_request'] | ||
jobs: | ||
test: | ||
name: Node.js ${{ matrix.node-version }} | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
node-version: [^12, ^14, ^16, ^17] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: npm install | ||
- run: npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Global | ||
node_modules/ | ||
|
||
# OS Generated | ||
.DS_Store* | ||
ehthumbs.db | ||
Icon? | ||
Thumbs.db | ||
*.swp | ||
|
||
# phpstorm | ||
.idea/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<a name="1.0.0"></a> | ||
# [1.0.0](https://github.com/faker-javascript/age) (2022-01-08) | ||
* Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) Sergey Romanenko | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,38 @@ | ||
# age | ||
<h1 align="center">Age</h1> | ||
<p align="center"> | ||
Age package provides functionality to generate a fake age value. | ||
</p> | ||
|
||
<p align="center"> | ||
<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"> | ||
|
||
## Install | ||
|
||
``` | ||
$ npm install --save @fakerjs/age | ||
``` | ||
|
||
## Usage | ||
|
||
```js | ||
import fakeAge from '@fakerjs/age'; | ||
|
||
fakeAge(); | ||
//=> 42 | ||
|
||
fakeAge({type: 'child'}); | ||
//=> 10 | ||
// Allowed types are: child, teen, adult, senior | ||
``` | ||
|
||
## Tests | ||
|
||
Run tests | ||
|
||
``` | ||
npm run test | ||
``` | ||
|
||
## License | ||
[The MIT License (MIT)](https://github.com/faker-javascript/age/blob/master/LICENSE.txt) | ||
Copyright (c) [Sergey Romanenko](https://github.com/Awilum) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
export default function fakeAge(options) { | ||
options = options || {}; | ||
let min = 0; | ||
let max = 100; | ||
switch (options.type) { | ||
case 'child': | ||
min = 0; | ||
max = 12; | ||
break; | ||
case 'teen': | ||
min = 13; | ||
max = 19; | ||
break; | ||
case 'adult': | ||
min = 18; | ||
max = 65; | ||
break; | ||
case 'senior': | ||
min = 65; | ||
max = 100; | ||
break; | ||
case 'all': | ||
min = 0; | ||
max = 100; | ||
break; | ||
default: | ||
min = 0; | ||
max = 100; | ||
break; | ||
} | ||
min = Math.ceil(min); | ||
max = Math.floor(max); | ||
return Math.floor(Math.random() * (max - min + 1)) + min; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "@fakerjs/age", | ||
"version": "1.0.0", | ||
"description": "Age package provides functionality to generate a fake age value.", | ||
"license": "MIT", | ||
"repository": "faker-javascript/age", | ||
"author": { | ||
"name": "Sergey Romanenko", | ||
"email": "[email protected]", | ||
"url": "https://github.com/Awilum" | ||
}, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"engines": { | ||
"node": ">=12" | ||
}, | ||
"scripts": { | ||
"test": "ava" | ||
}, | ||
"devDependencies": { | ||
"ava": "^3.15.0" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"fakerjs", | ||
"fake", | ||
"random", | ||
"age" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import fakeAge from './index.js'; | ||
import test from 'ava'; | ||
|
||
test('fakeAge return type to be number', t => { | ||
t.is(typeof fakeAge(), 'number'); | ||
}); | ||
|
||
test('fakeAge with type child less than 13 and more than -1', t => { | ||
t.true(fakeAge({type: 'child'}) < 13); | ||
t.true(fakeAge({type: 'child'}) > -1); | ||
}); | ||
|
||
test('fakeAge with type teen less than 20 and more than 12', t => { | ||
t.true(fakeAge({type: 'teen'}) < 20); | ||
t.true(fakeAge({type: 'teen'}) > 12); | ||
}); | ||
|
||
test('fakeAge with type adult less than 69 and more than 17', t => { | ||
t.true(fakeAge({type: 'adult'}) < 69); | ||
t.true(fakeAge({type: 'adult'}) > 17); | ||
}); | ||
|
||
test('fakeAge with type senior less than 101 and more than 64', t => { | ||
t.true(fakeAge({type: 'senior'}) < 101); | ||
t.true(fakeAge({type: 'senior'}) > 64); | ||
}); | ||
|
||
test('fakeAge with type all less than 101 and more than -1', t => { | ||
t.true(fakeAge({type: 'all'}) < 101); | ||
t.true(fakeAge({type: 'all'}) > -1); | ||
}); |