@bloomreach/clarity-utils 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,5 +1,6 @@
1
1
  type ClarityUtilsConfig = {
2
2
  mode?: 'list' | 'length' | 'mixed' | 'score';
3
+ locale?: string;
3
4
  whiteList?: string[];
4
5
  blackList?: string[];
5
6
  whiteListJson?: string;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  type ClarityUtilsConfig = {
2
2
  mode?: 'list' | 'length' | 'mixed' | 'score';
3
+ locale?: string;
3
4
  whiteList?: string[];
4
5
  blackList?: string[];
5
6
  whiteListJson?: string;
@@ -1,2 +1,2 @@
1
- "use strict";var tmp=(()=>{var S=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var N=Object.prototype.hasOwnProperty;var Q=(t,e)=>{for(var o in e)S(t,o,{get:e[o],enumerable:!0})},J=(t,e,o,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of z(e))!N.call(t,r)&&r!==o&&S(t,r,{get:()=>e[r],enumerable:!(s=A(e,r))||s.enumerable});return t};var V=t=>J(S({},"__esModule",{value:!0}),t);var X={};Q(X,{clarityUtils:()=>K});var v=t=>!/\w/.test(t),j={"won't":"will not","can't":"cannot","don't":"do not","doesn't":"does not","didn't":"did not","isn't":"is not","aren't":"are not","wasn't":"was not","weren't":"were not","haven't":"have not","hasn't":"has not","hadn't":"had not","wouldn't":"would not","shouldn't":"should not","couldn't":"could not","what's":"what is","what're":"what are","how's":"how is","where's":"where is","who's":"who is","that's":"that is","there's":"there is","it's":"it is","i'm":"i am","i'd":"i would","i'll":"i will","i've":"i have","we're":"we are","we've":"we have","we'd":"we would","they're":"they are","they've":"they have","you're":"you are","you've":"you have","you'd":"you would"},B=t=>t.replace(/[\w']+/g,e=>{var o;return(o=j[e])!=null?o:e}),u=t=>B(t).split(/\s+/).filter(Boolean);var b=(t,e)=>{if(!e.maxLength)return console.log(" checkLength \u2192 true (no maxLength configured)"),!0;let o=u(t).length,s=o<=e.maxLength;return console.log(` checkLength \u2192 ${s} (wordCount=${o} maxLength=${e.maxLength})`),s};var q=(t,e)=>{var o;for(let s of(o=e.blackPunctSet)!=null?o:[])if(t.includes(s))return console.log(` punct "${s}" found in sentence \u2192 false (blacklisted)`),!1;return!0},M=(t,e)=>{var s,r,n,i,h,c,a;if((s=e.blackWordSet)!=null&&s.has(t))return console.log(` word "${t}" \u2192 false (blacklisted)`),!1;if(((n=(r=e.whiteSet)==null?void 0:r.size)!=null?n:0)>0||((h=(i=e.whiteList)==null?void 0:i.length)!=null?h:0)>0){let l=!!((c=e.whiteSet)!=null&&c.has(t)||(a=e.whiteList)!=null&&a.some(g=>g.toLowerCase()===t));return console.log(` word "${t}" \u2192 ${l} (whitelist check)`),l}return console.log(` word "${t}" \u2192 true`),!0},O=(t,e)=>q(t,e)&&u(t).every(o=>M(o,e));var U=["order","package","shipment","tracking","delivery","delayed","late","lost","missing","cancel","modify","return","exchange","refund","replacement","eligible","eligibility","warranty","damaged","broken","defective","wrong","incorrect","password","login","account","locked","verification","otp","loyalty","rewards","points","promo","coupon","discount","gift","shipping","payment","billing","charged","charge","invoice","receipt","declined","size","sizing","fit","care","stock","restock","availability","sustainability","ethics","careers","privacy","terms","agent","representative","support","human","talk","speak","help","api","failure","server","technical","website","checkout","app","something"],E=["who","what","when","where","why","how","which","can","should","could","would","will","have","has","is","are","do","does","did"],D=["i","me","my","mine","we","us","our","you","your","it","he","him","his","she","her","they","them","their"],T=["is","are","was","were","do","does","did","have","need","want","look","help","know","think","make","create","find","get","buy","use","install","fix","recommend","tell","show","compare","explain"],F=["the","a","an","i","me","my","is","it","in","on","at","to","for","of","and","or","but","not","so","if","by","with","from","that","this","about"];var C=(t,e)=>{var $,R,W,x,P;let o=u(t);if(o.length===0)return!0;let s=($=e.scoreQuestionWords)!=null?$:E,r=(R=e.scorePronouns)!=null?R:D,n=(W=e.scoreCommonVerbs)!=null?W:T,i=(x=e.scoreStopwords)!=null?x:F,h=(P=e.scoreSupportWords)!=null?P:U,c=o.filter(d=>h.includes(d));if(c.length>0)return console.log(` [H] support words: found [${c.join(", ")}] \u2192 conversational (override)`),!1;let a=0,l=0;o.length<=3?(a+=2,console.log(` [A] token count: word count=${o.length} \u22643 \u2192 keyword +2`)):o.length>=6?(l+=2,console.log(` [A] token count: word count=${o.length} \u22656 \u2192 conversational +2`)):console.log(` [A] token count: word count=${o.length} (no score)`);let g=o.filter(d=>s.includes(d));g.length>0?(l+=2,console.log(` [B] question words: found [${g.join(", ")}] \u2192 conversational +2`)):console.log(" [B] question words: none");let w=o.filter(d=>r.includes(d));w.length>0?(l+=1,console.log(` [C] pronouns: found [${w.join(", ")}] \u2192 conversational +1`)):console.log(" [C] pronouns: none");let p=o.filter(d=>n.includes(d));p.length>0?(l+=1,console.log(` [D] common verbs: found [${p.join(", ")}] \u2192 conversational +1`)):console.log(" [D] common verbs: none"),t.includes("?")?(l+=3,console.log(" [E] question mark: found \u2192 conversational +3")):console.log(" [E] question mark: none");let f=o.filter(d=>i.includes(d)).length,k=f/o.length;k>.4?(l+=2,console.log(` [F] stopword ratio: ${k.toFixed(2)} (${f}/${o.length}) >0.4 \u2192 conversational +2`)):(a+=1,console.log(` [F] stopword ratio: ${k.toFixed(2)} (${f}/${o.length}) \u22640.4 \u2192 keyword +1`));let y=o.reduce((d,_)=>d+_.length,0)/o.length;y>=6?(a+=1,console.log(` [G] avg token length: ${y.toFixed(2)} \u22656 \u2192 keyword +1`)):console.log(` [G] avg token length: ${y.toFixed(2)} (no score)`);let L=a>=l;return console.log(` scores: keyword=${a} conversational=${l} \u2192 ${L?"keyword":"conversational"}`),L};var m={},I=async t=>{m={...t};let e=new Set,o=new Set,s=new Set;try{return await Promise.all([t.whiteListJson?fetch(t.whiteListJson).then(r=>r.json()).then(r=>{r.forEach(n=>s.add(n.toLowerCase()))}):null,t.blackListJson?fetch(t.blackListJson).then(r=>r.json()).then(r=>{r.forEach(n=>{let i=n.toLowerCase();v(i)?e.add(i):o.add(i)})}):null]),m={...m,blackJsonPunctSet:e,blackJsonWordSet:o,whiteSet:s},{success:!0}}catch(r){return{success:!1,error:r}}},G=t=>{var o,s,r;let e={...m,...t!=null?t:{}};return e.blackPunctSet=new Set([...(o=e.blackJsonPunctSet)!=null?o:[]]),e.blackWordSet=new Set([...(s=e.blackJsonWordSet)!=null?s:[]]),(r=e.blackList)==null||r.forEach(n=>{var h,c;let i=n.toLowerCase();v(i)?(h=e.blackPunctSet)==null||h.add(i):(c=e.blackWordSet)==null||c.add(i)}),e.scoreQuestionWords&&(e.scoreQuestionWords=e.scoreQuestionWords.map(n=>n.toLowerCase())),e.scorePronouns&&(e.scorePronouns=e.scorePronouns.map(n=>n.toLowerCase())),e.scoreCommonVerbs&&(e.scoreCommonVerbs=e.scoreCommonVerbs.map(n=>n.toLowerCase())),e.scoreStopwords&&(e.scoreStopwords=e.scoreStopwords.map(n=>n.toLowerCase())),e.scoreSupportWords&&(e.scoreSupportWords=e.scoreSupportWords.map(n=>n.toLowerCase())),e},H=(t,e)=>{var i,h,c,a,l,g,w,p;let o=G(e),s=t.toLowerCase(),r=u(s);console.group(`[isSearch] "${t}" | mode=${o.mode} | tokens=[${r.join(", ")}]`),(o.mode==="mixed"||o.mode==="list")&&console.log(`lists: blackWordSet=${(h=(i=o.blackWordSet)==null?void 0:i.size)!=null?h:0} blackPunctSet=${(a=(c=o.blackPunctSet)==null?void 0:c.size)!=null?a:0} whiteSet=${(g=(l=o.whiteSet)==null?void 0:l.size)!=null?g:0} whiteList=${(p=(w=o.whiteList)==null?void 0:w.length)!=null?p:0}`);let n;return o.mode==="length"?n=b(s,o):o.mode==="mixed"?n=O(s,o)&&b(s,o):o.mode==="score"?n=C(s,o):n=C(s,o),console.log(`\u2192 Result: ${n}`),console.groupEnd(),n},K={setup:I,isSearch:H};return V(X);})();
1
+ "use strict";var tmp=(()=>{var y=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var A=(n,e)=>{for(var o in e)y(n,o,{get:e[o],enumerable:!0})},G=(n,e,o,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of B(e))!T.call(n,s)&&s!==o&&y(n,s,{get:()=>e[s],enumerable:!(t=U(e,s))||t.enumerable});return n};var H=n=>G(y({},"__esModule",{value:!0}),n);var se={};A(se,{clarityUtils:()=>te});var q={questions:["who","what","when","where","why","how","which","can","should","could","would","will","have","has","is","are","do","does","did"],pronouns:["i","me","my","mine","we","us","our","you","your","it","he","him","his","she","her","they","them","their"],commonVerbs:["is","are","was","were","do","does","did","have","need","want","look","help","know","think","make","create","find","get","buy","use","install","fix","recommend","tell","show","compare","explain"],stopwords:["the","a","an","i","me","my","is","it","in","on","at","to","for","of","and","or","but","not","so","if","by","with","from","that","this","about"],support:["order","package","shipment","tracking","delivery","delayed","late","lost","missing","cancel","modify","return","exchange","refund","replacement","eligible","eligibility","warranty","damaged","broken","defective","wrong","incorrect","password","login","account","locked","verification","otp","loyalty","rewards","points","promo","coupon","discount","gift","shipping","payment","billing","charged","charge","invoice","receipt","declined","size","sizing","fit","care","stock","restock","availability","sustainability","ethics","careers","privacy","terms","agent","representative","support","human","talk","speak","help","api","failure","server","technical","website","checkout","app"],contractions:{"won't":"will not","can't":"cannot","don't":"do not","doesn't":"does not","didn't":"did not","isn't":"is not","aren't":"are not","wasn't":"was not","weren't":"were not","haven't":"have not","hasn't":"has not","hadn't":"had not","wouldn't":"would not","shouldn't":"should not","couldn't":"could not","what's":"what is","what're":"what are","how's":"how is","where's":"where is","who's":"who is","that's":"that is","there's":"there is","it's":"it is","i'm":"i am","i'd":"i would","i'll":"i will","i've":"i have","we're":"we are","we've":"we have","we'd":"we would","they're":"they are","they've":"they have","you're":"you are","you've":"you have","you'd":"you would"}},N={questions:["wer","was","wann","wo","warum","wieso","weshalb","wie","welche","welcher","welches","kann","kannst","k\xF6nnen","soll","sollte","k\xF6nnte","w\xFCrde","wird","hat","habe","haben","ist","sind","tust","tun"],pronouns:["ich","mich","mir","mein","meine","meiner","meinen","wir","uns","unser","unsere","du","dich","dir","dein","deine","sie","ihnen","er","ihn","ihm","sein","seine","ihr","ihre","es"],commonVerbs:["ist","sind","war","waren","tut","tun","tat","taten","hat","habe","haben","hatte","hatten","brauche","brauchen","m\xF6chte","m\xF6chten","will","willst","wollen","suche","suchen","hilf","helfen","wei\xDF","denke","denken","mache","machen","erstelle","erstellen","finde","finden","kaufe","kaufen","benutze","benutzen","installiere","installieren","repariere","reparieren","empfehle","empfehlen","sage","sagen","zeige","zeigen","vergleiche","vergleichen","erkl\xE4re","erkl\xE4ren"],stopwords:["der","die","das","den","dem","des","ein","eine","einen","einer","eines","ich","mich","mein","ist","es","in","an","auf","zu","f\xFCr","von","und","oder","aber","nicht","also","falls","mit","aus","dass","dieser","diese","dieses","\xFCber"],support:["bestellung","bestellungen","paket","sendung","versand","lieferung","tracking","verz\xF6gert","versp\xE4tet","verloren","fehlt","fehlend","stornieren","storno","\xE4ndern","r\xFCcksendung","r\xFCckgabe","retoure","umtausch","r\xFCckerstattung","erstattung","ersatz","berechtigt","anspruch","garantie","besch\xE4digt","kaputt","defekt","falsch","fehlerhaft","passwort","anmelden","login","konto","gesperrt","verifizierung","otp","treue","treueprogramm","pr\xE4mien","punkte","aktion","gutschein","rabatt","geschenk","geschenkkarte","versandkosten","zahlung","abrechnung","belastet","rechnung","beleg","quittung","abgelehnt","gr\xF6\xDFe","passform","pflege","lager","verf\xFCgbarkeit","nachhaltigkeit","ethik","karriere","datenschutz","bedingungen","agb","mitarbeiter","vertreter","support","mensch","sprechen","reden","hilfe","api","fehler","server","technisch","webseite","kasse","app","r\xFCckgabe","zur\xFCckgeben","bestellstatus","lieferstatus"]},D={questions:["qui","que","quoi","quand","o\xF9","pourquoi","comment","combien","quel","quelle","quels","quelles","peux","peut","peuvent","dois","doit","devrait","pourrait","aurait","sera","est","sont","fait","font","ai","as","a","avons","avez","ont"],pronouns:["je","moi","mon","ma","mes","mien","mienne","nous","notre","nos","n\xF4tre","tu","te","toi","ton","ta","tes","vous","votre","vos","il","lui","son","sa","ses","elle","ils","elles","leur","leurs"],commonVerbs:["est","sont","\xE9tait","\xE9taient","fait","font","faisait","ai","as","a","avons","avez","ont","avait","avaient","besoin","veux","veut","voulons","voulez","veulent","cherche","cherchons","cherchez","aide","aider","sais","sait","savez","savons","pense","pensons","pensez","fais","faisons","faites","cr\xE9e","cr\xE9er","trouve","trouver","ach\xE8te","acheter","utilise","utiliser","installe","installer","r\xE9pare","r\xE9parer","recommande","recommander","dis","dites","montre","montrer","compare","comparer","explique","expliquer"],stopwords:["le","la","les","un","une","des","du","au","aux","je","me","mon","est","il","elle","dans","sur","\xE0","pour","de","et","ou","mais","pas","donc","si","par","avec","depuis","que","ce","cette","ces"],support:["commande","commandes","colis","envoi","exp\xE9dition","livraison","suivi","retard\xE9","retard","perdu","manquant","annuler","annulation","modifier","retour","retours","\xE9change","remboursement","remplacement","\xE9ligible","\xE9ligibilit\xE9","garantie","endommag\xE9","cass\xE9","d\xE9fectueux","incorrect","erron\xE9","mot de passe","motdepasse","connexion","identifiant","compte","verrouill\xE9","v\xE9rification","otp","fid\xE9lit\xE9","r\xE9compenses","points","promo","promotion","coupon","remise","r\xE9duction","cadeau","paiement","facturation","factur\xE9","facture","re\xE7u","refus\xE9","taille","pointure","ajustement","entretien","stock","disponibilit\xE9","durabilit\xE9","\xE9thique","carri\xE8res","confidentialit\xE9","conditions","agent","repr\xE9sentant","support","humain","parler","aide","api","panne","serveur","technique","site","paiement","app","application","remboursement","retard","site web"],elisionPrefixes:["j","n","qu","l","d","c","m","t","s"]},I={questions:["chi","cosa","che","quando","dove","perch\xE9","perch\xE8","come","quanto","quanti","quante","quale","quali","posso","pu\xF2","possono","devo","deve","dovrebbe","potrebbe","vorrebbe","sar\xE0","ho","ha","hanno","\xE8","sono","fa","fanno","fai"],pronouns:["io","mi","me","mio","mia","miei","mie","noi","ci","nostro","nostra","nostri","nostre","tu","ti","te","tuo","tua","tuoi","tue","voi","vi","vostro","vostra","vostri","vostre","lui","lei","suo","sua","suoi","sue","loro"],commonVerbs:["\xE8","sono","era","erano","fa","fanno","faceva","ha","ho","hai","abbiamo","avete","hanno","aveva","avevano","bisogno","voglio","vuole","vogliamo","volete","vogliono","cerco","cerca","cerchiamo","cercate","aiuto","aiutare","so","sa","sappiamo","sapete","penso","pensa","pensiamo","faccio","facciamo","fate","creo","creare","trovo","trovare","compro","comprare","uso","usare","installo","installare","riparo","riparare","raccomando","raccomandare","dimmi","dire","mostra","mostrare","confronto","confrontare","spiego","spiegare"],stopwords:["il","lo","la","i","gli","le","un","uno","una","io","mi","mio","\xE8","in","su","a","per","di","da","e","ed","o","ma","non","cos\xEC","se","con","che","questo","questa","questi","queste"],support:["ordine","ordini","pacco","spedizione","consegna","tracciamento","ritardato","ritardo","perso","mancante","annullare","annullamento","modificare","reso","resi","cambio","rimborso","sostituzione","idoneo","idoneit\xE0","garanzia","danneggiato","rotto","difettoso","sbagliato","errato","password","accesso","login","account","bloccato","verifica","otp","fedelt\xE0","premi","punti","promozione","promo","coupon","sconto","regalo","pagamento","fatturazione","addebitato","fattura","ricevuta","rifiutato","taglia","misura","vestibilit\xE0","cura","scorta","disponibilit\xE0","sostenibilit\xE0","etica","carriere","privacy","termini","agente","rappresentante","supporto","umano","parlare","aiuto","api","guasto","server","tecnico","sito","checkout","app","assistenza","restituzione","stato ordine"],elisionPrefixes:["c","l","d","un","m","t","s","all","nell","dell","sull","quell"]},K={questions:["wie","wat","wanneer","waar","waarom","hoe","hoeveel","welke","welk","kan","kunt","kunnen","zou","zal","moet","heb","heeft","hebben","is","zijn","doe","doet","doen"],pronouns:["ik","mij","me","mijn","wij","we","ons","onze","jij","je","jou","jouw","u","uw","hij","hem","zijn","zij","ze","haar","hen","hun","het"],commonVerbs:["is","zijn","was","waren","doet","doe","doen","deed","deden","heb","heeft","hebben","had","hadden","nodig","wil","willen","wilde","zoek","zoeken","help","helpen","weet","weten","denk","denken","maak","maken","maakte","cre\xEBer","cre\xEBren","vind","vinden","vond","koop","kopen","gebruik","gebruiken","installeer","installeren","repareer","repareren","raad","aanraden","vertel","vertellen","toon","tonen","vergelijk","vergelijken","leg","uitleggen"],stopwords:["de","het","een","ik","mij","mijn","is","in","op","aan","naar","voor","van","en","of","maar","niet","dus","als","door","met","vanaf","dat","dit","deze","die","over"],support:["bestelling","bestellingen","pakket","zending","verzending","levering","tracking","vertraagd","laat","verloren","ontbrekend","annuleren","wijzigen","retour","retourneren","ruil","terugbetaling","restitutie","vervanging","geschikt","geschiktheid","garantie","beschadigd","kapot","defect","verkeerd","onjuist","wachtwoord","inloggen","login","account","geblokkeerd","verificatie","otp","loyaliteit","beloningen","punten","promo","promotie","kortingsbon","korting","cadeau","cadeaubon","verzending","betaling","facturering","gefactureerd","factuur","bonnetje","kassabon","geweigerd","maat","pasvorm","verzorging","voorraad","beschikbaarheid","duurzaamheid","ethiek","carri\xE8res","privacy","voorwaarden","medewerker","vertegenwoordiger","ondersteuning","mens","praten","spreken","hulp","api","storing","server","technisch","website","afrekenen","app","klantenservice","bestelstatus","terugsturen"]},E={questions:["qui\xE9n","quien","qu\xE9","que","cu\xE1ndo","cuando","d\xF3nde","donde","porqu\xE9","porque","c\xF3mo","como","cu\xE1l","cual","cu\xE1les","cuales","cu\xE1nto","cuanto","cu\xE1ntos","puedo","puede","pueden","podr\xEDa","deber\xEDa","ser\xEDa","ha","han","es","son","hace","hacen"],pronouns:["yo","me","m\xED","mi","m\xEDo","m\xEDa","m\xEDos","m\xEDas","nosotros","nosotras","nos","nuestro","nuestra","nuestros","nuestras","t\xFA","tu","te","ti","tuyo","tuya","tuyos","tuyas","usted","ustedes","vosotros","vosotras","vuestro","vuestra","\xE9l","ella","su","sus","suyo","suya","ellos","ellas","les","los","las","le","la","lo"],commonVerbs:["es","son","era","eran","est\xE1","est\xE1n","hace","hacen","hac\xEDa","ha","he","has","hemos","hab\xE9is","han","hab\xEDa","hab\xEDan","necesito","necesita","necesitamos","necesitan","quiero","quiere","queremos","quer\xE9is","quieren","busco","busca","buscamos","buscan","ayuda","ayudar","s\xE9","sabe","sabemos","saben","pienso","piensa","pensamos","hago","hacemos","creo","crear","encuentro","encontrar","compro","comprar","uso","usar","instalo","instalar","reparo","reparar","recomiendo","recomendar","dime","decir","muestra","mostrar","comparo","comparar","explico","explicar"],stopwords:["el","la","los","las","un","una","unos","unas","yo","me","mi","es","en","a","al","para","de","del","y","e","o","u","pero","no","as\xED","si","por","con","desde","que","este","esta","estos","estas","sobre"],support:["pedido","pedidos","paquete","env\xEDo","entrega","seguimiento","retrasado","tarde","perdido","faltante","cancelar","cancelaci\xF3n","modificar","devoluci\xF3n","devoluciones","cambio","reembolso","reemplazo","elegible","elegibilidad","garant\xEDa","da\xF1ado","roto","defectuoso","incorrecto","equivocado","contrase\xF1a","acceso","login","cuenta","bloqueada","bloqueado","verificaci\xF3n","otp","fidelidad","recompensas","puntos","promo","promoci\xF3n","cup\xF3n","descuento","regalo","env\xEDo","pago","facturaci\xF3n","cobrado","cargo","factura","recibo","rechazado","talla","tama\xF1o","ajuste","cuidado","inventario","disponibilidad","sostenibilidad","\xE9tica","carreras","privacidad","t\xE9rminos","agente","representante","soporte","humano","hablar","ayuda","api","fallo","servidor","t\xE9cnico","sitio","pago","app","atenci\xF3n al cliente","estado del pedido","devolver","empleo","trabajo"]},V={"en-gb":q,"en-us":q,"en-ca":q,"de-de":N,"fr-fr":D,"fr-ca":D,"it-it":I,"nl-nl":K,"es-es":E,"es-us":E},F="en-us",f=n=>{var e,o;return(o=V[(e=n==null?void 0:n.toLowerCase())!=null?e:F])!=null?o:V[F]};var z=n=>!/\w/.test(n),M=(n,e)=>{if(!e||e.length===0)return n;let o=new RegExp(`\\b(${e.join("|")})'(?=\\w)`,"gi");return n.replace(o,"$1' ")},X=(n,e)=>e?n.replace(/[\w']+/g,o=>{var t;return(t=e[o])!=null?t:o}):n,p=(n,e)=>{let o=f(e),t=M(n,o.elisionPrefixes);return X(t,o.contractions).split(/\s+/).filter(Boolean)},h=n=>{let e=[];for(let o of n.phrases){let t=o.split(/\s+/).filter(Boolean);if(t.length!==0){if(t.length===1){n.tokens.includes(t[0])&&e.push(o);continue}for(let s=0;s<=n.tokens.length-t.length;s++){let r=!0;for(let a=0;a<t.length;a++)if(n.tokens[s+a]!==t[a]){r=!1;break}if(r){e.push(o);break}}}}return e},J=n=>n.reduce((e,o)=>e+o.split(/\s+/).filter(Boolean).length,0);var L=(n,e)=>{if(!e.maxLength)return console.log(" checkLength \u2192 true (no maxLength configured)"),!0;let o=p(n).length,t=o<=e.maxLength;return console.log(` checkLength \u2192 ${t} (wordCount=${o} maxLength=${e.maxLength})`),t};var Y=(n,e)=>{var o;for(let t of(o=e.blackPunctSet)!=null?o:[])if(n.includes(t))return console.log(` punct "${t}" found in sentence \u2192 false (blacklisted)`),!1;return!0},Z=(n,e)=>{var t,s,r,a,c,u,d;if((t=e.blackWordSet)!=null&&t.has(n))return console.log(` word "${n}" \u2192 false (blacklisted)`),!1;if(((r=(s=e.whiteSet)==null?void 0:s.size)!=null?r:0)>0||((c=(a=e.whiteList)==null?void 0:a.length)!=null?c:0)>0){let l=!!((u=e.whiteSet)!=null&&u.has(n)||(d=e.whiteList)!=null&&d.some(i=>i.toLowerCase()===n));return console.log(` word "${n}" \u2192 ${l} (whitelist check)`),l}return console.log(` word "${n}" \u2192 true`),!0},O=(n,e)=>Y(n,e)&&p(n).every(o=>Z(o,e));var C=(n,e)=>{var W,$,j,R,P;let o=p(n,e.locale);if(o.length===0)return!0;let t=f(e.locale),s=(W=e.scoreQuestionWords)!=null?W:t.questions,r=($=e.scorePronouns)!=null?$:t.pronouns,a=(j=e.scoreCommonVerbs)!=null?j:t.commonVerbs,c=(R=e.scoreStopwords)!=null?R:t.stopwords,u=(P=e.scoreSupportWords)!=null?P:t.support,d=h({tokens:o,phrases:u});if(d.length>0)return console.log(` [A] support words: found [${d.join(", ")}] \u2192 conversational (override)`),!1;let l=0,i=0;o.length<=3?(l+=2,console.log(` [B] token count: word count=${o.length} \u22643 \u2192 keyword +2`)):o.length>=6?(i+=2,console.log(` [B] token count: word count=${o.length} \u22656 \u2192 conversational +2`)):console.log(` [B] token count: word count=${o.length} (no score)`);let m=h({tokens:o,phrases:s});m.length>0?(i+=2,console.log(` [C] question words: found [${m.join(", ")}] \u2192 conversational +2`)):console.log(" [C] question words: none");let g=h({tokens:o,phrases:r});g.length>0?(i+=1,console.log(` [D] pronouns: found [${g.join(", ")}] \u2192 conversational +1`)):console.log(" [D] pronouns: none");let S=h({tokens:o,phrases:a});S.length>0?(i+=1,console.log(` [E] common verbs: found [${S.join(", ")}] \u2192 conversational +1`)):console.log(" [E] common verbs: none"),n.includes("?")?(i+=3,console.log(" [F] question mark: found \u2192 conversational +3")):console.log(" [F] question mark: none");let w=J(h({tokens:o,phrases:c})),b=w/o.length;b>.4?(i+=2,console.log(` [G] stopword ratio: ${b.toFixed(2)} (${w}/${o.length}) >0.4 \u2192 conversational +2`)):(l+=1,console.log(` [G] stopword ratio: ${b.toFixed(2)} (${w}/${o.length}) \u22640.4 \u2192 keyword +1`));let k=o.reduce((_,Q)=>_+Q.length,0)/o.length;k>=6?(l+=1,console.log(` [H] avg token length: ${k.toFixed(2)} \u22656 \u2192 keyword +1`)):console.log(` [H] avg token length: ${k.toFixed(2)} (no score)`);let x=l>=i;return console.log(` scores: keyword=${l} conversational=${i} \u2192 ${x?"keyword":"conversational"}`),x};var v={},ee=async n=>{v={...n};let e=new Set,o=new Set,t=new Set;try{return await Promise.all([n.whiteListJson?fetch(n.whiteListJson).then(s=>s.json()).then(s=>{s.forEach(r=>t.add(r.toLowerCase()))}):null,n.blackListJson?fetch(n.blackListJson).then(s=>s.json()).then(s=>{s.forEach(r=>{let a=r.toLowerCase();z(a)?e.add(a):o.add(a)})}):null]),v={...v,blackJsonPunctSet:e,blackJsonWordSet:o,whiteSet:t},{success:!0}}catch(s){return{success:!1,error:s}}},oe=n=>{var o,t,s;let e={...v,...n!=null?n:{}};return e.blackPunctSet=new Set([...(o=e.blackJsonPunctSet)!=null?o:[]]),e.blackWordSet=new Set([...(t=e.blackJsonWordSet)!=null?t:[]]),(s=e.blackList)==null||s.forEach(r=>{var c,u;let a=r.toLowerCase();z(a)?(c=e.blackPunctSet)==null||c.add(a):(u=e.blackWordSet)==null||u.add(a)}),e.scoreQuestionWords&&(e.scoreQuestionWords=e.scoreQuestionWords.map(r=>r.toLowerCase())),e.scorePronouns&&(e.scorePronouns=e.scorePronouns.map(r=>r.toLowerCase())),e.scoreCommonVerbs&&(e.scoreCommonVerbs=e.scoreCommonVerbs.map(r=>r.toLowerCase())),e.scoreStopwords&&(e.scoreStopwords=e.scoreStopwords.map(r=>r.toLowerCase())),e.scoreSupportWords&&(e.scoreSupportWords=e.scoreSupportWords.map(r=>r.toLowerCase())),e},ne=(n,e)=>{var a,c,u,d,l,i,m,g;let o=oe(e),t=n.toLowerCase(),s=p(t);console.group(`[isSearch] "${n}" | mode=${o.mode} | tokens=[${s.join(", ")}]`),(o.mode==="mixed"||o.mode==="list")&&console.log(`lists: blackWordSet=${(c=(a=o.blackWordSet)==null?void 0:a.size)!=null?c:0} blackPunctSet=${(d=(u=o.blackPunctSet)==null?void 0:u.size)!=null?d:0} whiteSet=${(i=(l=o.whiteSet)==null?void 0:l.size)!=null?i:0} whiteList=${(g=(m=o.whiteList)==null?void 0:m.length)!=null?g:0}`);let r;return o.mode==="length"?r=L(t,o):o.mode==="mixed"?r=O(t,o)&&L(t,o):o.mode==="score"?r=C(t,o):r=C(t,o),console.log(`\u2192 Result: ${r}`),console.groupEnd(),r},te={setup:ee,isSearch:ne};return H(se);})();
2
2
  window.clarityUtils=tmp.clarityUtils;