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

Commit

Permalink
count sentences problem fixed ~ package releasing
Browse files Browse the repository at this point in the history
  • Loading branch information
Prosen-Ghosh committed Aug 26, 2017
1 parent e51a115 commit 4f727d9
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 53 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ console.log(rand.generateEmail());

## String

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

```javascript
var rand = require('random-pro');
console.log(rand.generateEmail(30,1));
console.log(rand.generateString(30,1));
/*
and useful 1998 controlling View the stated its production make through Sergey The were editing has launched percent Must only have one clause. an shares India notetaking became that hardware services navigation Don't be evil offers August
*/
Expand Down
81 changes: 46 additions & 35 deletions data/text.js

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

6 changes: 3 additions & 3 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
var countWord = (str) => {
return str.length;
var countSentences = (str) => {
return str.split('.').length;
}

var checkEmail = (email) => {
return /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email);
}
module.exports = {
countWord,
countSentences,
checkEmail
}
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.10",
"version": "1.0.0",
"description": "A JavaScript package for random things.",
"main": "index.js",
"scripts": {
Expand Down
14 changes: 7 additions & 7 deletions src/pro-string.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
var text = require('./../data/text');
var countWord = require('./../lib/util').countWord;
var countSentences = require('./../lib/util').countSentences;

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

let tmp = '';
let tmp = 'This Random Generator generate random string.';
for(let i = 0; i < paragraph; i++){
for(let j = 0; j < latters; j++){
if(countWord(tmp) <= latters){
break;
for(let j = 0; j < sentences; j++){
if(countSentences(tmp) <= sentences-1){
tmp += text[Math.floor(Math.random() * text.length + 1)];
}
else tmp += text[Math.floor(Math.random() * text.length + 1)] + " ";
else break;
}
tmp += "\n\n";
}
Expand Down
10 changes: 5 additions & 5 deletions test/appTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const chai = require('chai'),
const index = require('./../index');
const names = require('./../data/names');
const util = require('./../lib/util')
countWord = util.countWord,
countSentences = util.countSentences,
checkEmail = util.checkEmail;

describe("Index",function(){
Expand Down Expand Up @@ -40,12 +40,12 @@ describe("Index",function(){
assert.isAtMost(res,end);
});

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

it("Generate Email Should be a Valid Email",function(){
Expand Down

0 comments on commit 4f727d9

Please sign in to comment.