text: function isVowel(t){var e=t.toLowerCase();return"a"===e||"e"===e||"i"===e||"o"===e||"u"===e}function isAlphaNum(t){return t>="a"&&t<="z"||t>="A"&&t<="Z"||t>="0"&&t<="9"}function escapeRegExp(t){return t.replace(/([.*+?^=!:${}()|\[\]\/\\])/g,"\\$1")}var tracery=function(){function t(t,e){this.node=t;var s=e.split(":");this.target=s[0],1===s.length?this.type=2:(this.rule=s[1],"POP"===this.rule?this.type=1:this.type=0)}function e(t,e){this.raw=e,this.grammar=t,this.falloff=1,Array.isArray(e)?this.defaultRules=e:("string"==typeof e||e instanceof String)&&(this.defaultRules=[e])}function s(t,e){for(var s,i,a=t.length;0!==a;)i=Math.floor(r()*a),a-=1,s=t[a],t[a]=t[i],t[i]=s;return t}var r=Math.random,i=function(t){r=t},a=function(t,e,s){this.errors=[],void 0===s.raw&&(this.errors.push("Empty input for node"),s.raw=""),t instanceof tracery.Grammar?(this.grammar=t,this.parent=null,this.depth=0,this.childIndex=0):(this.grammar=t.grammar,this.parent=t,this.depth=t.depth+1,this.childIndex=e),this.raw=s.raw,this.type=s.type,this.isExpanded=!1,this.grammar||console.warn("No grammar specified for this node",this)};a.prototype.toString=function(){return"Node('"+this.raw+"' "+this.type+" d:"+this.depth+")"},a.prototype.expandChildren=function(t,e){if(this.children=[],this.finishedText="",this.childRule=t,void 0!==this.childRule){var s=tracery.parse(t);s.errors.length>0&&(this.errors=this.errors.concat(s.errors));for(var r=0;r<s.length;r++)this.children[r]=new a(this,r,s[r]),e||this.children[r].expand(e),this.finishedText+=this.children[r].finishedText}else this.errors.push("No child rule provided, can't expand children"),console.warn("No child rule provided, can't expand children")},a.prototype.expand=function(e){if(!this.isExpanded)switch(this.isExpanded=!0,this.expansionErrors=[],this.type){case-1:this.expandChildren(this.raw,e);break;case 0:this.finishedText=this.raw;break;case 1:this.preactions=[],this.postactions=[];var s=tracery.parseTag(this.raw);this.symbol=s.symbol,this.modifiers=s.modifiers;for(var r=0;r<s.preactions.length;r++)this.preactions[r]=new t(this,s.preactions[r].raw);for(var r=0;r<s.postactions.length;r++);for(var r=0;r<this.preactions.length;r++)0===this.preactions[r].type&&this.postactions.push(this.preactions[r].createUndo());for(var r=0;r<this.preactions.length;r++)this.preactions[r].activate();this.finishedText=this.raw;var i=this.grammar.selectRule(this.symbol,this,this.errors);this.expandChildren(i,e);for(var r=0;r<this.modifiers.length;r++){var a=this.modifiers[r],n=[];if(a.indexOf("(")>0){var h=/\(([^)]+)\)/,o=h.exec(this.modifiers[r]);if(!o||o.length<2);else{var n=o[1].split(",");a=this.modifiers[r].substring(0,a.indexOf("("))}}var l=this.grammar.modifiers[a];l?this.finishedText=l(this.finishedText,n):(this.errors.push("Missing modifier "+a),this.finishedText+="((."+a+"))")}for(var r=0;r<this.postactions.length;r++)this.postactions[r].activate();break;case 2:this.action=new t(this,this.raw),this.action.activate(),this.finishedText=""}},a.prototype.clearEscapeChars=function(){this.finishedText=this.finishedText.replace(/\\\\/g,"DOUBLEBACKSLASH").replace(/\\/g,"").replace(/DOUBLEBACKSLASH/g,"\\")},t.prototype.createUndo=function(){return 0===this.type?new t(this.node,this.target+":POP"):null},t.prototype.activate=function(){var t=this.node.grammar;switch(this.type){case 0:this.ruleSections=this.rule.split(","),this.finishedRules=[],this.ruleNodes=[];for(var e=0;e<this.ruleSections.length;e++){var s=new a(t,0,{type:-1,raw:this.ruleSections[e]});s.expand(),this.finishedRules.push(s.finishedText)}t.pushRules(this.target,this.finishedRules,this);break;case 1:t.popRules(this.target);break;case 2:t.flatten(this.target,!0)}},t.prototype.toText=function(){switch(this.type){case 0:return this.target+":"+this.rule;case 1:return this.target+":POP";case 2:return"((some function))";default:return"((Unknown Action))"}},e.prototype.selectRule=function(t){if(this.conditionalRule){var e=this.grammar.expand(this.conditionalRule,!0);if(this.conditionalValues[e]){var i=this.conditionalValues[e].selectRule(t);if(null!==i&&void 0!==i)return i}}if(this.ranking)for(var a=0;a<this.ranking.length;a++){var i=this.ranking.selectRule();if(null!==i&&void 0!==i)return i}if(void 0!==this.defaultRules){var n=0,h=this.distribution;switch(h||(h=this.grammar.distribution),h){case"shuffle":this.shuffledDeck&&0!==this.shuffledDeck.length||(this.shuffledDeck=s(Array.apply(null,{length:this.defaultRules.length}).map(Number.call,Number),this.falloff)),n=this.shuffledDeck.pop();break;case"weighted":t.push("Weighted distribution not yet implemented");break;case"falloff":t.push("Falloff distribution not yet implemented");break;default:n=Math.floor(Math.pow(r(),this.falloff)*this.defaultRules.length)}return this.defaultUses||(this.defaultUses=[]),this.defaultUses[n]=++this.defaultUses[n]||1,this.defaultRules[n]}return t.push("No default rules defined for "+this),null},e.prototype.clearState=function(){this.defaultUses&&(this.defaultUses=[])};var n=function(t,s,r){this.key=s,this.grammar=t,this.rawRules=r,this.baseRules=new e(this.grammar,r),this.clearState()};n.prototype.clearState=function(){this.stack=[this.baseRules],this.uses=[],this.baseRules.clearState()},n.prototype.pushRules=function(t){var s=new e(this.grammar,t);this.stack.push(s)},n.prototype.popRules=function(){this.stack.pop()},n.prototype.selectRule=function(t,e){return this.uses.push({node:t}),0===this.stack.length?(e.push("The rule stack for '"+this.key+"' is empty, too many pops?"),"(("+this.key+"))"):this.stack[this.stack.length-1].selectRule()},n.prototype.getActiveRules=function(){return 0===this.stack.length?null:this.stack[this.stack.length-1].selectRule()},n.prototype.rulesToJSON=function(){return JSON.stringify(this.rawRules)};var h=function(t,e){this.modifiers={},this.loadFromRawObj(t)};return h.prototype.clearState=function(){for(var t=Object.keys(this.symbols),e=0;e<t.length;e++)this.symbols[t[e]].clearState()},h.prototype.addModifiers=function(t){for(var e in t)t.hasOwnProperty(e)&&(this.modifiers[e]=t[e])},h.prototype.loadFromRawObj=function(t){if(this.raw=t,this.symbols={},this.subgrammars=[],this.raw)for(var e in this.raw)this.raw.hasOwnProperty(e)&&(this.symbols[e]=new n(this,e,this.raw[e]))},h.prototype.createRoot=function(t){var e=new a(this,0,{type:-1,raw:t});return e},h.prototype.expand=function(t,e){var s=this.createRoot(t);return s.expand(),e||s.clearEscapeChars(),s},h.prototype.flatten=function(t,e){var s=this.expand(t,e);return s.finishedText},h.prototype.toJSON=function(){for(var t=Object.keys(this.symbols),e=[],s=0;s<t.length;s++){var r=t[s];e.push(' "'+r+'" : '+this.symbols[r].rulesToJSON())}return"{\n"+e.join(",\n")+"\n}"},h.prototype.pushRules=function(t,e,s){void 0===this.symbols[t]?(this.symbols[t]=new n(this,t,e),s&&(this.symbols[t].isDynamic=!0)):this.symbols[t].pushRules(e)},h.prototype.popRules=function(t){this.symbols[t]||this.errors.push("Can't pop: no symbol for key "+t),this.symbols[t].popRules()},h.prototype.selectRule=function(t,e,s){if(this.symbols[t]){var r=this.symbols[t].selectRule(e,s);return r}for(var i=0;i<this.subgrammars.length;i++)if(this.subgrammars[i].symbols[t])return this.subgrammars[i].symbols[t].selectRule();return s.push("No symbol for '"+t+"'"),"(("+t+"))"},tracery={createGrammar:function(t){return new h(t)},parseTag:function(t){for(var e={symbol:void 0,preactions:[],postactions:[],modifiers:[]},s=tracery.parse(t),r=void 0,i=0;i<s.length;i++)if(0===s[i].type){if(void 0!==r)throw"multiple main sections in "+t;r=s[i].raw}else e.preactions.push(s[i]);if(void 0===r);else{var a=r.split(".");e.symbol=a[0],e.modifiers=a.slice(1)}return e},parse:function(t){function e(e,s,r){s-e<1&&(1===r&&n.push(e+": empty tag"),2===r&&n.push(e+": empty action"));var a;a=void 0!==l?o+"\\"+t.substring(l+1,s):t.substring(e,s),i.push({type:r,raw:a}),l=void 0,o=""}var s=0,r=!1,i=[],a=!1,n=[],h=0,o="",l=void 0;if(null===t){var i=[];return i.errors=n,i}for(var u=0;u<t.length;u++)if(a)a=!1;else{var c=t.charAt(u);switch(c){case"[":0!==s||r||(h<u&&e(h,u,0),h=u+1),s++;break;case"]":s--,0!==s||r||(e(h,u,2),h=u+1);break;case"#":0===s&&(r?(e(h,u,1),h=u+1):(h<u&&e(h,u,0),h=u+1),r=!r);break;case"\\":a=!0,o+=t.substring(h,u),h=u+1,l=u}}return h<t.length&&e(h,t.length,0),r&&n.push("Unclosed tag"),s>0&&n.push("Too many ["),s<0&&n.push("Too many ]"),i=i.filter(function(t){return 0!==t.type||0!==t.raw.length}),i.errors=n,i}},tracery.TraceryNode=a,tracery.Grammar=h,tracery.Symbol=n,tracery.RuleSet=e,tracery.setRng=i,tracery}(),baseEngModifiers={replace:function(t,e){return t.replace(new RegExp(escapeRegExp(e[0]),"g"),e[1])},capitalizeAll:function(t){for(var e="",s=!0,r=0;r<t.length;r++)isAlphaNum(t.charAt(r))?s?(e+=t.charAt(r).toUpperCase(),s=!1):e+=t.charAt(r):(s=!0,e+=t.charAt(r));return e},capitalize:function(t){return t.charAt(0).toUpperCase()+t.substring(1)},a:function(t){if(t.length>0){if("u"===t.charAt(0).toLowerCase()&&t.length>2&&"i"===t.charAt(2).toLowerCase())return"a "+t;if(isVowel(t.charAt(0)))return"an "+t}return"a "+t},firstS:function(t){console.log(t);var e=t.split(" "),s=baseEngModifiers.s(e[0])+" "+e.slice(1).join(" ");return console.log(s),s},s:function(t){switch(t.charAt(t.length-1)){case"s":return t+"es";case"h":return t+"es";case"x":return t+"es";case"y":return isVowel(t.charAt(t.length-2))?t+"s":t.substring(0,t.length-1)+"ies";default:return t+"s"}},ed:function(t){switch(t.charAt(t.length-1)){case"s":return t+"ed";case"e":return t+"d";case"h":return t+"ed";case"x":return t+"ed";case"y":return isVowel(t.charAt(t.length-2))?t+"d":t.substring(0,t.length-1)+"ied";default:return t+"ed"}}};
  