Skip to content
This repository has been archived by the owner on Nov 2, 2019. It is now read-only.

Commit

Permalink
README file updated ~ create lib/util functions ~ more test included
Browse files Browse the repository at this point in the history
  • Loading branch information
Prosen-Ghosh committed Aug 26, 2017
1 parent b81a407 commit 0733c35
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 37 deletions.
52 changes: 19 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
# random-pro
A JavaScript package for random things.

![npm](https://img.shields.io/npm/v/random-pro.svg) ![license](https://img.shields.io/npm/l/random-pro.svg) ![github-issues](https://img.shields.io/github/issues/Prosen-Ghosh/random-pro.svg) ![Circle CI build status](https://circleci.com/gh/Prosen-Ghosh/random-pro.svg?style=svg)
![npm](https://img.shields.io/npm/v/random-pro.svg) ![license](https://img.shields.io/npm/l/random-pro.svg) ![github-issues](https://img.shields.io/github/issues/Prosen-Ghosh/random-pro.svg)

A JavaScript package for random things.

![nodei.co](https://nodei.co/npm/random-pro.png?downloads=true&downloadRank=true&stars=true)

![travis-status](https://img.shields.io/travis/Prosen-Ghosh/random-pro.svg)
![stars](https://img.shields.io/github/stars/Prosen-Ghosh/random-pro.svg)
![forks](https://img.shields.io/github/forks/Prosen-Ghosh/random-pro.svg)

![forks](https://img.shields.io/github/forks/Prosen-Ghosh/random-pro.svg)

![](https://david-dm.org/Prosen-Ghosh/random-pro/status.svg)
![](https://david-dm.org/Prosen-Ghosh/random-pro/dev-status.svg)

## Features

# Features

## Install

`npm install --save random-pro`


## Scripts

- **npm run test** : `mocha || true`
- **npm run readme** : `node ./node_modules/.bin/node-readme`

## Dependencies
## Development Dependencies

Package | Version | Dev
--- |:---:|:---:
Expand All @@ -37,30 +27,16 @@ Package | Version | Dev
[node-readme](https://www.npmjs.com/package/node-readme) | ^0.1.9 | ✔


## Contributing

Contributions welcome; Please submit all pull requests the against master branch. If your pull request contains JavaScript patches or features, you should include relevant unit tests. Please check the [Contributing Guidelines](contributng.md) for more details. Thanks!

## Author

Prosen Ghosh <[email protected]> (https://bd.linkedin.com/in/prosen-ghosh-baba9aa8)

## License

- **MIT** : http://opensource.org/licenses/MIT
# random-pro
A JavaScript package for random things.

## Installation
```npm install random-pro```

## Number

***generateNumber()*** This Function will generate random number.

```javascript
var rand = require('random-pro');
console.log(rand.generateNumber());
// 0.24763671110551866
```

***generateNumber(start)*** This function will generate random number from your input number to 1000 inclusive.

```javascript
Expand All @@ -70,6 +46,7 @@ console.log(rand.generateNumber(75));
console.log(rand.generateNumber(75));
// 129
```

***generateNumber(start,end)*** This function will generate random number from your input number start to end inclusive.

```javascript
Expand All @@ -82,22 +59,26 @@ console.log(rand.generateNumber(300));
## Users

***generateName()*** This function Will generate random name.

```javascript
var rand = require('random-pro');
console.log(rand.generateName());
// Johirul
console.log(rand.generateName());
// Abhijit
```

You can also use gender for generate name.
***generateName(gender)*** This Function will generate name based on gender. Gender Is case insensitive.

```javascript
var rand = require('random-pro');
console.log(rand.generateName("male"));
// Sany
console.log(rand.generateName("Female"));
// Farzana
```

***generateLastName()*** This function Will generate random last name of a user.

```javascript
Expand All @@ -107,6 +88,7 @@ console.log(rand.generateLastName());
console.log(rand.generateLastName());
// Ghosh
```

***generateFullName(gender)*** This Function Will generate random full name. The Deafult parameter of the function is `Male`.

```javascript
Expand Down Expand Up @@ -134,7 +116,7 @@ console.log(rand.generateEmail());

## String

***generateString(words,paragraph)*** This function will generate random string. The default parameter of this function of word and paragraph is 1.
***generateString(latters,paragraph)*** This function will generate random string. The default parameter of this function of latters is 50 and paragraph is 1.

```javascript
var rand = require('random-pro');
Expand All @@ -152,4 +134,8 @@ console.log(rand.generateString(50,2));

## License

MIT
- **MIT** : http://opensource.org/licenses/MIT

## Author

***Prosen Ghosh*** <[email protected]> (https://bd.linkedin.com/in/prosen-ghosh-baba9aa8)
11 changes: 11 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var countWord = (str) => {
return str.length;
}

var checkEmail = (email) => {
return /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email);
}
module.exports = {
countWord,
checkEmail
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "random-pro",
"version": "0.0.8",
"version": "0.0.9",
"description": "A JavaScript package for random things.",
"main": "index.js",
"scripts": {
Expand Down
8 changes: 6 additions & 2 deletions src/pro-string.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
var text = require('./../data/text');
var countWord = require('./../lib/util').countWord;

var generateString = function(words = 1,paragraph = 1){
var generateString = function(latters = 50,paragraph = 1){

let tmp = '';
for(let i = 0; i < paragraph; i++){
for(let j = 0; j < words; j++){
for(let j = 0; j < latters; j++){
tmp += text[Math.floor(Math.random() * text.length + 1)] + " ";
if(tmp.length === countWord(tmp)){
break;
}
}
tmp += "\n\n";
}
Expand Down
13 changes: 13 additions & 0 deletions test/appTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ const chai = require('chai'),
assert = chai.assert;
const index = require('./../index');
const names = require('./../data/names');
const util = require('./../lib/util')
countWord = util.countWord,
checkEmail = util.checkEmail;

describe("Index",function(){
it("Generate Number type should be a number.",function(){
Expand Down Expand Up @@ -37,6 +40,16 @@ describe("Index",function(){
assert.isAtMost(res,end);
});

it("Generate String Should equal to the word arguments",function(){
let res = index.generateString();
assert.equal(res.length,countWord(res));
});

it("Generate Email Should be a Valid Email",function(){
let email = index.generateEmail();
assert.equal(checkEmail(email),true);
});

// it("Generate Name should return a name from the First name male array."),function(done){
// let res = index.generateName(),
// arrayVal = false;
Expand Down

0 comments on commit 0733c35

Please sign in to comment.