git @ Cat's Eye Technologies Lexeduct / 84ed810
Add a repeat-chars filter. Chris Pressey 10 years ago
1 changed file(s) with 24 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 module.exports = {
1 makeTransformer: function(cfg) {
2 cfg.count = parseInt(cfg.count || "1", 10);
3 cfg.chance = parseInt(cfg.chance || "100", 10);
4 return function(str, state) {
5 var s = "";
6 for (var i = 0; i < str.length; i++) {
7 var c = str.charAt(i);
8 s += c;
9 if (Math.floor(Math.random() * 100) < cfg.chance) {
10 for (var j = 0; j < cfg.count; j++) {
11 s += c;
12 }
13 }
14 }
15 return s;
16 };
17 },
18 parameters: {
19 'count': ["How many extra occurrences of the character to insert", "1"],
20 'chance': ["Probability (0-100) of applying to any individual character", "100"]
21 },
22 description: "Insert extra copies of the character after each character"
23 };