File size: 2,054 Bytes
ae4627d | 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 | var vowels = "aeiouyæøåAEIOUYÆØÅ";
var vowels_array = {};
var consonants = "bcdfghjklmnpqrstvwxzBCDFGHJKLMNPQRSTVQWXZ";
var consonants_array = {};
for(var pos=0;pos<vowels.length;pos++) {
vowels_array[vowels.substr(pos, 1)] = 1;
}
for(var pos=0;pos<consonants.length;pos++) {
consonants_array[consonants.substr(pos, 1)] = 1;
}
function prototypeString(funcs) {
for(var func in funcs) {
Object.defineProperty(String.prototype, func,
{
value: function() {
return func(this.toString())
},
enumerable: false
});
}
}
function splitIntoWords(text, include) {
if (include) {
return text.split(/([\s,!.-]+)/);
}
return text.split(/[\s,!.-]+/);
}
function shuffle(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
return array;
}
function isVowel(char) {
if (vowels_array[char]) {
return true;
}
return false;
}
function isConsonant(char) {
if (consonant_array[char]) {
return true;
}
return false;
}
function isUpperCase(char) {
if (char==char.toUpperCase()) {
return true;
}
return false;
}
function isLowerCase(char) {
if (char==char.toLowerCase()) {
return true;
}
return false;
}
function firstToLowerCase(line) {
return line.charAt(0).toLowerCase()+line.substr(1);
}
function firstToUpperCase(line) {
return line.charAt(0).toUpperCase()+line.substr(1);
}
function consonants() {
return consonants;
}
function vowels() {
return vowels;
}
exports.splitIntoWords = splitIntoWords;
exports.shuffle = shuffle;
exports.isVowel = isVowel;
exports.isConsonant = isConsonant;
exports.isUpperCase = isUpperCase;
exports.isLowerCase = isLowerCase;
exports.firstToLowerCase = firstToLowerCase;
exports.firstToUpperCase = firstToUpperCase;
exports.consonants = consonants;
exports.vowels = vowels;
exports.prototypeString = prototypeString; |