Skip to content

Commit 6aa1e03

Browse files
committed
Merge branch 'release/1.9.0' into main
2 parents 98aa7c6 + 09b0722 commit 6aa1e03

File tree

13 files changed

+154
-16
lines changed

13 files changed

+154
-16
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ randomer.NUMBER.INTEGER(min, max); // Defaults to 1, 100
3030
#### String
3131

3232
```js
33-
// Parameter number of characters as string
33+
// Parameter number of characters, could be used as a random password generator
3434
randomer.STRING.GIBBERISH(length); // Defaults to 10
3535

3636
// Array of full name strings between 1 and 1000 results
@@ -95,6 +95,16 @@ randomer.EMAIL.SINGLE(host); // Defaults to randomer
9595
randomer.EMAIL.LIST(howMany); // Defaults to 10
9696
```
9797

98+
#### Users
99+
100+
```js
101+
// Random user object, { firstName: '...', lastName: '...', email: '...', password: '...', dob: '...' }
102+
randomer.USER.SINGLE();
103+
104+
// Array of user objects between 1 and 1000 results
105+
randomer.USER.LIST(howMany); // Defaults to 10
106+
```
107+
98108
## Contributing
99109

100110
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ const COLOR = require('./modules/color');
55
const DATE = require('./modules/date');
66
const QUOTES = require('./modules/quote');
77
const EMAIL = require('./modules/email');
8+
const USER = require('./modules/user');
89

910
module.exports = {
10-
NUMBER, STRING, BOOLEAN, COLOR, DATE, QUOTES, EMAIL,
11+
NUMBER, STRING, BOOLEAN, COLOR, DATE, QUOTES, EMAIL, USER,
1112
};

modules/email.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Importing dependecies
22
const { ARGUMENTS } = require('../utils/arguments');
3-
4-
const { names } = require('../data/names');
5-
const { INTEGER } = require('./number');
3+
const { name: fullName } = require('../utils/helpers');
64

75
/**
86
* Returns random generated email address
@@ -16,7 +14,7 @@ exports.SINGLE = function (host = 'randomer') {
1614
ARGUMENTS(arguments, 0, 1, 'string', undefined);
1715

1816
// Creating value
19-
const name = names[INTEGER(0, names.length - 1)].replace(/\s/g, '.').toLowerCase();
17+
const name = fullName().replace(/\s/g, '.').toLowerCase();
2018
const value = `${name}@${host}.com`;
2119

2220
// Making sure value is casted to proper type
@@ -43,5 +41,6 @@ exports.LIST = function (howMany = 10) {
4341
value.push(email);
4442
}
4543

44+
// Returning value
4645
return value;
4746
};

modules/string.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ exports.GIBBERISH = function (length = 10) {
2727
};
2828

2929
// Importing dependecies
30-
const { names } = require('../data/names');
31-
const { INTEGER } = require('./number');
30+
const { name } = require('../utils/helpers');
3231

3332
/**
3433
* Returns array of random full names, default length is one, can
@@ -46,9 +45,9 @@ exports.NAMES = function (howMany = 10) {
4645
const value = [];
4746

4847
for (let i = 0; i < howMany; i += 1) {
49-
const index = INTEGER(0, names.length - 1);
50-
value.push(names[index]);
48+
value.push(name());
5149
}
5250

51+
// Returning value
5352
return value;
5453
};

modules/user.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Importing dependecies
2+
const { ARGUMENTS } = require('../utils/arguments');
3+
const { name } = require('../utils/helpers');
4+
const { GIBBERISH } = require('./string');
5+
const { PAST } = require('./date');
6+
7+
/**
8+
* Returns random generated user object
9+
*
10+
* @return {Object} Resulting user object containtng parameters first
11+
* name, last name, email, password & date of birth
12+
*/
13+
exports.SINGLE = function () {
14+
// Arguments checking
15+
ARGUMENTS(arguments, 0, 0, undefined, undefined);
16+
17+
// Creating value
18+
const user = name().split(' ');
19+
20+
const value = {
21+
firstName: user[0],
22+
lastName: user[1],
23+
email: `${user[0]}.${user[1]}@randomer.com`.toLowerCase(),
24+
password: GIBBERISH(10),
25+
dob: PAST(),
26+
};
27+
28+
// Returning value
29+
return value;
30+
};
31+
32+
/**
33+
* Returns array of random user objects, default length is 10, can
34+
* be overridden using parameter
35+
*
36+
* @param {Number} [howMany=10] Number of emails you need
37+
*
38+
* @return {Array} Resulting array of user objects
39+
*/
40+
exports.LIST = function (howMany = 10) {
41+
// Arguments checking
42+
ARGUMENTS(arguments, 0, 1, 'number', howMany);
43+
44+
// Creating value
45+
const value = [];
46+
47+
for (let i = 0; i < howMany; i += 1) {
48+
const user = exports.SINGLE();
49+
value.push(user);
50+
}
51+
52+
// Returning value
53+
return value;
54+
};

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "complete-randomer",
3-
"version": "1.8.0",
3+
"version": "1.9.0",
44
"description": "A simple NPM helper package for generating random values.",
55
"author": "Miloš Paunović <paun992@hotmail.com>",
66
"repository": {

test/number/integer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const { INTEGER } = require('../../modules/number');
33

44
describe('INTEGER()', () => {
55
it('Should throw TypeError if more than 2 parameter are sent', () => {
6-
assert.throw(() => { INTEGER(1, 2, 3); }, TypeError, '2 parameter(s) allowed');
6+
assert.throw(() => { INTEGER(true, true, true); }, TypeError, '2 parameter(s) allowed');
77
});
88

99
it('Should throw TypeError if at least one parameter is not Number', () => {

test/string/gibberish.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const { GIBBERISH } = require('../../modules/string');
33

44
describe('GIBBERISH()', () => {
55
it('Should throw TypeError if more than 2 parameter are sent', () => {
6-
assert.throw(() => { GIBBERISH(1, 2); }, TypeError, '1 parameter(s) allowed');
6+
assert.throw(() => { GIBBERISH(true, true); }, TypeError, '1 parameter(s) allowed');
77
});
88

99
it('Should throw TypeError if parameter is not Number', () => {

test/string/names.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const { NAMES } = require('../../modules/string');
33

44
describe('NAMES()', () => {
55
it('Should throw TypeError if more than 1 parameter is sent', () => {
6-
assert.throw(() => { NAMES(1, 2); }, TypeError, '1 parameter(s) allowed');
6+
assert.throw(() => { NAMES(true, true); }, TypeError, '1 parameter(s) allowed');
77
});
88

99
it('Should throw TypeError if parameter is not Number', () => {

0 commit comments

Comments
 (0)