Skip to content

Commit

Permalink
Merge pull request #14 from ndaidong/dev
Browse files Browse the repository at this point in the history
v0.2.01
  • Loading branch information
ndaidong authored Jun 17, 2016
2 parents c2a2df1 + 86f2b90 commit 59a5026
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 18 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# txtgen
Util for generating random sentences, paragraphs and articles in English. Inspired by [Sentencer](https://github.com/kylestetz/Sentencer) and [metaphorpsum.com](http://metaphorpsum.com/).

This library is very lightweight to use at client side. Just about 160B gzip or 7KB minified!
Lightweight util for generating random sentences, paragraphs and articles in English. Inspired by [Sentencer](https://github.com/kylestetz/Sentencer) and [metaphorpsum.com](http://metaphorpsum.com/).

[![NPM](https://badge.fury.io/js/txtgen.svg)](https://badge.fury.io/js/txtgen)
![Travis](https://travis-ci.org/ndaidong/txtgen.svg?branch=master)
Expand Down Expand Up @@ -54,6 +52,9 @@ console.log(article);
- .sentence()
- .paragraph([Number totalSentences])
- .article([Number totalParagraphs])
- .addNouns([Array nouns])
- .addAdjectives([Array adjectives])
- .addTemplates([Array sentenceTemplates])

# Test

Expand Down
19 changes: 10 additions & 9 deletions dist/txtgen.min.js

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.1.30",
"version": "0.2.01",
"name": "txtgen",
"description": "Util for generating random sentences, paragraphs and articles in English",
"homepage": "http://ndaidong.github.io/txtgen",
Expand All @@ -13,12 +13,12 @@
"node": ">= 6.0.0"
},
"scripts": {
"test": "./node_modules/.bin/snyk test && ./node_modules/.bin/tape test/start.js | tap-spec",
"test": "./node_modules/.bin/tape test/start.js | tap-spec",
"coverage": "./node_modules/.bin/nyc tape test/start.js | tap-spec",
"report": "npm run coverage && ./node_modules/.bin/nyc report --reporter=lcov",
"coveralls": "npm run report && cat ./coverage/lcov.info | ./node_modules/.bin/coveralls",
"build": "./node_modules/.bin/gccmin src dist",
"snyk": "./node_modules/.bin/snyk wizard"
"snyk": "./node_modules/.bin/snyk test"
},
"devDependencies": {
"bellajs": "latest",
Expand Down
33 changes: 32 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,34 @@
];
/* eslint-enable */

var unique = (a) => {
let r = [];
for (let i = 0; i < a.length; i++) {
if (r.indexOf(a[i]) === -1) {
r.push(a[i]);
}
}
return r;
};

var addNouns = (ls = []) => {
let a = nouns.concat(ls);
nouns = unique(a);
return nouns.length;
};

var addAdjectives = (ls) => {
let a = adjectives.concat(ls);
adjectives = unique(a);
return adjectives.length;
};

var addTemplates = (ls) => {
let a = sentenceTemplates.concat(ls);
sentenceTemplates = unique(a);
return sentenceTemplates.length;
};

var random = (min, max) => {
let offset = min;
let range = max - min + 1;
Expand Down Expand Up @@ -227,6 +255,9 @@
return {
sentence: makeSentence,
paragraph: makeParagraph,
article: makeArticle
article: makeArticle,
addNouns,
addAdjectives,
addTemplates
};
});
23 changes: 22 additions & 1 deletion test/specs/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ var hasMethods = (o) => {
var structure = [
'sentence',
'paragraph',
'article'
'article',
'addNouns',
'addAdjectives',
'addTemplates'
];

return structure.every((k) => {
Expand Down Expand Up @@ -46,3 +49,21 @@ test('txtgen.article():', (assert) => {
assert.ok(bella.isString(article) && article.length > 0, 'An article must be created');
assert.end();
});

test('txtgen.addNouns():', (assert) => {
let count = txtgen.addNouns([bella.createId(), bella.createId(), bella.createId()]);
assert.equals(count, 85, 'After adding 3 items => 85 nouns');
assert.end();
});

test('txtgen.addAdjectives():', (assert) => {
let count = txtgen.addAdjectives([bella.createId(), bella.createId(), bella.createId(), bella.createId()]);
assert.equals(count, 195, 'After adding 4 items => 195 adjectives');
assert.end();
});

test('txtgen.addTemplates():', (assert) => {
let count = txtgen.addTemplates([bella.createId(), bella.createId(), bella.createId()]);
assert.equals(count, 32, 'After adding 3 items => 32 adjectives');
assert.end();
});
32 changes: 31 additions & 1 deletion test/specs/txtgen.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ describe('Testing txtgen APIs', () => {
let keys = [
'sentence',
'paragraph',
'article'
'article',
'addNouns',
'addAdjectives',
'addTemplates'
];

let check = (k) => {
Expand Down Expand Up @@ -62,4 +65,31 @@ describe('Testing txtgen APIs', () => {
});

});

describe('txtgen.addNouns()', () => {

let d = txtgen.addNouns(['a', 'b', 'c']);
it('After adding 3 items => 85 nouns', () => {
expect(d).toBe(85);
});

});

describe('txtgen.addAdjectives()', () => {

let d = txtgen.addAdjectives(['a', 'b', 'c', 'd']);
it('After adding 4 items => 195 adjectives', () => {
expect(d).toBe(195);
});

});

describe('txtgen.addTemplates()', () => {

let d = txtgen.addTemplates(['a', 'b', 'c']);
it('After adding 3 items => 32 adjectives', () => {
expect(d).toBe(32);
});

});
});

0 comments on commit 59a5026

Please sign in to comment.