-
Notifications
You must be signed in to change notification settings - Fork 5
/
blah-code.js
117 lines (109 loc) · 2.59 KB
/
blah-code.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
(function (root, factory) {
'use strict';
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define([], function () {
return (root.blahCode = factory());
});
} else if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like enviroments that support module.exports,
// like Node.
module.exports = factory();
} else {
// Browser globals
root.blahCode = factory();
}
})(this, function () {
// UMD Definition above, do not remove this line
// To get to know more about the Universal Module Definition
// visit: https://github.com/umdjs/umd
'use strict';
/**
* Languages object
* @type {Object}
* @property {Array} languages.bleh - Strings of blah which are used to represent a number.
* @private
*/
var languages = {
blah: [
'bleh',
'blah',
'bluh',
'blaah',
'bleeh',
'bluuh',
'blehh',
'blaa',
'blahh',
'blee'
],
ooks: [
'Ook',
'Ook?',
'Ook!',
'Ook?!',
'Ook!?',
'Oook',
'Oook?',
'Oook!',
'Oook?!',
'Oook!?'
]
};
/**
* Encodes normal text.
*
* @param {String} text Normal text.
* @param {String} [language='blah'] - Optional. Defaults to blah. Could be 'ooks' otherwise.
* @return {String} Encoded text
* @public
*/
var encode = function (text, language) {
var output = [];
language = language === undefined ? 'blah' : language;
for (var letter in text) {
if (text.hasOwnProperty(letter)) {
var encoded = [];
var temporary = text[letter].charCodeAt(0).toString().split('');
for (var code in temporary) {
if (temporary.hasOwnProperty(code)) {
encoded.push(languages[language][temporary[code]]);
}
}
output.push(encoded.join(' '));
}
}
return output.join('. ');
};
/**
* Decodes to normal text.
*
* @param {String} text Encoded text.
* @param {String} [language='blah'] - Optional. Defaults to blah. Could be 'ooks' otherwise.
* @return {String} Decoded text
* @public
*/
var decode = function (text, language) {
var output = [];
language = language === undefined ? 'blah' : language;
var encoded = text.split('. ');
for (var char in encoded) {
if (encoded.hasOwnProperty(char)) {
var codes = encoded[char].split(' ');
var character = [];
for (var i in codes) {
if (codes.hasOwnProperty(i)) {
character.push(languages[language].indexOf(codes[i]));
}
}
output.push(String.fromCharCode(character.join('')));
}
}
return output.join('');
};
return {
encode: encode,
decode: decode
};
});