Skip to content

Commit abba864

Browse files
committed
feat(core): initial code commit
1 parent 8d9332e commit abba864

File tree

9 files changed

+172
-2
lines changed

9 files changed

+172
-2
lines changed

.editorconfig

+18
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

.gitignore

+12
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

+3
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/fakerjs/integer) (2022-01-08)
3+
* Initial release

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022 Faker Javascript
3+
Copyright (c) Sergey Romanenko
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

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

index.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export default function fakeInteger(min, max) {
2+
if (min === undefined) {
3+
min = Number.MIN_SAFE_INTEGER;
4+
}
5+
if (max === undefined) {
6+
max = Number.MAX_SAFE_INTEGER;
7+
}
8+
if (typeof min !== 'number' || typeof max !== 'number') {
9+
throw new TypeError('Expected all arguments to be numbers.');
10+
}
11+
if (min > max) {
12+
throw new TypeError('Min cannot be greater than Max.');
13+
}
14+
min = Math.ceil(min);
15+
max = Math.floor(max);
16+
return Math.floor(Math.random() * (max - min + 1)) + min;
17+
};

package.json

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "@fakerjs/integer",
3+
"version": "1.0.0",
4+
"description": "Random Integer package provides functionality to generate a fake integer value.",
5+
"license": "MIT",
6+
"repository": "fakerjs/integer",
7+
"author": {
8+
"name": "Sergey Romanenko",
9+
"email": "[email protected]",
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+
"faker",
29+
"random",
30+
"integer",
31+
"int",
32+
"number"
33+
]
34+
}

test.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import fakeInteger from './index.js';
2+
import test from 'ava';
3+
4+
test('fakeInteger return type to be number', t => {
5+
t.is(typeof fakeInteger(), 'number');
6+
});
7+
8+
test('fakeInteger with number min 0 return type to be number', t => {
9+
t.is(typeof fakeInteger(0), 'number');
10+
});
11+
12+
test('fakeInteger with number min 0 and max 10 return type to be number', t => {
13+
t.is(typeof fakeInteger(0, 10), 'number');
14+
});
15+
16+
test('fakeInteger with number min 0 and max 10 less than 11', t => {
17+
t.true(fakeInteger(0, 10) < 11);
18+
});
19+
20+
test('fakeInteger with string to thow error on string', t => {
21+
const error = t.throws(() => {
22+
fakeInteger('string')
23+
}, {instanceOf: TypeError});
24+
25+
t.is(error.message, 'Expected all arguments to be numbers.');
26+
});
27+
28+
test('fakeInteger with string to thow error on min > max', t => {
29+
const error = t.throws(() => {
30+
fakeInteger(10, 0)
31+
}, {instanceOf: TypeError});
32+
33+
t.is(error.message, 'Min cannot be greater than Max.');
34+
});

workflows/tests.yml

+17
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

0 commit comments

Comments
 (0)