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,162 +0,0 @@
1
- (function () {
2
- var arrayMethods = {
3
- /** Returns a shallow copy of this array */
4
- copy: function () { return this.slice(0); },
5
-
6
- /** Returns true if this array contains 'element', returns false otherwise */
7
- contains: function (element) { return this.indexOf(element) >= 0; },
8
-
9
- /** Returns a copy of this array, removing the elements 'from' index 'to' index within it */
10
- remove: function (from, to) {
11
- var res = [];
12
- var i = 0, j = 0;
13
- for (i = 0; i < from; i++) {
14
- res[i] = this[i];
15
- }
16
- j = i;
17
- for (i = to; i < this.length; i++) {
18
- res[j++] = this[i];
19
- }
20
- return res;
21
- },
22
-
23
- /** Returns a copy of this array, rotated 'n' places, counterclockwise if 'n' is positive, clockwise otherwise*/
24
- rotate: function (n) {
25
- if (!n) return this.slice(0);
26
- var length = this.length;
27
- var res = new Array(length);
28
- var thisIndex = (n > 0) ? n : length + n, i = 0, j = 0;
29
- for (i = thisIndex; i < length; i++) {
30
- res[j++] = this[i];
31
- }
32
- for (i = 0; i < thisIndex; i++) {
33
- res[j++] = this[i];
34
- }
35
- return res;
36
- },
37
-
38
- /**
39
- * Returns a copy of this array, removing but
40
- * the first 'n' elements from it
41
- * assumes n=1 when called with no arguments.
42
- */
43
- skipFirst: function (n) {
44
- if (n === 'undefined') n = 1;
45
- return this.slice(n);
46
- },
47
-
48
- /**
49
- * Returns a copy of this array, removing
50
- * but the last 'n' elements from it
51
- * assumes n=1 when called with no arguments.
52
- */
53
- skipLast: function (n) {
54
- if (n === 'undefined') n = 1;
55
- if (n > this.length) return [];
56
- return this.slice(0, this.length - n);
57
- },
58
-
59
- /**
60
- * Returns a copy of this array,
61
- * sorting its elements randomly
62
- */
63
-
64
- shuffle: function () {
65
- array = this.splice(0);
66
- var m = array.length, t, i;
67
-
68
- // While there remain elements to shuffle…
69
- while (m) {
70
-
71
- // Pick a remaining element…
72
- i = Math.floor(Math.random() * m--);
73
-
74
- // And swap it with the current element.
75
- t = array[m];
76
- array[m] = array[i];
77
- array[i] = t;
78
- }
79
-
80
- return array;
81
- },
82
-
83
- /**
84
- * Returns an unique array
85
- */
86
- makeUnique: function(){
87
- var u = {}, a = [];
88
- for(var i = 0, l = this.length; i < l; ++i){
89
- if(u.hasOwnProperty(this[i])) {
90
- continue;
91
- }
92
- a.push(this[i]);
93
- u[this[i]] = 1;
94
- }
95
- return a;
96
- },
97
-
98
- /**
99
- * Returns this associative array length
100
- */
101
- getAssociativeArrayLength: function () {
102
- return this.length;
103
- },
104
-
105
- /**
106
- * Returns a copy of this array that contains the difference
107
- * between source array and 'array'
108
- */
109
- difference: function (array) {
110
- var filterFunc = filterOnOtherArray_diff.bind(array);
111
- return this.filter(filterFunc);
112
- },
113
-
114
- /**
115
- * Returns a copy of this array that contains the
116
- * intersection between source array and 'array'
117
- */
118
- intersection: function (array) {
119
- var filterFunc = filterOnOtherArray_inter.bind(array);
120
- return this.filter(filterFunc);
121
- },
122
-
123
- /**
124
- * Returns a copy of this array that contains the union
125
- * between source array with 'array', removing duplicates
126
- * ! fails with a sparse array !
127
- */
128
- union: function (array) {
129
- var obj = {}, res = [], i = 0, k = 0;
130
- for (i = 0; i < this.length; i++) {
131
- obj[this[i]] = this[i];
132
- }
133
- for (i = 0; i < array.length; i++) {
134
- obj[array[i]] = array[i];
135
- }
136
- for (k in obj) {
137
- res.push(obj[k]);
138
- }
139
- return res;
140
- }
141
- };
142
-
143
- // let's install those methods on the prototype
144
- for (var newMethodName in arrayMethods) {
145
- installFunction(newMethodName, arrayMethods[newMethodName]);
146
- }
147
-
148
- function installFunction(name, fn) {
149
- if (Array.prototype[name]) throw ('Array method ' + name + '() already defined.');
150
- Object.defineProperty(Array.prototype, name, {
151
- value: fn
152
- });
153
- }
154
-
155
- function filterOnOtherArray_diff(arr, i) {
156
- return (arr.indexOf(i) < 0);
157
- }
158
-
159
- function filterOnOtherArray_inter(arr, i) {
160
- return (arr.indexOf(i) >= 0);
161
- }
162
- })();
@@ -1,60 +0,0 @@
1
-
2
- var braceParser = function (input, group, reps, sep, dic) {
3
- dic = dic || require("./en_US");
4
- var tempRes = "", matchIndex = 1;
5
- var result = input, matches = [], token, replacement = [], regex;
6
- matchIndex = 0;
7
- group = group.replace("}", "");
8
- group = group.replace("{", "");
9
- var repetitions=reps.pop();
10
- var separator=sep.pop();
11
- var newGroup = '';
12
-
13
-
14
- // Check for shorthand codes
15
- //[rep:10][sep:\N]{\C}
16
- regex = /\\\w+/g;
17
- i = 0;
18
- var replaceGroup='';
19
- while (matches = regex.exec(group)) {
20
- var groupCopy = group;
21
- while (i < repetitions) {
22
- if(matches[0]==="\\C"){ replaceGroup+=require("./randomString")(1); }
23
- i++;
24
- }
25
-
26
- groupCopy=groupCopy.replace("\\C", replaceGroup );
27
- if("undefined" != typeof separator){
28
- if (separator.toLowerCase() === "n") groupCopy += separator.replace("n", "\n");
29
- else if (separator.toLowerCase() === "s") groupCopy += separator.replace("s", " ");
30
- else groupCopy += separator;
31
- }
32
- return groupCopy;
33
-
34
- }
35
-
36
- // Check for token patterns
37
- regex = /<(.*?)>/g;
38
- i = 0;
39
- while (i < repetitions) {
40
- while (matches = regex.exec(group)) {
41
- groupCopy = group;
42
- re = new RegExp("\\w+", "g");
43
- token = matches[1].match(re);
44
- if (dic().tokens.indexOf(token[0]) != -1) {
45
- if("undefined" != typeof separator){
46
- if (separator === "n") groupCopy += separator.replace("n", "\n");
47
- else if (separator === "s") groupCopy += separator.replace("s", " ");
48
- else groupCopy += separator;
49
- }
50
- }
51
- }
52
- newGroup += "undefined" == typeof groupCopy ? "" : groupCopy;
53
-
54
- i++;
55
- }
56
- //console.log(group);
57
- return "undefined" != typeof newGroup ? newGroup : group;
58
- };
59
-
60
- module.exports = braceParser;
@@ -1,19 +0,0 @@
1
-
2
- var capitalize = function (s,_case) {
3
- if(_case==="upper")
4
- return s.toUpperCase();
5
- else if(_case==="lower")
6
- return s.toLowerCase();
7
- else if(_case==="word")
8
- return s.toWordCase();
9
- else if(_case==="title")
10
- return s.toTitleCase();
11
- else if(_case==="sentence")
12
- return s.toSentenceCase();
13
- else if(_case==="none")
14
- return s;
15
- else
16
- return s[0].toUpperCase() + s.slice(1); //default && first
17
- };
18
-
19
- module.exports = capitalize;