Skip to content

Commit cb5e39d

Browse files
committed
Convert module code into TypeScript
1 parent de5112d commit cb5e39d

26 files changed

+361
-438
lines changed

index.ts

+24-26
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
1-
module.exports = {
2-
b1ff: require('./src/b1ff')['b1ff'],
3-
censor: require('./src/censor')['censor'],
4-
chef: require('./src/chef')['chef'],
5-
cockney: require('./src/cockney')['cockney'],
6-
eleet: require('./src/eleet')['eleet'],
7-
fudd: require('./src/fudd')['fudd'],
8-
jethro: require('./src/jethro')['jethro'],
9-
jibberish: require('./src/jibberish')['jibberish'],
10-
ken: require('./src/ken')['ken'],
11-
kenny: require('./src/kenny')['kenny'],
12-
klaus: require('./src/klaus')['klaus'],
13-
ky00te: require('./src/ky00te')['ky00te'],
14-
LOLCAT: require('./src/LOLCAT')['LOLCAT'],
15-
nethackify: require('./src/nethackify')['nethackify'],
16-
newspeak: require('./src/newspeak')['newspeak'],
17-
nyc: require('./src/nyc')['nyc'],
18-
pirate: require('./src/pirate')['pirate'],
19-
rasterman: require('./src/rasterman')['rasterman'],
20-
scottish: require('./src/scottish')['scottish'],
21-
scramble: require('./src/scramble')['scramble'],
22-
spammer: require('./src/spammer')['spammer'],
23-
studly: require('./src/studly')['studly'],
24-
uniencode: require('./src/uniencode')['uniencode'],
25-
upsidedown: require('./src/upsidedown')['upsidedown'],
26-
};
1+
export { b1ff } from './src/b1ff';
2+
export { censor } from './src/censor';
3+
export { chef } from './src/chef';
4+
export { cockney } from './src/cockney';
5+
export { eleet } from './src/eleet';
6+
export { fudd } from './src/fudd';
7+
export { jethro } from './src/jethro';
8+
export { jibberish } from './src/jibberish';
9+
export { ken } from './src/ken';
10+
export { kenny } from './src/kenny';
11+
export { klaus } from './src/klaus';
12+
export { ky00te } from './src/ky00te';
13+
export { LOLCAT } from './src/LOLCAT';
14+
export { nethackify } from './src/nethackify';
15+
export { newspeak } from './src/newspeak';
16+
export { nyc } from './src/nyc';
17+
export { pirate } from './src/pirate';
18+
export { rasterman } from './src/rasterman';
19+
export { scottish } from './src/scottish';
20+
export { scramble } from './src/scramble';
21+
export { spammer } from './src/spammer';
22+
export { studly } from './src/studly';
23+
export { uniencode } from './src/uniencode';
24+
export { upsidedown } from './src/upsidedown';

src/LOLCAT.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @author Aaron Wells
99
*/
1010

