Skip to content
Snippets Groups Projects
Commit 22739795 authored by Pedy's avatar Pedy
Browse files

Prepare the speech modifiers, todo macro

parent 651a55e5
No related branches found
No related tags found
No related merge requests found
......@@ -51,6 +51,11 @@ window.jsEither = function(choices) {
return choices[index];
};
//find an occurrence within given string, supports regex
window.jsStrcount = function(str, search) {
return (str.match(new RegExp(search, "g")) || []).length;
}
//unlike the previous function, this doesn't require strict formatting, accepting a simple string-type var
//splitter can be specified, by default it's :
window.jsSplitr = function(choices, splitter) {
......@@ -66,6 +71,12 @@ window.jsSplitcheck = function() {
}
return n
};
String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.replace(new RegExp(search, 'g'), replacement);
};
//capitalize first letter of a given string
window.jsCapitalize = function(lower) {
return lower.replace(/^\w/, c => c.toUpperCase());
......@@ -103,6 +114,9 @@ return output
//second var is capitalization - 1 will give full caps, 2 will give lowercase, 3 will give random capitalization
//todo - gender division? I mean boys probably moan differently
window.jsMoan = function(mode, capitalization) {
/*check if there are splitters, choose one*/
mode = jsSplitr(mode)
switch(mode) {
case 'rand': case 'r':
......@@ -203,10 +217,7 @@ window.jsCount = function(n) {
default: return n + "th";
}
};
//find an occurrence within given string, supports regex
window.jsStrcount = function(str, search) {
return (str.match(new RegExp(search, "g")) || []).length;
}
//puts an appropriate article to the given string
window.jsArticle = function(str) {
/* exceptions, add on demand */
......@@ -823,4 +834,125 @@ while (true) {
default:
return intToString;
}
};
window.jsintToTally = function(integer) {
var numeralSB = "";
for(var i=0; i<Math.floor(integer/5); i++) {
numeralSB += "<strike>IIII</strike> ";
}
for(var i=0; i<integer%5; i++) {
numeralSB += "I";
}
return numeralSB.toString();
};
window.jsaddStutter = function(sentence, frequency) {
var splitSentence = sentence.split(" ");
var builder = "";
// 1 in "frequency" words are stutters, with a minimum of 1.
var wordsToStutter = Math.floor(splitSentence.length / frequency) + 1;
var offset = 0;
for (var i = 0; i < wordsToStutter; i++) {
offset = jsRandom(frequency);
offset = (i * frequency + offset) >= splitSentence.length ? splitSentence.length - 1 : (i * frequency + offset);
// In case of an accidental comma position? also avoid apostrophe
if (splitSentence[offset].charAt(0) != ',' && splitSentence[offset].charAt(0) != '\'')
splitSentence[offset] = splitSentence[offset].charAt(0) + "-" + splitSentence[offset];
else
if (splitSentence[offset].charAt(0) == ',')
splitSentence[offset] = "," + splitSentence[offset].charAt(1); //+ "-" + splitSentence[offset].substring(1, splitSentence[offset].length + 1)
else
splitSentence[offset] = "'" + splitSentence[offset].charAt(1) + "-" + splitSentence[offset].substring(1, splitSentence[offset].length + 1);
for (var j = 0; j < frequency && ((i * frequency + j) < splitSentence.length); j++)
builder += splitSentence[i * frequency + j] + " "
}
//remove the trailing space
return builder.substring(0, builder.length-1).toString()
};
const endOfSentence = new RegExp('[,.!?]', 'g');
/*
* Determine whether a given string contains sentence-ending punctuation.
* @param text text to check whether
* @return boolean whether the text contains a period, exclamation or question mark
*/
window.jsisEndOfSentence = function(text) {
if(!text.length) {
return false;
}
return Boolean((text.substring(text.length-1).match(endOfSentence) || []).length);
};
window.jsinsertIntoSentences = function(sentence, frequency, inserts, middle) {
var splitSentence = sentence.split(" ");
//utilitiesStringBuilder.setLength(0);
var builder = "";
// 1 in "frequency" words have an insert, with a minimum of 1.
var wordsToInsert = Math.floor(splitSentence.length / frequency + 1)
var offset = 0;
for (var i = 0; i < wordsToInsert; i++) {
var offset = Math.min(i * frequency + jsRandom(frequency), splitSentence.length - 1);
var insert = inserts[jsRandom(inserts.length-1)];
// If wanted, ensure not inserting to the start or end of a sentence
if (offset >= splitSentence.length -1 || jsisEndOfSentence(splitSentence[offset])) {
if (middle) {
// Skip if at end of string or sentence
continue;
}
// Add a full stop to the insert, creating its own sentence
insert += ".";
}
var len = splitSentence[offset].length;
// Remove duplicate commas if selected position ends with one and insert has one
if (insert.trim().charAt(0) == ',' && splitSentence[offset].charAt(len -1) == ',') {
splitSentence[offset] = splitSentence[offset].substring(0, len-1);
}
// Append the insert to this word:
splitSentence[offset] = splitSentence[offset] + insert;
}
//for (var word : splitSentence)
for (var i = 0; i < splitSentence.length; i++){
builder += splitSentence[i] + " ";
}
return builder.substring(0, builder.length-1).toString()
};
var sexSounds = [ " ~"+jsMoan("l")+"!~", " ~"+jsMoan("l")+"!~"," ~"+jsMoan("l")+"!~"," ~"+jsMoan("l")+"!~", " ~"+jsMoan("m")+"!~", " ~"+jsMoan("m")+"!~"," ~"+jsMoan("m")+"!~"," ~"+jsMoan("m")+"!~"];
window.jsaddSexSounds = function(sentence, frequency) {
return jsinsertIntoSentences(sentence, frequency, sexSounds, true);
};
var muffledSounds = [ " ~Mrph~", " ~Mmm~", " ~Mrmm~" ];
window.jsaddMuffle = function(sentence, frequency) {
return jsinsertIntoSentences(sentence, frequency, muffledSounds, true);
};
var drunkSounds = [ " ~Hic!~" ];
window.jsaddDrunkSlur = function(sentence, frequency) {
/* diploma man style here, maybe there's a better method?*/
var sentence = sentence.replaceAll("Hi", "Heeey")
var sentence = sentence.replaceAll("yes", "yesh")
var sentence = sentence.replaceAll("is", "ish")
var sentence = sentence.replaceAll("ss", "ssh")
var sentence = sentence.replaceAll("So", "Sho")
var sentence = sentence.replaceAll("so", "sho");
return jsinsertIntoSentences(sentence, frequency, drunkSounds, false)
};
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment