git @ Cat's Eye Technologies Lexeduct / 9609e4c
Add shuffle-chars and shuffle-words transformers. Chris Pressey 6 years ago
2 changed file(s) with 33 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 module.exports = {
1 makeTransformer: function(cfg) {
2 return function(str, state) {
3 var s = "";
4 var len = str.length;
5 for (var i = 0; i < len; i++) {
6 var index = Math.floor(Math.random() * str.length);
7 s += str.charAt(index);
8 str = str.slice(0, index) + str.slice(index + 1, str.length);
9 }
10 return s;
11 };
12 },
13 parameters: {},
14 description: "Randomly re-order all characters found"
15 };
0 module.exports = {
1 makeTransformer: function(cfg) {
2 return function(str, state) {
3 var words = str.split(/\s+/);
4 var acc = [];
5 var len = words.length;
6 for (var i = 0; i < len; i++) {
7 var index = Math.floor(Math.random() * words.length);
8 acc.push(words[index]);
9 words = words.slice(0, index).concat(words.slice(index + 1, words.length));
10 }
11 return acc.join(' ');
12 };
13 },
14 parameters: {},
15 description: "Randomly re-order all words found"
16 };