11-
function LOLCAT(initialString) {
11+
export function LOLCAT(initialString: string): string {
1212
return (
1313
initialString
1414
.toLowerCase()
@@ -84,5 +84,3 @@ function LOLCAT(initialString) {
8484
.toUpperCase()
8585
);
8686
}
87-
88-
module.exports = { LOLCAT };

src/b1ff.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
* @license GPL-2+
66
* @author Aaron Wells
77
*/
8-
9-
const { getRandFn } = require('./lib.js');
8+
import { getRandFn } from './lib';
109

1110
// # I use an array, not a hash. because order is important.
12-
function b1ff(initialString) {
11+
export function b1ff(initialString: string): string {
1312
const rand = getRandFn();
1413
return initialString
1514
.split('\n')
@@ -72,7 +71,7 @@ function b1ff(initialString) {
7271
// I guess b1ff doesn't use two spaces after his periods. How 90s-rude!
7372
.replace(/\. /g, '. ')
7473
.replace(/\./g, () => {
75-
switch (rand() % 3) {
74+
switch ((rand() % 3) as 0 | 1 | 2) {
7675
case 0:
7776
return '.';
7877
case 1:

src/censor.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @author Aaron Wells
77
*/
88

9-
const tr = require('./lib').tr;
9+
import { tr } from './lib';
1010

1111
/**
1212
* List of regexes to censor, encoded in ROT-13 so this program itself won't
@@ -161,7 +161,10 @@ const censorRE = new RegExp(`\\b(${censorCombined})(ed)?`, 'ig');
161161
* @param {string[]} [additionalWords]
162162
* @returns {string};
163163
*/
164-
function censor(originalString, additionalWords) {
164+
export function censor(
165+
originalString: string,
166+
additionalWords?: string[]
167+
): string {
165168
const censoredString = originalString.replace(censorRE, 'CENSORED');
166169
if (additionalWords) {
167170
return censoredString.replace(
@@ -172,5 +175,3 @@ function censor(originalString, additionalWords) {
172175
return censoredString;
173176
}
174177
}
175-
176-
module.exports = { censor };

src/chef.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
* @param {string} initialString
1313
* @returns {string}
1414
*/
15-
function chef(initialString) {
15+
export function chef(initialString: string): string {
1616
// This whole function will be just a chain of
1717
// string.replace() calls.
1818
return (
1919
initialString
2020

2121
// // Change 'e' at the end of a word to 'e-a', but don't mess with the word
2222
// // "the".
23-
.replace(/(\w+)e(\b)/g, function (whole, p1, p2) {
23+
.replace(/(\w+)e(\b)/g, function (whole: string, p1: string, p2: string) {
2424
if (p1.toLowerCase() === 'th') {
2525
return whole;
2626
} else {
@@ -56,7 +56,7 @@ function chef(initialString) {
5656
.replace(/tiun/g, 'shun') // this actually has the effect of changing "tion" to "shun".
5757
.replace(/the/g, 'zee')
5858
.replace(/The/g, 'Zee')
59-
.replace(/[vVwW]/g, (match) => {
59+
.replace(/[vVwW]/g, (match: string) => {
6060
switch (match) {
6161
case 'v':
6262
return 'f';
@@ -65,6 +65,7 @@ function chef(initialString) {
6565
case 'w':
6666
return 'v';
6767
case 'W':
68+
default:
6869
return 'V';
6970
}
7071
})
@@ -89,5 +90,3 @@ function chef(initialString) {
8990
.replace(/([.?!])$/gm, '$1\nBork Bork Bork!')
9091
);
9192
}
92-
93-
module.exports = { chef };

src/cockney.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
* @author Aaron Wells
1010
*/
1111

12-
const { getRandFn } = require('./lib.js');
12+
import { getRandFn } from './lib';
1313

1414
/**
1515
*
1616
*
1717
* @param {string} initialString
1818
* @return {string}
1919
*/
20-
function cockney(initialString) {
20+
export function cockney(initialString: string): string {
2121
const I_rand = getRandFn();
2222
function I() {
2323
if (I_rand() % 5 === 1) {
@@ -29,7 +29,7 @@ function cockney(initialString) {
2929

3030
let b_count = 0;
3131
let b_which = 0;
32-
function bloody() {
32+
function bloody(): string {
3333
if (b_count++ % 2 === 0) {
3434
switch (b_which++ % 4) {
3535
case 0:
@@ -55,7 +55,7 @@ function cockney(initialString) {
5555
* @param {string} fullstring
5656
* @returns
5757
*/
58-
function dintI(offset, fullstring) {
58+
function dintI(offset: number, fullstring: string) {
5959
let sentence = fullstring
6060
.substr(0, offset + 1)
6161
.match(/(?:^|(?:\w|')[.?])([^.?]+)$/);
@@ -64,8 +64,7 @@ function cockney(initialString) {
6464
let sentenceStr = sentence[1].trim();
6565

6666
// Find out if the sentence contains an "I" phrase
67-
/** @type {false | string} */
68-
let iOrWe = false;
67+
let iOrWe: false | string = false;
6968
const indexOfI = sentenceStr.search(/\b(I|Oy) did\b/);
7069
if (indexOfI !== -1) {
7170
iOrWe = 'I';
@@ -205,5 +204,3 @@ function cockney(initialString) {
205204
)
206205
);
207206
}
208-
209-
module.exports = { cockney };

src/eleet.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
* @license GPL-2+
88
* @author Aaron Wells
99
*/
10-
const { sameCapReplacer, tr } = require('./lib');
10+
import { sameCapReplacer, tr } from './lib';
1111

1212
let from = 'abcdefghijklmnopqrstuvwxyz';
1313
from = from + from.toUpperCase();
1414
let to = '4bcd3fgh1jklmn0pqr5tuvwxyz';
1515
to = to + to.toUpperCase();
1616

17-
function eleet(initialString) {
17+
export function eleet(initialString: string): string {
1818
return tr(
1919
initialString
2020
.replace(/porn/g, sameCapReplacer('pr0n'))
@@ -32,5 +32,3 @@ function eleet(initialString) {
3232
// #s:w:\\/\\/:ig;
3333
// #s:v:\\/:ig;
3434
// #s:x:><:ig;
35-
36-
module.exports = { eleet };

src/fudd.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @author Aaron Wells
77
*/
88

9-
function fudd(initialString) {
9+
export function fudd(initialString: string): string {
1010
return initialString
1111
.replace(/[rl]/g, 'w')
1212
.replace(/qu/g, 'qw')
@@ -21,5 +21,3 @@ function fudd(initialString) {
2121
.replace(/Th/g, 'D')
2222
.replace(/N\./g, 'N, uh-hah-hah-hah.');
2323
}
24-
25-
module.exports = { fudd };

src/jethro.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const sameCapReplacer = require('./lib').sameCapReplacer;
1212
* @param {string} originalString
1313
* @returns {string}
1414
*/
15-
function jethro(originalString) {
15+
export function jethro(originalString: string): string {
1616
return (
1717
originalString
1818
// {SW}[Gg]reetings{EW} |
@@ -423,5 +423,3 @@ function jethro(originalString) {
423423
.replace(/!(?=(\s|$))/gm, '. Ye DAWGies!!!')
424424
);
425425
}
426-
427-
module.exports = { jethro };

src/jibberish.ts

+18-19
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,31 @@
55
* @license GPL-2+
66
* @author Aaron Wells
77
*/
8-
const { getRandFn } = require('./lib');
8+
import { getRandFn } from './lib';
99

10-
const { eleet } = require('./eleet');
11-
const { b1ff } = require('./b1ff');
12-
const { chef } = require('./chef');
13-
const { jethro } = require('./jethro');
14-
const { upsidedown } = require('./upsidedown');
15-
const { klaus } = require('./klaus');
16-
const { cockney } = require('./cockney');
17-
const { pirate } = require('./pirate');
18-
const { nyc } = require('./nyc');
19-
const { ken } = require('./ken');
20-
const { ky00te } = require('./ky00te');
21-
const { rasterman } = require('./rasterman');
22-
const { newspeak } = require('./newspeak');
23-
const { studly } = require('./studly');
24-
const { censor } = require('./censor');
25-
const { spammer } = require('./spammer');
10+
import { eleet } from './eleet';
11+
import { b1ff } from './b1ff';
12+
import { chef } from './chef';
13+
import { jethro } from './jethro';
14+
import { upsidedown } from './upsidedown';
15+
import { klaus } from './klaus';
16+
import { cockney } from './cockney';
17+
import { pirate } from './pirate';
18+
import { nyc } from './nyc';
19+
import { ken } from './ken';
20+
import { ky00te } from './ky00te';
21+
import { rasterman } from './rasterman';
22+
import { newspeak } from './newspeak';
23+
import { studly } from './studly';
24+
import { censor } from './censor';
25+
import { spammer } from './spammer';
2626

2727
/**
2828
*
2929
* @param {string} originalString
3030
* @returns {string}
3131
*/
32-
function jibberish(originalString) {
32+
export function jibberish(originalString: string): string {
3333
const rand = getRandFn();
3434

3535
const all = [
@@ -74,4 +74,3 @@ function jibberish(originalString) {
7474
// # But you have to ask yourself: how important is it to optimize
7575
// # the generation of jibberish?
7676
}
77-
module.exports = { jibberish };

0 commit comments

Comments
 (0)