git @ Cat's Eye Technologies Lexeduct / 3662a7d
Random up/downcase, rudimentary test suite, params/desc exports. Chris Pressey 6 years ago
6 changed file(s) with 63 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
22 return function(str, state) {
33 return str;
44 };
5 }
5 },
6 parameters: {},
7 description: "Identity transformation: makes no changes"
68 };
77 }
88 return s;
99 };
10 }
10 },
11 parameters: {
12 'chars': "The set of characters to select from"
13 },
14 description: "Insert a randomly-selected character after each character"
1115 };
00 module.exports = {
11 makeTransformer: function(cfg) {
2 cfg.chance = parseInt(cfg.chance || "100", 10);
23 return function(str, state) {
3 return str.toLowerCase();
4 var s = "";
5 for (var i = 0; i < str.length; i++) {
6 var c = str.charAt(i);
7 if (Math.floor(Math.random() * 100) < cfg.chance) {
8 c = c.toLowerCase();
9 }
10 s += c;
11 }
12 return s;
413 };
5 }
14 },
15 parameters: {
16 'chance': "Probability (0-100) of applying to any individual character"
17 },
18 description: "Convert characters to lowercase"
619 };
22 return function(str, state) {
33 var s = "";
44 for (var i = 0; i < str.length; i++) {
5 if (cfg.chars.lastIndexOf(str.charAt(i)) === -1) {
5 if (cfg.chars.indexOf(str.charAt(i)) === -1) {
66 s += c;
77 }
88 }
99 return s;
1010 };
11 }
11 },
12 parameters: {
13 'chars': "The set of characters to select from"
14 },
15 description: "Remove all occurrences of the specified characters"
1216 };
00 module.exports = {
11 makeTransformer: function(cfg) {
2 cfg.chance = parseInt(cfg.chance || "100", 10);
23 return function(str, state) {
3 return str.toUpperCase();
4 var s = "";
5 for (var i = 0; i < str.length; i++) {
6 var c = str.charAt(i);
7 if (Math.floor(Math.random() * 100) < cfg.chance) {
8 c = c.toUpperCase();
9 }
10 s += c;
11 }
12 return s;
413 };
5 }
14 },
15 parameters: {
16 'chance': "Probability (0-100) of applying to any individual character"
17 },
18 description: "Convert characters to uppercase"
619 };
0 #!/bin/sh
1
2 assert() {
3 COMMAND=$1
4 EXPECTED=$2
5 RESULT=`eval $COMMAND`
6 if [ "x$RESULT" != "x$EXPECTED" ]; then
7 echo "FAIL : $COMMAND"
8 echo "Expected: $EXPECTED"
9 echo "Got : $RESULT"
10 exit 1
11 fi
12 }
13
14 assert "echo 'Hello' | src/lexeduct.js upper" "HELLO"
15 assert "echo 'Hello' | src/lexeduct.js lower" "hello"
16 assert "echo 'Hello' | src/lexeduct.js chars=' ' insert-chars" "H e l l o "
17 assert "echo 'Hello' | src/lexeduct.js chars='a' insert-chars upper" "HAEALALAOA"
18 assert "echo 'Hello' | src/lexeduct.js upper chars='a' insert-chars" "HaEaLaLaOa"