rantjs 1.0.9 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,20 +0,0 @@
1
-
2
- var getCase = function (tokenStream) {
3
- var _case = 0;
4
- var cases = ["default", "none", "lower", "upper", "title", "word", "first", "sentence"];
5
- var token, matches, re;
6
- while (matches = /(\[.*?\])/g.exec(tokenStream)) {
7
- re = new RegExp("\\w+", "g");
8
- token = matches[1].match(re);
9
- if (["case"].indexOf(token[0]) != -1) {
10
- if (token[0] === "case") {
11
- if (cases.indexOf(token[1] != -1)) {
12
- _case = cases.indexOf(token[1]);
13
- }
14
- }
15
- }
16
- return cases[_case];
17
- }
18
- return cases[0];
19
- };
20
- module.exports = getCase;
@@ -1,24 +0,0 @@
1
- var lexer = function (input, dic) {
2
- dic = dic || require("./en_US");
3
- var tempRes="";
4
- var result = input, matches, token, replacement = [],regex = /\<(.*?)\>/g;
5
- while (matches = regex.exec(input)) {
6
- // We accept a number of keywords, and they all correlate to the entries in the DIC files
7
- // First, get the DIC token
8
- re = new RegExp("\\w+", "g");
9
- token = matches[1].match(re);
10
- // Match against valid keywords in valid_tokens
11
- if (dic().tokens.indexOf(token[0]) != -1) {
12
- // Now we're ready to pass the token to the parser. It should
13
- // include the token and any modifiers and subs
14
- // result = lexer(this, matches, result);
15
-
16
- tempRes = require("./replaceToken")( matches, result, 1, dic);
17
- result = result.replace(matches[0], function () {
18
- return tempRes;
19
- });
20
- }
21
- }
22
- return result;
23
- };
24
- module.exports=lexer;
@@ -1,11 +0,0 @@
1
- var randomString = function (l, chars) {
2
- chars = chars || 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
3
- //chars = chars || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
4
- var rndString = '';
5
- for (var i = 0; i < l; i++) {
6
- var rndPos = Math.floor(Math.random() * chars.length);
7
- rndString += chars.substring(rndPos, rndPos + 1);
8
- }
9
- return rndString;
10
- };
11
- module.exports = randomString;
@@ -1,70 +0,0 @@
1
- var replaceToken = function (matches, input, matchIndex, dic) {
2
- dic = dic || require('./en_US');
3
- var result, modifier = 0, re = new RegExp("\\w+", "g");
4
- var token = matches[matchIndex].match(re)[0];
5
- var indexPos = matches.index;
6
- var matched = matches[matchIndex].match(re);
7
- // matches[0] contains the token. It can be noun, verb, adj etc.
8
- // we already know it's valid, because this function doesn't get
9
- // called unless it is.
10
- // Let's check if there's any qualifiers or modifiers
11
- if (token.length > 1) {
12
- // There are two types. Filters and subs. Let's see what we got
13
- var mysubs = myfilters = [];
14
- var dictionary = [];
15
- if (matched.length > 1) {
16
- matched.forEach(function (entry, idx) {
17
- if (idx > 0) {
18
- if ("undefined" != typeof dic()[token].filters) {
19
- if (dic()[token].filters.indexOf(entry) > -1) {
20
- // Filters are categories of the token, so <adj emotion> will
21
- // set filters valid for emotion for the token adj
22
- myfilters.push(entry);
23
- }
24
- }
25
- if ("undefined" != typeof dic()[token].subs) {
26
- if (dic()[token].subs.indexOf(entry) > -1) {
27
- // Subs are grammatical instructions
28
- modifier = dic()[token].subs.indexOf(entry);
29
- }
30
- }
31
- }
32
- // So.. now we got the token, the filters and the subs. Let's do some magic
33
- });
34
- }
35
- }
36
- if (myfilters.length <= 0) {
37
- if ("undefined" != typeof dic()[token].all) {
38
- dictionary = dictionary.concat(dic()[token].all);
39
- }
40
- } else {
41
- dictionary = dictionary.concat(dic()[token][myfilters.pop()]);
42
-
43
- //myfilters.forEach(function (e) {
44
- // dictionary = dictionary.concat(dic()[token][e]);
45
- //});
46
- }
47
-
48
- if (modifier === 0) {
49
- matched.forEach(function (e) {
50
- if (e.toLowerCase() === "modifier") {
51
- modifier = 1;
52
- }
53
- });
54
- }
55
-
56
- var rand, newToken, replacement = [];
57
- re = new RegExp(matches[0], 'g');
58
-
59
- rand = Math.floor(Math.random() * dictionary.length);
60
- if (dictionary[rand].match(/\//) <= 0) {
61
- newToken = dictionary[rand];
62
- } else {
63
- newToken = dictionary[rand].split("/")[modifier];
64
- }
65
- replacement.push(newToken);
66
-
67
- rand = Math.floor(Math.random() * dictionary.length);
68
- return replacement[0];
69
- };
70
- module.exports=replaceToken;
@@ -1,11 +0,0 @@
1
- var sample_DIC = function () {
2
- var dic = {};
3
- dic.tokens = {};
4
-
5
- dic.sample = sample = {};
6
- var sample_all = ["smiled", "frowned", "grimaced", "grinned evilly", "grinned cheekily", "sneered", "puckered", "smirked", "snarled", "snickered", "pouted"];
7
- dic.sample.all=[].concat(sample_all);
8
- dic.tokens.push("sample");
9
- return dic;
10
- };
11
- module.exports=sample_DIC;
@@ -1,21 +0,0 @@
1
- dic.amount = amount={};
2
- var amount_all = ["a few", "a bunch of", "some", "many more"];
3
- dic.amount.all = amount_all;
4
- dic.tokens.push("amount");
5
-
6
- dic.faced = faced={};
7
- var faced_all = ["smiled", "frowned", "grimaced", "grinned evilly", "grinned cheekily", "sneered", "puckered", "smirked", "snarled", "snickered", "pouted"];
8
- dic.faced.all = faced_all;
9
- dic.tokens.push("faced");
10
-
11
- dic.pron_female = pron_female={};
12
- var pron_female_all = ["her/she/herself/her/hers"];
13
- dic.pron_female.all = pron_female_all;
14
- dic.tokens.push("pron_female");
15
-
16
- dic.alien = {};
17
- var alien_race = ["Badoon/Badoons","Brood/The Broods","Celestials/The Celestials","Kree/The Kree"];
18
- dic.alien.all = alien_race;
19
- dic.alien.races = alien_race;
20
- dic.alien.subs=["plural"];
21
- dic.tokens.push("alien");