-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
articles.min.js
4 lines (4 loc) · 2.27 KB
/
articles.min.js
1
2
3
4
// articles.min.js, for SugarCube 2, by Chapel
// v1.0.0, 2024-07-22, 336675ff2cabe5f729a5f30d86aa409cc8432726
;!function(){"use strict";var e=new Map,r=["eunuch","eucalyptus","eugenics","eulogy","euphemism","euphony","euphoria","eureka","european","euphemistic","euphonic","euphoric","euphemistically","euphonically","euphorically","heir","heiress","herb","homage","honesty","honor","honour","hour","honest","honorous","honestly","hourly","one","ouija","once","ubiquitous","ugandan","ukrainian","unanimous","unicameral","unified","unique","unisex","universal","urinal","urological","useful","useless","usurious","usurped","utilitarian","utopic","ubiquitously","unanimously","unicamerally","uniquely","universally","urologically","usefully","uselessly","usuriously"],i=["a","an"],t=/[aeiou8]/i,n=/[A-Z]+$/,u=/[UFHLMNRSX]/,a=/[.,\/#!$%\^&\*;:{}=\-_`~()]/g;function o(e){return"a"===e?"an":"a"}function s(r,t,n){var u;return State.length>0?(u="cannot add article override -> needs to be run in StoryInit special passage or earlier",console.error(u),u):t&&"string"==typeof t?(r&&"string"==typeof r&&(r=r.toLowerCase().trim()),i.includes(r)?(t=t.trim(),void(n?e.set(t,{article:r,caseSensitive:!!n}):e.set(t.toLowerCase(),{article:r,caseSensitive:!!n}))):(u='cannot add article override -> invalid article, must be "a" or "an"',console.error(u),u)):(u="cannot add article override -> invalid word",console.error(u),u)}function l(e){var i;return i=t.test(e.first())?"an":"a",function(e,i){return!!r.includes(e.toLowerCase())&&o(i)}(e,i)||function(e,r){return!(!n.test(e)||!u.test(e.first()))&&o(r)}(e,i)||i}function c(r){if(r&&"string"==typeof r){var i=r.trim().split(" ")[0].trim();return function(r){var i=(r=r.trim()).toLowerCase();if(e.has(i)||e.has(r)){var t=e.get(i)||e.get(r);return t.caseSensitive&&!e.has(r)?null:t.article}return null}(i=i.replace(a,""))||l(i)}}function h(e,r){if(!e||"string"!=typeof e)return e;var i=c(e);return(r?i.toUpperFirst():i)+" "+e}setup.articles={find:c,output:h,override:s},Macro.add("setarticle",{handler:function(){var e=s(this.args[0],this.args[1],this.args[2]);e&&"string"==typeof e&&this.error(e)}}),Macro.add(["a","an","A","An"],{handler:function(){var e=this.name.first()===this.name.first().toUpperCase();this.output.append(h(String(this.args[0]),e))}})}();
// end articles.min.js