UNPKG

@danielhaim/titlecaser

Version:

A powerful utility for transforming text to title case with support for multiple style guides and extensive customization options.

5 lines 37.3 kB
/*! * @danielhaim/titlecaser - v1.7.15 - 2026-02-17 * https://github.com/danielhaim1/titlecaser.git * Copyright (c) 2026 Daniel Haim, Licensed Apache-2.0 */var e=function(){for(var e=[],r=arguments.length,t=new Array(r),a=0;a<r;a++)t[a]=arguments[a];return t.forEach((r=>{Array.isArray(r)?r.forEach((r=>{Object.values(r).forEach((r=>{e.push(...r)}))})):"object"==typeof r&&Object.values(r).forEach((r=>{e.push(...r)}))})),[...new Set(e)]}(JSON.parse('{"sports":["FIFA","UEFA","NBA","NFL","MLB","NHL","NASCAR","IOC","FIBA","ATP","WTA","PGA","LPGA","FIA","WADA","ITF","AFL","NRL","ICC","IRB","IHF","FIVB","FINA","UCI","IAAF","ISU","WSF","BWF","WBC","WBO","IBF","IBO","UEFA","CONMEBOL","CONCACAF","CAF","AFC","OFC","CPL","MLS","LaLiga","Bundesliga","Ligue1","Eredivisie","JLeague","KLeague","Ryder Cup","Davis Cup","FedCup","XGames","Olympics","Paralympics","Dakar"],"apple":["Apple","AirDrop","AirPlay","AirPods","AirTags","FinalCut","GarageBand","iBooks","iCloud","iLife","iMac","iMessage","iMovie","iPhoto","iWatch","iWork","LogicPro","macOS","ProTools","QuickTime","iPhone","iPad","iPod","iOS","macOS","tvOS","watchOS"],"corporate":["Deloitte","Devoteam","ExxonMobil","GE","Boeing","Shell","Chevron"],"tech":["Bing","Salesforce","Asus","Acer","Lenovo","Huawei","Xiaomi","Epson","Nvidia","AMD","Qualcomm","Logitech","Panasonic","Sharp","Toshiba","Philips","Fujitsu","Netgear","Lexmark","Razer","SAP","Symantec","Kaspersky","Avast","McAfee","Siemens","Canon","Nikon","Garmin","GoPro","Oculus","Zoom","Slack","Trello","WeChat","Alibaba","Tencent","Baidu","Roku","Fitbit","Dropbox","Reddit","TikTok","Slack","Trello","Uber","Zoom","Reddit","Quora","JIRA","ZoomInfo","HubSpot","Mailchimp","WeChat","Dropbox","Uber","Telegram","Discord","StackOverflow","Quora","Reddit","ZoomInfo","Airbnb","LinkedIn","Snapchat","GitHub","GitLab","Nginx","OpenSSL","Webpack","Unity3D","Figma","JIRA","Kubernetes","TensorFlow","NPM","WooCommerce","WordPress","Slack","Trello","Uber","Zoom","Reddit","Quora","WeChat","Dropbox","Telegram","Discord","StackOverflow","Airbnb","LinkedIn","Snapchat","JIRA","MobX","VMware","Google"],"business":["Visa","Mastercard","Citibank","JPMorgan","Barclay","AMEX","Citigroup","PayPal","BNP","HSBC","Santander","UBS","Allianz","Prudential","Vanguard","BlackRock","CapitalOne","TD","Robinhood","MoneyGram","SoFi","Experian","Equifax","TransUnion","MasterCard","Blockchain","Coinbase","Binance","Kraken","Ethereum","Bitcoin"],"automotive":["BMW","Ford","Mercedes","Nissan","Tesla","Toyota","Audi","Chevrolet","Chrysler","Dodge","Ferrari","Fiat","Honda","Hyundai","Infiniti","Jaguar","Jeep","Kia","Lamborghini","LandRover","Lexus","Maserati","Mazda","McLaren","Mitsubishi","Peugeot","Porsche","Renault","RollsRoyce","Saab","Subaru","Suzuki","Volkswagen","Volvo","Alfa Romeo","Bentley","Bugatti","Cadillac","Citroen","Daewoo","Daihatsu","Datsun","DeLorean","Fiat Chrysler","GMC","Holden","Hummer","Isuzu","Koenigsegg","Lancia","Lincoln","Lotus","Mahindra","Suzuki","Opel","Pagani","Perodua","Proton","Rover","Scania","Skoda","SsangYong","Tata","Vauxhall","VinFast","Yugo","Zenvo"],"media":["Disney","Netflix","YouTube","Instagram","Twitter","Facebook","Spotify","Hulu","TikTok","Snapchat","Vimeo","Twitch","Reddit","HBO","Showtime","Starz","Crunchyroll","Audible","Pixar","DreamWorks","MGM","Lionsgate","Miramax","EpicGames","Ubisoft","Blizzard","Capcom","Bethesda","Sega","Roku","Fandango","IMDb","Shazam","SoundCloud","Vevo","Vine","Zynga","Tidal","Quibi","Crave","Gaia","PlutoTV","Vudu","Kanopy","Mubi","BritBox"],"telecom":["Verizon","Sprint","Nokia","Ericsson","Vodafone","AT&T","Huawei","Xiaomi","Orange","NTT","T-Mobile","Telefonica","Airtel","Telstra","Rogers","Bell","MTN","ZTE","Qualcomm","Motorola","Telus","BT","Swisscom","SoftBank","KDDI"],"entertainment":["Disney","Netflix","YouTube","Instagram","Twitter","Facebook","Spotify","Hulu","TikTok","Snapchat","Vimeo","Twitch","Reddit","Pandora","HBO","Showtime","Starz","Paramount","Peacock","Crunchyroll","Audible","Pixar","DreamWorks","MGM","Lionsgate","Miramax","EpicGames","Ubisoft","Blizzard","Capcom","Bethesda","Sega","Roku","Fandango","IMDb","Shazam","SoundCloud","Vevo","Zynga","Tidal","Oscars"],"retail":["Amazon","eBay","IKEA","Walmart","Zara","Target","Costco","Sephora","Nordstrom","Tesco","Asda","Aldi","Lidl","Carrefour","Uniqlo","H&M","Gap","Cabela’s","BassPro","REI","Ulta","Saks","JCPenney","Belk","Argos","Safeway","Kroger","Publix","HomeDepot","Woolworths","Staples","OfficeMax","B&H","Newegg","MicroCenter","Frys","Monoprix","Waitrose","Morrisons","Ocado","Flipkart","Rakuten","Alibaba","JD","Taobao","Tmall","Guomei","Suning"],"food":["Nestle","Pepsi","Coca-Cola","PepsiCo","Starbucks","KFC","BurgerKing","PizzaHut","TacoBell","Kroger","Costco","Woolworths","Carrefour","Tesco","Aldi","Lidl","Walmart","Safeway","Publix","WholeFoods","RedBull","Monster","Nespresso","Heineken","Budweiser","Corona","Guinness","GeneralMills","Unilever","Kraft","Heinz","Danone","Campbell","Tyson","Conagra","Mondelez","Suntory","Diageo","Pernod"],"pharmaceutical":["Pfizer","Moderna","Gilead","Merck","Novartis","Sanofi","Roche","AbbVie","Amgen","Bayer","Biogen","BristolMyers","Celgene","GSK","Janssen","Lilly","Medtronic","Mylan","NovoNordisk","Regeneron","Teva","AstraZeneca","Boehringer","Daiichi","Eisai","Genentech","Grifols","Ipsen","Mundipharma","Otsuka","Purdue","Sandoz","Servier","SunPharma","Takeda","UCB","Viatris","Wockhardt","Zydus","Alkem"],"nonprofit":["NGO","NPO","NGOs","NPOs","UN","UNESCO","UNICEF","UNHCR","UNODC","UNDP","UNFPA","UNEP","UNRWA"]}'),JSON.parse('{"commercial":["Ltd.","LLC","PLC","Co.","Inc.","St.","Ave.","Bldg.","No.","GmbH"],"titles":["CEO","CEOs","CFO","CFOs","CIO","CIOs","CMO","CMOs","COO","COOs","CPO","CPOs","CRO","CROs","CSO","CSOs","CTO","CTOs","EVP","EVPs","HR","HRs","SVP","SVPs","VP","VPs","CMTO","CDO"],"accounting":["AP","COGS","EBIT","EPS","FIFO","GAAP","LIFO","P&L","ROI","SOX","TCO","VAT","EBITDA","NPV","WACC","AR"],"finance":["CAGR","DCF","ETF","IPO","IRR","M&A","NAV","PE","PEG","PPE","ROE","S&P","TVM","VC","FOMC","FX","ETF"],"legal":["AFA","ADR","CCPA","CFAA","CISG","DMCA","EULA","GDPR","HIPAA","NDA","SOW","TOS","LLM","JD","Esq.","AG","SARL","KYC","AML","ph.d.","m.d.","d.d.s.","d.m.d.","d.o.","d.c.","d.v.m.","d.n.p.","d.p.m.","d.s.w.","d.s.n.","d.n.sc.","d.n.a.","d.n.t.","d.n.p.t.","d.n.o.","d.n.m.","d.n.e.","d.n.s.","d.n.p.s."]}'),JSON.parse('{"eterms":["eBook","eBooks","eMarket","eMarketplace","eMarketplaces","eMarkets","eReader","eShop","eShops","eStore","eStores","E-commerce","E-com"]}'),JSON.parse('{"countries":["Afghanistan","Albania","Algeria","Andorra","Angola","Antigua and Barbuda","Argentina","Armenia","Australia","Austria","Azerbaijan","Bahamas","Bahrain","Bangladesh","Barbados","Belarus","Belgium","Belize","Benin","Bhutan","Bolivia","Bosnia and Herzegovina","Botswana","Brazil","Brunei","Bulgaria","Burkina Faso","Burundi","Cabo Verde","Cambodia","Cameroon","Canada","Central African Republic","Chad","Chile","China","Colombia","Comoros","Congo","Costa Rica","Cote d\'Ivoire","Croatia","Cuba","Cyprus","Czech Republic","Denmark","Djibouti","Dominica","Dominican Republic","Ecuador","Egypt","El Salvador","Equatorial Guinea","Eritrea","Estonia","Eswatini","Ethiopia","Fiji","Finland","France","Gabon","Gambia","Georgia","Germany","Ghana","Greece","Grenada","Guatemala","Guinea","Guinea-Bissau","Guyana","Haiti","Honduras","Hungary","Iceland","India","Indonesia","Iran","Iraq","Ireland","Israel","Italy","Jamaica","Japan","Jordan","Kazakhstan","Kenya","Kiribati","Korea","Kosovo","Kuwait","Kyrgyzstan","Laos","Latvia","Lebanon","Lesotho","Liberia","Libya","Liechtenstein","Lithuania","Luxembourg","Madagascar","Malawi","Malaysia","Maldives","Mali","Malta","Marshall Islands","Mauritania","Mauritius","Mexico","Micronesia","Moldova","Monaco","Mongolia","Montenegro","Morocco","Mozambique","Myanmar","Namibia","Nauru","Nepal","Netherlands","New Zealand","Nicaragua","Niger","Nigeria","North Macedonia","Norway","Oman","Pakistan","Palau","Panama","Papua New Guinea","Paraguay","Peru","Philippines","Poland","Portugal","Qatar","Romania","Russia","Rwanda","Saint Kitts and Nevis","Saint Lucia","Saint Vincent and the Grenadines","Samoa","San Marino","Sao Tome and Principe","Saudi Arabia","Senegal","Serbia","Seychelles","Sierra Leone","Singapore","Slovakia","Slovenia","Solomon Islands","Somalia","South Africa","South Korea","South Sudan","Spain","Sri Lanka","Sudan","Suriname","Sweden","Switzerland","Syria","Taiwan","Tajikistan","Tanzania","Thailand","Timor-Leste","Togo","Tonga","Trinidad and Tobago","Tunisia","Turkey","Turkmenistan","Tuvalu","Uganda","Ukraine","United Arab Emirates","United Kingdom","United States","Uruguay","Uzbekistan","Vanuatu","Vatican City","Venezuela","Vietnam","Yemen","Zambia","Zimbabwe"],"alpha2":["UK"],"alpha3":["USA"]}'),JSON.parse('{"advertising":["AdWords","AdSense","AdMob","DoubleClick","SpotX"],"digitalMarketing":["DSP","SSP","CTR","CPA","CPC","CPL","CPM","CRM","SEO","SEM","SMM","A/B","CTOR","KPI","SERP","FAQ","PR"],"general":["B2B","B2C","CMO","USP","PWA","SMO","T&C","TOS","PP","UI","UX","UI/UX"],"blockchain":["PoE","PoW","PoC"],"accessibility":["A11Y"]}'),JSON.parse('{"miscellaneous":["w/","w/o","Open Source","Cybersecurity","Ecosystem","Biodiversity","LGBT","LGBTQ+","LGBTQIA+","2SLGBTQ+","BIPOC"]}'),JSON.parse('{"terms":["API","APIs","ASCII","CI","CLI","DLL","DNS","EC2","FTP","HTTP","HTTPS","ICMP","IDE","IP","ISP","LPWAN","M2M","MQTT","OOP","REST","SSH","SSL","TCP","UDP","URL","WLAN","WYSIWYG","IMAP","RSS","IaaS","PaaS","SaaS","CaaS","FaaS","XaaS","RaaS","IoE","IoT","LoRa","NB-IoT","RFID","RF","RFI","RFQ","ECMAScript","IO","I/O","DevOps","SecOps","DDoS","VoIP","AI","AR","ML","VR","CI/CD","DevSecOps","UI/UX","UX/UI","UI","UX","MVC","ORM","3G","4G","5G","NumPy","VPN","PKI","WAN","NAT","GPU","SSD","HDD","RAM","Frontend","Backend","Fullstack"],"legal":["DMCA","GDPR","HIPAA","NDA","SOW","TOS"],"languages":["JavaScript","TypeScript","Java","PHP","SQL","CSS",".NET","ES5","ES6","NoSQL","DynamoDB","Terraform","CloudFormation","RDS","Python","Ruby","Go","Swift","Kotlin","Perl"],"formats":["JSON","XML","YAML","GraphQL","WebSocket","RESTful"],"secops":["RaaS","DevSecOps","SecOps","Cybersecurity","DDoS"],"technologies":["AWS","Azure","GCP","VMware","Docker","Ansible","Chef","Puppet","Git","Subversion","Jenkins","CircleCI","Hadoop","Spark","BigQuery","PowerBI","Tableau"],"os":["Android","macOS","Windows","Linux","iOS","Ubuntu","CentOS","Fedora","Debian","SUSE","HarmonyOS","FreeRTOS","BeOS","BSD","Cordova","Flutter"],"programming":["Angular","Bootstrap","CodeIgniter","jQuery","Laravel","Redux","Vue.js","VueX","SCSS","AJAX","GraphQL","HTML","HTML5","MySQL","MongoDB","PostgresQL","SQLite","ASP","ASPX","Elasticsearch","Nginx","OpenSSL","Webpack","Unity3D","Kubernetes","TensorFlow","NPM","cURL"]}'),JSON.parse('{"timeRelated":["a.m.","p.m.","ca.","cc.","fig.","pl.","pt.","rev.","sr.","v.","vol.","et al.","pp.","p."],"academic":["adj.","adv.","cf.","cm.","co.","corp.","dept.","dist.","ed.","edn.","esp.","etc.","ex.","i.e.","e.g.","op. cit.","vs."]}'),JSON.parse('{"ranks":["Pvt.","Cpl.","Sgt.","SSgt.","GySgt.","MSgt.","1stSgt.","SgtMaj.","WO1","CW2","CW3","CW4","CW5","2ndLt.","1stLt.","Capt.","Maj.","LtCol.","Col.","BrigGen.","MajGen.","LtGen.","Gen.","Adm.","Cpt.","Cmdr.","Lt.","Ens."],"branches":["Army","Navy","Air Force","Marines","Coast Guard","Space Force","National Guard","People\'s Liberation Army","Russian Ground Forces","JASDF","ROKA"],"units":["Platoon","Company","Battalion","Regiment","Brigade","Division","Corps","Squad","Fleet","Wing","Squadron","Task Force","Eurocorps","Battlegroup","Rapid Reaction Force","Joint Expeditionary Force"],"acronyms":["DoD","NATO","EUFOR","EUTM","OSCE","UNSC","JAG","ROTC","AFB","MOS","AWOL","MRE","IED","FOB","TOC","CONUS","OCONUS","UCMJ","USMC","USAF","USN","USA","SOCOM","CENTCOM","NORAD","PACOM","JTF","RPG","SAM","ASEAN","AUKUS","QUAD","CSTO","SCO","CFSP","EEAS","EUMS","Frontex","GRU","FSB","PLAN","PLAAF"],"equipment":["Humvee","MRAP","Apache","Black Hawk","Bradley","Abrams","F-16","F-22","F-35","B-2","B-52","C-130","LCAC","MRE"],"operations":["Operation Desert Storm","Operation Enduring Freedom","Operation Iraqi Freedom","Operation Inherent Resolve"],"treaties":["Lisbon Treaty","Maastricht Treaty","Treaty of Rome","Nice Treaty","Schengen Agreement"],"regions":["South China Sea","Taiwan Strait","Korean DMZ","Kashmir","Kuril Islands","Senkaku Islands"],"alliances":["NATO","AUKUS","QUAD","ASEAN","SCO","CSTO","Five Eyes"]}')),r=["the","in","to","within","towards","into","at","of","for","by","on","from","with","through","about","across","over","under","between"],t=[{"a.k.a":"AKA"},{"a.s.a.p":"ASAP"},{"f.a.q":"FAQ"},{"f.a.q.s":"FAQs"},{FAQS:"FAQs"},{"f.y.i":"FYI"},{"d.i.y":"DIY"},{"t.b.d":"TBD"},{"back-end":"Backend"},{"front-end":"Frontend"},{"full-stack":"Fullstack"},{nodejs:"Node.js"},{nextjs:"Next.js"},{nuxtjs:"Nuxt.js"},{reactjs:"React"},{"react.js":"React"},{"cyber-security":"Cybersecurity"}],a=Object.freeze({AP:"ap",APA:"apa",BRITISH:"british",CHICAGO:"chicago",NYT:"nyt",WIKIPEDIA:"wikipedia"}),i=Object.values(a),o=Object.freeze({ap:{caseStyle:"title",shortConjunctionsList:["and","but","or","nor","yet","so","for"],articlesList:["a","an","the"],shortPrepositionsList:["at","by","for","in","of","off","on","out","per","to","via"],neverCapitalizedList:[]},apa:{caseStyle:"title",shortConjunctionsList:["and","as","but","for","if","nor","or","so","yet"],articlesList:["a","an","the"],shortPrepositionsList:["as","at","by","for","in","of","off","on","per","to","via"],neverCapitalizedList:[]},british:{caseStyle:"title",shortConjunctionsList:["and","but","or","for","nor","yet","so"],articlesList:["a","an","the"],shortPrepositionsList:["at","by","for","in","of","off","on","out","per","to","via"],neverCapitalizedList:[]},chicago:{caseStyle:"title",shortConjunctionsList:["and","but","or","for","nor","yet","so"],articlesList:["a","an","the"],shortPrepositionsList:["at","by","for","in","of","off","on","out","per","to","via"],neverCapitalizedList:["etc."]},nyt:{caseStyle:"title",shortConjunctionsList:["and","but","or","nor","yet","so","for"],articlesList:["a","an","the"],shortPrepositionsList:["at","by","for","in","of","off","on","out","per","to","via"],neverCapitalizedList:[]},wikipedia:{caseStyle:"sentence",shortConjunctionsList:["and","as","but","for","nor","or","so","yet"],articlesList:["a","an","the"],shortPrepositionsList:["at","by","for","in","of","off","on","out","per","to","via"],neverCapitalizedList:[]}}),n=[],s={"the cybersmile foundation":"The Cybersmile Foundation","co. by colgate":"CO. by Colgate","on & off":"On & Off","on and off":"On and Off"},l=Object.freeze({TRAILING_PUNCTUATION:/[.,!?;:]+$/,SPLIT_AT_PUNCTUATION:/([.,\/#!$%\^&\*;:{}=\-_`~()?])/g,HTML_BREAK:/<\s*br\s*\/?\s*>/gi,MULTIPLE_SPACES:/ {2,}/g,REGEX_ESCAPE:/[.*+?^${}()|[\]\\]/g}),c=["usa","us","u.s.a","u.s.","u.s","u.s.a.","eu","e.u.","e.u","uk","u.k.","u.k"],u=["the","via","among","across","beyond","outside","alongside","throughout","despite","unlike","upon"],p=["act","acts","administration","administrations","agency","agencies","agreement","agreements","airforce","airforces","aid","alliance","alliances","ambassador","ambassadors","authority","authorities","bill","bills","bloc","blocs","budget","budgets","bureau","bureaus","cabinet","cabinets","charter","charters","command","commands","commission","commissions","conference","conferences","congress","congresses","convention","conventions","council","councils","court","courts","defense","defences","defence","defenses","delegation","delegations","democracy","democracies","department","departments","development","developments","directive","directives","diplomacy","division","divisions","economy","economies","embassy","embassies","engagement","engagements","envoy","envoys","exports","federation","federations","finance","finances","forces","framework","frameworks","funding","government","governments","hearing","hearings","imports","initiative","initiatives","intel","intelligence","intervention","interventions","jurisdiction","jurisdictions","law","laws","leadership","leaders","legislation","liaison","liaisons","mandate","mandates","markets","marines","military","militaries","ministry","ministries","mission","missions","navy","navies","negotiations","office","offices","operations","oversight","parliament","parliaments","plan","plans","policies","policy","policy-makers","precedent","precedents","presence","program","programme","programmes","programs","project","projects","protocol","protocols","province","provinces","reform","reforms","regulation","regulations","regulator","regulators","relations","representation","representations","republic","republics","resolution","resolutions","ruling","rulings","sanctions","security","securities","senate","senates","service","services","state","states","statute","statutes","strategy","strategies","summit","summits","summitry","surveillance","talks","tariffs","territory","territories","trade","trades","treasury","treasuries","treaty","treaties","tribunal","tribunals","troops","union","unions","veterans","warships","zone","zones"];function d(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);r&&(a=a.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,a)}return t}function m(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?d(Object(t),!0).forEach((function(r){h(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):d(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}function h(e,r,t){return(r=function(e){var r=function(e,r){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var a=t.call(e,r||"default");if("object"!=typeof a)return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"==typeof r?r:r+""}(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}class g{static validateOption(e,r){if(!Array.isArray(r))throw new TypeError("Invalid option: ".concat(e," must be an array"));if(!r.every((e=>"string"==typeof e)))throw new TypeError("Invalid option: ".concat(e," must be an array of strings"))}static validateOptions(e){for(var r of Object.keys(e))if("style"!==r)if("wordReplacementsList"!==r){if(!o.hasOwnProperty(r))throw new TypeError("Invalid option: ".concat(r));g.validateOption(r,e[r])}else{if(!Array.isArray(e.wordReplacementsList))throw new TypeError("Invalid option: ".concat(r," must be an array"));for(var t of e.wordReplacementsList)if("string"!=typeof t)throw new TypeError("Invalid option: ".concat(r," must contain only strings"))}else{if("string"!=typeof e.style)throw new TypeError("Invalid option: ".concat(r," must be a string"));if(!i.includes(e.style))throw new TypeError("Invalid option: ".concat(r," must be a string"))}}static getTitleCaseOptions(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],a=e.style||"ap",i=!!e.hasOwnProperty("smartQuotes")&&e.smartQuotes,n="".concat(a,"|").concat(i,"|").concat(r.length>0?r.sort().join(","):"");if(g.titleCaseOptionsCache.has(n))return g.titleCaseOptionsCache.get(n);var s=m(m(m({},o[e.style||"ap"]),e),{},{smartQuotes:!!e.hasOwnProperty("smartQuotes")&&e.smartQuotes}),l=[...new Set([...s.articlesList,...r])],c=[...new Set([...s.shortConjunctionsList,...r])],u=[...new Set([...s.shortPrepositionsList,...r])],p=[...(s.replaceTerms||[]).map((e=>{var[r,t]=e;return[r.toLowerCase(),t]})),...t],d={articlesList:l,shortConjunctionsList:c,shortPrepositionsList:u,neverCapitalizedList:[...s.neverCapitalizedList],replaceTerms:p,smartQuotes:s.smartQuotes};return g.titleCaseOptionsCache.set(n,d),d}static capitalizeFirstLetter(e){return e.charAt(0).toUpperCase()+e.slice(1)}static isShortConjunction(e,r){var t=[...g.getTitleCaseOptions({style:r}).shortConjunctionsList],a=e.toLowerCase();return t.includes(a)}static isArticle(e,r){return g.getTitleCaseOptions({style:r}).articlesList.includes(e.toLowerCase())}static isShortPreposition(e,r){var{shortPrepositionsList:t}=g.getTitleCaseOptions({style:r});return t.includes(e.toLowerCase())}static isNeverCapitalized(e,r){var t="".concat(r,"_").concat(e.toLowerCase());if(g.isNeverCapitalizedCache.has(t))return g.isNeverCapitalizedCache.get(t);var{neverCapitalizedList:a}=g.getTitleCaseOptions({style:r}),i=a.includes(e.toLowerCase());return g.isNeverCapitalizedCache.set(t,i),i}static isShortWord(e,r){if("string"!=typeof e)throw new TypeError("Invalid input: word must be a string. Received ".concat(typeof e,"."));if(!i.includes(r))throw new Error("Invalid option: style must be one of ".concat(i.join(", "),"."));return g.isShortConjunction(e,r)||g.isArticle(e,r)||g.isShortPreposition(e,r)||g.isNeverCapitalized(e,r)}static hasNumbers(e){return/\d/.test(e)}static hasUppercaseMultiple(e){for(var r=0,t=0;t<e.length&&r<2;t++)/[A-Z]/.test(e[t])&&r++;return r>=2}static hasUppercaseIntentional(e){if(e.length<=4)return/[A-Z]/.test(e.slice(1));var r=/[A-Z]/.test(e.slice(1)),t=/[a-z]/.test(e.slice(1));return r&&t}static isEntirelyUppercase(e){return e===e.toUpperCase()&&e!==e.toLowerCase()&&e.length>1}static isRegionalAcronym(e){if("string"!=typeof e)throw new TypeError("Invalid input: word must be a string.");if(e.length<2)return!1;var r=e.toLowerCase();return c.includes(r)}static isRegionalAcronymNoDot(e,r){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;if("string"!=typeof e||"string"!=typeof r)return!1;var a=e.toLowerCase().replace(/[^\w\s]/g,""),i=r.toLowerCase().replace(/[^\w\s]/g,"");return!!(t&&c.includes(a)&&["the"].includes(t.toLowerCase()))||c.includes(a)&&p.includes(i)}static isFinalWordRegionalAcronym(e,r){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;if("string"!=typeof e||"string"!=typeof r)return!1;var a=e.toLowerCase().replace(/[^\w]/g,""),i=r.toLowerCase().replace(/[^\w]/g,""),o="string"==typeof t?t.toLowerCase().replace(/[^\w]/g,""):null;return!!c.includes(a)&&(!!u.includes(i)||!("the"!==i||!o||!u.includes(o)))}static normalizeRegionalAcronym(e){if("string"!=typeof e)throw new TypeError("Invalid input: word must be a string.");return e.toUpperCase()}static normalizeAcronymKey(e){return e.toLowerCase().replace(/\./g,"")}static normalizeCasingForWordByStyle(e,r){if(!e||!r||!o[r])return!1;var t=e.toLowerCase(),{shortConjunctionsList:a,articlesList:i,shortPrepositionsList:n,neverCapitalizedList:s}=o[r];return!![...a,...i,...n,...s].includes(t)&&e}static hasSuffix(e){return e.length>2&&e.endsWith("'s")}static hasApostrophe(e){return-1!==e.indexOf("'")}static hasHyphen(e){return-1!==e.indexOf("-")||-1!==e.indexOf("–")||-1!==e.indexOf("—")}static hasRomanNumeral(e){if("string"!=typeof e||""===e)throw new TypeError("Invalid input: word must be a non-empty string.");var r=e.includes("'")?e.split("'"):[e],t=/^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/i;return r.every((e=>t.test(e)))}static hasHyphenRomanNumeral(e){if("string"!=typeof e||""===e)throw new TypeError("Invalid input: word must be a non-empty string.");for(var r=e.split("-"),t=0;t<r.length;t++)if(!g.hasRomanNumeral(r[t]))return!1;return!0}static hasHtmlBreak(e){return"nl2br"===e}static hasUnicodeSymbols(e){return/[^\x00-\x7F\u00A0-\u00FF\u0100-\u017F\u0180-\u024F\u0250-\u02AF\u02B0-\u02FF\u0300-\u036F\u0370-\u03FF\u0400-\u04FF\u0500-\u052F\u0530-\u058F\u0590-\u05FF\u0600-\u06FF\u0700-\u074F\u0750-\u077F\u0780-\u07BF\u07C0-\u07FF\u0800-\u083F\u0840-\u085F\u0860-\u087F\u0880-\u08AF\u08B0-\u08FF\u0900-\u097F\u0980-\u09FF\u0A00-\u0A7F\u0A80-\u0AFF\u0B00-\u0B7F\u0B80-\u0BFF\u0C00-\u0C7F\u0C80-\u0CFF\u0D00-\u0D7F\u0D80-\u0DFF\u0E00-\u0E7F\u0E80-\u0EFF\u0F00-\u0FFF]/.test(e)}static hasCurrencySymbols(e){return/[^\x00-\x7F\u00A0-\u00FF\u20AC\u20A0-\u20B9\u20BD\u20A1-\u20A2\u00A3-\u00A5\u058F\u060B\u09F2-\u09F3\u0AF1\u0BF9\u0E3F\u17DB\u20A6\u20A8\u20B1\u2113\u20AA-\u20AB\u20AA\u20AC-\u20AD\u20B9]/.test(e)}static isWordAmpersand(e){return/&amp;|&/.test(e)}static startsWithSymbol(e){if("string"!=typeof e)throw new Error("Parameter 'word' must be a string. Received '".concat(typeof e,"' instead."));if(0===e.length)return!1;var r=e.charAt(0);return"#"===r||"@"===r||"."===r}static escapeSpecialCharacters(e){return e.replace(/[&<>"']/g,(function(e){switch(e){case"&":return"&amp;";case"<":return"&lt;";case">":return"&gt;";case'"':return"&quot;";case"'":return"&#x27;";default:return e}}))}static unescapeSpecialCharacters(e){return e.replace(/&amp;|&lt;|&gt;|&quot;|&#x27;/g,(function(e){switch(e){case"&amp;":return"&";case"&lt;":return"<";case"&gt;":return">";case"&quot;":return'"';case"&#x27;":return"'";default:return e}}))}static endsWithSymbol(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[".",",",";",":","?","!"];if("string"!=typeof e||!Array.isArray(r))throw new Error("Invalid arguments");return r.some((r=>e.endsWith(r)))||r.includes(e.slice(-2))}static isWordIgnored(e){var r,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:n;if(!Array.isArray(t))throw new TypeError("Invalid input: ignoredWords must be an array.");if("string"!=typeof e||""===e.trim())throw new TypeError("Invalid input: word must be a non-empty string.");return r=e.toLowerCase().trim(),t.includes(r)}static isWordInArray(e,r){return!!Array.isArray(r)&&r.some((r=>r.toLowerCase()===e.toLowerCase()))}static convertQuotesToCurly(e){for(var r={"'":["",""],'"':["“","”"]},t="",a=0;a<e.length;a++){var i=e[a],o=r[i];if(o){var n=e[a-1],s=e[a+1],l=!n||" "===n||"\n"===n?o[0]:o[1];t+=l,l===o[1]&&/[.,;!?()\[\]{}:]/.test(s)&&(t+=s,a++)}else t+=i}return t}static replaceTerm(e,r){if("string"!=typeof e||""===e)throw new TypeError("Invalid input: word must be a non-empty string.");if(!r||"object"!=typeof r)throw new TypeError("Invalid input: replaceTermObj must be a non-null object.");var t;if(t=e.toLowerCase(),r.hasOwnProperty(t))return r[t];if(r.hasOwnProperty(e))return r[e];var a=e.toUpperCase();return r.hasOwnProperty(a)?r[a]:e}static isElidedWord(e){if("string"!=typeof e||""===e.trim())throw new TypeError("Invalid input: word must be a non-empty string.");var r=new Set(["o’","fo’","ne’er","e’er","’tis","’twas","’n’"]),t=e.trim().toLowerCase().replace(/'/g,"’");for(var a of r)if(t.startsWith(a))return!0;return!1}static normalizeElidedWord(e){if("string"!=typeof e||""===e.trim())throw new TypeError("Invalid input: word must be a non-empty string.");var r=new Set(["o’","fo’","ne’er","e’er","’tis","’twas","’n’"]),t=e.trim(),a=t.replace(/'/g,"’").toLowerCase();for(var i of r)if(a.startsWith(i)){var o=i.length,n=t.slice(o);return i.charAt(0).toUpperCase()+i.slice(1)+(n.length>0?n.charAt(0).toUpperCase()+n.slice(1):"")}return!1}static correctSuffix(e,r){if("string"!=typeof e||""===e)throw new TypeError("Invalid input: word must be a non-empty string.");if(!r||!Array.isArray(r)||r.some((e=>"string"!=typeof e)))throw new TypeError("Invalid input: correctTerms must be an array of strings.");if(/'s$/i.test(e)){var t=e.slice(0,-2),a=r.findIndex((e=>e.toLowerCase()===t.toLowerCase()));if(a>=0){var i=r[a];return"".concat(i,"'s")}var o=t.charAt(0).toUpperCase()+t.slice(1);return"".concat(o,"'s")}return e}static correctTerm(e,r){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:/[-']/;if("string"!=typeof e||""===e)throw new TypeError("Invalid input: word must be a non-empty string.");if(!r||!Array.isArray(r))throw new TypeError("Invalid input: correctTerms must be an array.");if(!("string"==typeof t||Array.isArray(t)||t instanceof RegExp))throw new TypeError("Invalid input: delimiters must be a string, an array of strings, or a regular expression.");"string"==typeof t?t=new RegExp("[".concat(t,"]")):Array.isArray(t)&&(t=new RegExp("[".concat(t.join(""),"]")));for(var a=e.split(t),i=a.length,o=function(){var e=a[n].toLowerCase(),t=r.findIndex((r=>r.toLowerCase()===e));a[n]=t>=0?r[t]:a[n].charAt(0).toUpperCase()+a[n].slice(1).toLowerCase()},n=0;n<i;n++)o();var s=t.source.charAt(0);return e.includes("-")?s="-":e.includes("'")&&(s="'"),a.join(s)}static correctTermHyphenated(r,t){var a=r.match(/[-–—]/);if(!a)return r;var i=a[0],o=r.split(/[-–—]/),n=o.some((e=>c.includes(e.toLowerCase().replace(/[^\w]/g,"")))),s=e=>e.charAt(0).toUpperCase()+e.slice(1),l=e=>e.charAt(0)+e.slice(1).toLowerCase(),u={ap:(e,r)=>n||0===r?s(e):l(e),chicago:s,apa:(e,r,a)=>!n&&g.isShortWord(e,t)&&r>0&&r<a-1?e.toLowerCase():s(e),nyt:s,wikipedia:(e,r)=>0===r?s(e):l(e)},p=u[t]||l;return o.map(((r,t)=>{var a=r,i=r.toLowerCase().replace(/[^\w]/g,"");if(c.includes(i))return r.toUpperCase();if(/^(M{0,3})(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/i.test(r))return r.toUpperCase();var n=r.toLowerCase(),s=e.findIndex((e=>e.toLowerCase()===n));return s>=0&&(a=e[s]),p(a,t,o.length)})).join(i)}}h(g,"TitleCaseValidator",void 0),h(g,"titleCaseOptionsCache",new Map),h(g,"isNeverCapitalizedCache",new Map);class y{constructor(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.options=e,this.debug=e.debug||!1,this.wordReplacementsList=JSON.parse(JSON.stringify(t)),this.phraseReplacementMap=JSON.parse(JSON.stringify(s))}logWarning(e){this.debug&&console.warn("Warning: ".concat(e))}toTitleCase(t){try{if("string"!=typeof t)throw new TypeError("Invalid input: input must be a string.");if(0===t.length)throw new TypeError("Invalid input: input must not be empty.");if(t.length>1e5)throw new TypeError("Invalid input: input exceeds maximum length of 100,000 characters.");if(void 0!==this.options&&"object"!=typeof this.options)throw new TypeError("Invalid options: options must be an object.");var{style:a="ap",neverCapitalize:i=[],wordReplacementsList:n=this.wordReplacementsList,smartQuotes:s=!1,normalizeWhitespace:c=!0}=this.options,u=o[a]||{},p=["nl2br",...i],{articlesList:d,shortConjunctionsList:m,shortPrepositionsList:h,neverCapitalizedList:C,replaceTerms:f,smartQuotes:S}=g.getTitleCaseOptions(this.options,r,n),A=n.map((e=>Object.keys(e)[0].toLowerCase())),w=Object.fromEntries(n.map((e=>[Object.keys(e)[0].toLowerCase(),Object.values(e)[0]])));this.logWarning("replaceTermsArray: ".concat(A)),this.logWarning("this.wordReplacementsList: ".concat(this.wordReplacementsList));var v=t;v=v.replace(l.HTML_BREAK," nl2br "),g.isEntirelyUppercase(v.replace(/[^a-zA-Z]/g,""))&&(this.logWarning("Input string is entirely uppercase, normalizing to lowercase first"),v=v.toLowerCase());var b=v.split(/(\s+)/),L=b.map(((r,t)=>{if(!r||/^\s+$/.test(r))return r;var i=r;switch(!0){case g.isWordAmpersand(i):case g.hasHtmlBreak(i):case g.isWordIgnored(i,p):return i;case A.includes(i.toLowerCase()):return w[i.toLowerCase()];case g.isWordInArray(i,e):return g.correctTerm(i,e);case g.isElidedWord(i):return g.normalizeElidedWord(i);case g.hasHyphen(i):var o=i.replace(/[\W_]+$/,""),n=i.slice(o.length),s=o.split("-"),c=s.map((e=>{var r=e.toLowerCase();return A.includes(r)?w[r]:e})),u=!c.every(((e,r)=>e===s[r])),d=u?c.join("-"):g.correctTermHyphenated(i,a);return d.endsWith(n)?d:d+n;case g.hasSuffix(i,a):return g.correctSuffix(i,e);case g.hasUppercaseIntentional(i):return i;case g.isShortWord(i,a)&&0!==t:for(var m=null,h=t-1;h>=0;h--)if(!/^\s+$/.test(b[h])){m=b[h];break}return m&&g.endsWithSymbol(m,[":","?","!","."])?i.charAt(0).toUpperCase()+i.slice(1):g.normalizeCasingForWordByStyle(i,a);case g.endsWithSymbol(i):this.logWarning("Check if the word ends with a symbol: ".concat(i));var y=i.split(l.SPLIT_AT_PUNCTUATION);this.logWarning("Splitting word at symbols, result: ".concat(y));var C=y.map((r=>{if(this.logWarning("Processing part: ".concat(r)),g.endsWithSymbol(r))return this.logWarning("Part is a symbol: ".concat(r)),r;if(this.logWarning("Part is a word: ".concat(r)),g.isWordInArray(r,e)){var t=g.correctTerm(r,e);return this.logWarning("Word is in specialTermsList, corrected term: ".concat(t)),t}if(A.includes(r)){var a=w[r];return this.logWarning("Word is in replaceTermsArray, replacement: ".concat(a)),a}var i=r.charAt(0).toUpperCase()+r.slice(1).toLowerCase();return this.logWarning("Applying title casing to word: ".concat(i)),i}));return C.join("");case g.startsWithSymbol(i):return g.isWordInArray(i,e)?g.correctTerm(i):i;case g.hasRomanNumeral(i):return i.toUpperCase();case g.hasNumbers(i):return i;default:return i.charAt(0).toUpperCase()+i.slice(1).toLowerCase()}}));v=(v=L.join("")).replace(/nl2br/gi,"<br>"),s&&(v=g.convertQuotesToCurly(v));for(var T=v.split(/(\s+)/),O=T.filter((e=>!/^\s+$/.test(e))),P=O[0]||null,I=O[1]||null,F=0;F<T.length;F++)if(!/^\s+$/.test(T[F])){for(var E=null,R=F-1;R>=0;R--)if(!/^\s+$/.test(T[R])){E=T[R];break}for(var M=null,N=F+1;N<T.length;N++)if(!/^\s+$/.test(T[N])){M=T[N];break}var B=T[F],k=B.match(l.TRAILING_PUNCTUATION),U="";k&&(U=k[0],B=B.replace(l.TRAILING_PUNCTUATION,"")),g.isRegionalAcronymNoDot(B,M,E)&&(B=g.normalizeRegionalAcronym(B)),""!==U&&(B+=U),T[F]=B}for(var D=(v=T.join("")).split(/(\s+)/),W=1;W<D.length-1;W++){var j=D[W];D[W-1],D[W+1];j===j.toUpperCase()||g.hasUppercaseIntentional(j)||g.isWordInArray(j,r)&&(D[W]=j.length<=3?j.toLowerCase():j)}for(var G=(v=D.join("")).split(/(\s+)/),z=0;z<G.length;z++)if(!/^\s+$/.test(G[z])){for(var x=G[z],H=null,V=z-1;V>=0;V--)if(!/^\s+$/.test(G[V])){H=G[V];break}for(var K=null,Q=z+1;Q<G.length;Q++)if(!/^\s+$/.test(G[Q])){K=G[Q];break}K&&g.isRegionalAcronymNoDot(x,K,H)&&(G[z]=x.toUpperCase())}var J=G.filter((e=>!/^\s+$/.test(e))),X=J[J.length-1],Z=J[J.length-2],$=J[J.length-3];for(var[q,_]of(P&&g.isRegionalAcronym(P)&&(this.logWarning("firstWord is a regional acronym: ".concat(P)),G[0]=P.toUpperCase()),P&&I&&g.isRegionalAcronymNoDot(P,I)&&(G[0]=P.toUpperCase()),X&&Z&&g.isFinalWordRegionalAcronym(X,Z,$)&&(G[G.length-1]=X.toUpperCase()),v=G.join(""),Object.entries(this.phraseReplacementMap))){var Y=new RegExp(q.replace(l.REGEX_ESCAPE,"\\$&"),"gi");v=v.replace(Y,_)}if("sentence"===u.caseStyle){for(var ee=v.split(/(\s+)/),re=!1,te=0;te<ee.length;te++){var ae=ee[te];re||!/[A-Za-z]/.test(ae)?y.shouldKeepCasing(ae,e)||(ee[te]=ae.toLowerCase()):(y.shouldKeepCasing(ae,e)||(ee[te]=ae.charAt(0).toUpperCase()+ae.slice(1).toLowerCase()),re=!0)}v=ee.join("")}return c&&(v=v.replace(/\s+/g," ").trim()),v}catch(e){throw e instanceof Error?e:new Error(String(e))}}setReplaceTerms(e){if(!Array.isArray(e))throw new TypeError("Invalid argument: setReplaceTerms must be an array of objects.");if(e.forEach((e=>{if(e&&"object"==typeof e){var[r,t]=Object.entries(e)[0],a=this.wordReplacementsList.findIndex((e=>e.hasOwnProperty(r)));-1!==a?this.wordReplacementsList[a][r]=t:this.wordReplacementsList.push({[r]:t})}else console.warn("Invalid entry in terms array:",e)})),this.wordReplacementsList.length>2e3)throw new Error("Too many replacement rules.");this.options.wordReplacementsList=this.wordReplacementsList,this.logWarning("Log the updated this.wordReplacementsList: ".concat(this.wordReplacementsList))}addReplaceTerm(e,r){if("string"!=typeof e||"string"!=typeof r)throw new TypeError("Invalid argument: term and replacement must be strings.");var t=this.wordReplacementsList.findIndex((r=>Object.keys(r)[0]===e));if(-1!==t?this.wordReplacementsList[t][e]=r:this.wordReplacementsList.push({[e]:r}),this.wordReplacementsList.length>2e3)throw new Error("Too many replacement rules.");this.options.wordReplacementsList=this.wordReplacementsList}removeReplaceTerm(e){if("string"!=typeof e)throw new TypeError("Invalid argument: term must be a string.");var r=this.wordReplacementsList.findIndex((r=>Object.keys(r)[0]===e));if(-1===r)throw new Error("Term '".concat(e,"' not found in word replacements list."));this.wordReplacementsList.splice(r,1),this.options.wordReplacementsList=this.wordReplacementsList,this.logWarning("Log the updated this.wordReplacementsList: ".concat(this.wordReplacementsList))}addExactPhraseReplacements(e){if(!Array.isArray(e))throw new TypeError("Invalid argument: newPhrases must be an array.");e.forEach((e=>{if("object"!=typeof e||Array.isArray(e)||1!==Object.keys(e).length){if("object"!=typeof e||Array.isArray(e))throw new TypeError("Invalid argument: Each item must be an object with a single key-value pair.");Object.entries(e).forEach((e=>{var[r,t]=e;if("string"!=typeof r||"string"!=typeof t)throw new TypeError("Invalid argument: Each key-value pair must contain strings.");this.phraseReplacementMap[r]=t}))}else{var r=Object.keys(e)[0],t=e[r];if("string"!=typeof r||"string"!=typeof t)throw new TypeError("Invalid argument: Each key-value pair must contain strings.");this.phraseReplacementMap[r]=t}})),this.logWarning("Log the this.phraseReplacementMap: ".concat(this.phraseReplacementMap))}setStyle(e){if("string"!=typeof e)throw new TypeError("Invalid argument: style must be a string.");this.options.style=e}static shouldKeepCasing(e,r){return!!g.isRegionalAcronym(e)||(!!g.hasUppercaseIntentional(e)||!!g.isWordInArray(e,r))}}void 0===String.prototype.toTitleCase&&(String.prototype.toTitleCase=function(e){return new y(e).toTitleCase(this)}),"undefined"!=typeof window&&window.document&&(window.TitleCaser=y);const C=y;export{y as TitleCaser,C as default};