@bloomreach/clarity-utils 1.0.2 → 1.0.3
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 +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.global.js +1 -1
- package/dist/index.js +93 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +93 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.global.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var tmp=(()=>{var
|
|
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);})();
|
|
2
2
|
window.clarityUtils=tmp.clarityUtils;
|
package/dist/index.js
CHANGED
|
@@ -110,6 +110,91 @@ var checkWord = (word, c) => {
|
|
|
110
110
|
var checkList = (lower, c) => checkPuncts(lower, c) && tokenize(lower).every((word) => checkWord(word, c));
|
|
111
111
|
|
|
112
112
|
// src/enums.ts
|
|
113
|
+
var DEFAULT_SUPPORT_WORDS = [
|
|
114
|
+
// Orders / tracking / delivery
|
|
115
|
+
"order",
|
|
116
|
+
"package",
|
|
117
|
+
"shipment",
|
|
118
|
+
"tracking",
|
|
119
|
+
"delivery",
|
|
120
|
+
"delayed",
|
|
121
|
+
"late",
|
|
122
|
+
"lost",
|
|
123
|
+
"missing",
|
|
124
|
+
"cancel",
|
|
125
|
+
"modify",
|
|
126
|
+
// Returns / refunds / exchanges
|
|
127
|
+
"return",
|
|
128
|
+
"exchange",
|
|
129
|
+
"refund",
|
|
130
|
+
"replacement",
|
|
131
|
+
"eligible",
|
|
132
|
+
"eligibility",
|
|
133
|
+
// 'money back',
|
|
134
|
+
// Product issues
|
|
135
|
+
"warranty",
|
|
136
|
+
"damaged",
|
|
137
|
+
"broken",
|
|
138
|
+
"defective",
|
|
139
|
+
"wrong",
|
|
140
|
+
"incorrect",
|
|
141
|
+
// Account / login
|
|
142
|
+
"password",
|
|
143
|
+
"login",
|
|
144
|
+
// 'sign in',
|
|
145
|
+
"account",
|
|
146
|
+
"locked",
|
|
147
|
+
"verification",
|
|
148
|
+
"otp",
|
|
149
|
+
// Loyalty / promos / gift cards
|
|
150
|
+
"loyalty",
|
|
151
|
+
"rewards",
|
|
152
|
+
"points",
|
|
153
|
+
"promo",
|
|
154
|
+
"coupon",
|
|
155
|
+
"discount",
|
|
156
|
+
"gift",
|
|
157
|
+
// Shipping / payments / billing
|
|
158
|
+
"shipping",
|
|
159
|
+
"payment",
|
|
160
|
+
"billing",
|
|
161
|
+
"charged",
|
|
162
|
+
"charge",
|
|
163
|
+
"invoice",
|
|
164
|
+
"receipt",
|
|
165
|
+
"declined",
|
|
166
|
+
// Product info / sizing / inventory
|
|
167
|
+
"size",
|
|
168
|
+
"sizing",
|
|
169
|
+
"fit",
|
|
170
|
+
"care",
|
|
171
|
+
"stock",
|
|
172
|
+
"restock",
|
|
173
|
+
"availability",
|
|
174
|
+
// Company / policy
|
|
175
|
+
"sustainability",
|
|
176
|
+
"ethics",
|
|
177
|
+
"careers",
|
|
178
|
+
"privacy",
|
|
179
|
+
"terms",
|
|
180
|
+
// Human support
|
|
181
|
+
"agent",
|
|
182
|
+
"representative",
|
|
183
|
+
"support",
|
|
184
|
+
"human",
|
|
185
|
+
"talk",
|
|
186
|
+
"speak",
|
|
187
|
+
"help",
|
|
188
|
+
// Technical / service issues
|
|
189
|
+
"api",
|
|
190
|
+
"failure",
|
|
191
|
+
"server",
|
|
192
|
+
"technical",
|
|
193
|
+
"website",
|
|
194
|
+
"checkout",
|
|
195
|
+
"app",
|
|
196
|
+
"something"
|
|
197
|
+
];
|
|
113
198
|
var DEFAULT_QUESTION_WORDS = [
|
|
114
199
|
"who",
|
|
115
200
|
"what",
|
|
@@ -211,13 +296,19 @@ var DEFAULT_STOPWORDS = [
|
|
|
211
296
|
|
|
212
297
|
// src/modes/score.ts
|
|
213
298
|
var scoreQuery = (query, c) => {
|
|
214
|
-
var _a, _b, _c, _d;
|
|
299
|
+
var _a, _b, _c, _d, _e;
|
|
215
300
|
const tokens = tokenize(query);
|
|
216
301
|
if (tokens.length === 0) return true;
|
|
217
302
|
const questionWords = (_a = c.scoreQuestionWords) != null ? _a : DEFAULT_QUESTION_WORDS;
|
|
218
303
|
const pronouns = (_b = c.scorePronouns) != null ? _b : DEFAULT_PRONOUNS;
|
|
219
304
|
const commonVerbs = (_c = c.scoreCommonVerbs) != null ? _c : DEFAULT_COMMON_VERBS;
|
|
220
305
|
const stopwords = (_d = c.scoreStopwords) != null ? _d : DEFAULT_STOPWORDS;
|
|
306
|
+
const supportWords = (_e = c.scoreSupportWords) != null ? _e : DEFAULT_SUPPORT_WORDS;
|
|
307
|
+
const matchedSupportWords = tokens.filter((t) => supportWords.includes(t));
|
|
308
|
+
if (matchedSupportWords.length > 0) {
|
|
309
|
+
console.log(` [H] support words: found [${matchedSupportWords.join(", ")}] \u2192 conversational (override)`);
|
|
310
|
+
return false;
|
|
311
|
+
}
|
|
221
312
|
let scoreKeyword = 0;
|
|
222
313
|
let scoreConversational = 0;
|
|
223
314
|
if (tokens.length <= 3) {
|
|
@@ -333,6 +424,7 @@ var resolveConfig = (config) => {
|
|
|
333
424
|
if (merged.scorePronouns) merged.scorePronouns = merged.scorePronouns.map((s) => s.toLowerCase());
|
|
334
425
|
if (merged.scoreCommonVerbs) merged.scoreCommonVerbs = merged.scoreCommonVerbs.map((s) => s.toLowerCase());
|
|
335
426
|
if (merged.scoreStopwords) merged.scoreStopwords = merged.scoreStopwords.map((s) => s.toLowerCase());
|
|
427
|
+
if (merged.scoreSupportWords) merged.scoreSupportWords = merged.scoreSupportWords.map((s) => s.toLowerCase());
|
|
336
428
|
return merged;
|
|
337
429
|
};
|
|
338
430
|
var isSearch = (value, config) => {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/utils.ts","../src/modes/length.ts","../src/modes/list.ts","../src/enums.ts","../src/modes/score.ts"],"sourcesContent":["import { checkLength } from './modes/length'\nimport { checkList } from './modes/list'\nimport { scoreQuery } from './modes/score'\nimport type { ClarityUtilsConfig, ResolvedConfig } from './types'\nimport { isPunct, tokenize } from './utils'\n\nlet globalResolved: ResolvedConfig = {}\n\nconst setup = async (\n config: ClarityUtilsConfig\n): Promise<{ success: true } | { success: false; error: unknown }> => {\n globalResolved = { ...config }\n const blackJsonPunctSet = new Set<string>()\n const blackJsonWordSet = new Set<string>()\n const whiteSet = new Set<string>()\n\n try {\n await Promise.all([\n config.whiteListJson\n ? fetch(config.whiteListJson)\n .then(r => r.json())\n .then((arr: string[]) => {\n arr.forEach(s => whiteSet.add(s.toLowerCase()))\n })\n : null,\n config.blackListJson\n ? fetch(config.blackListJson)\n .then(r => r.json())\n .then((arr: string[]) => {\n arr.forEach(s => {\n const lower = s.toLowerCase()\n if (isPunct(lower)) blackJsonPunctSet.add(lower)\n else blackJsonWordSet.add(lower)\n })\n })\n : null,\n ])\n globalResolved = {\n ...globalResolved,\n blackJsonPunctSet,\n blackJsonWordSet,\n whiteSet,\n }\n return { success: true }\n } catch (error) {\n return { success: false, error }\n }\n}\n\nconst resolveConfig = (config?: ClarityUtilsConfig): ResolvedConfig => {\n const merged = { ...globalResolved, ...(config ?? {}) }\n merged.blackPunctSet = new Set([...(merged.blackJsonPunctSet ?? [])])\n merged.blackWordSet = new Set([...(merged.blackJsonWordSet ?? [])])\n merged.blackList?.forEach(s => {\n const lower = s.toLowerCase()\n if (isPunct(lower)) {\n merged.blackPunctSet?.add(lower)\n } else {\n merged.blackWordSet?.add(lower)\n }\n })\n\n if (merged.scoreQuestionWords)\n merged.scoreQuestionWords = merged.scoreQuestionWords.map(s => s.toLowerCase())\n if (merged.scorePronouns) merged.scorePronouns = merged.scorePronouns.map(s => s.toLowerCase())\n if (merged.scoreCommonVerbs) merged.scoreCommonVerbs = merged.scoreCommonVerbs.map(s => s.toLowerCase())\n if (merged.scoreStopwords) merged.scoreStopwords = merged.scoreStopwords.map(s => s.toLowerCase())\n\n return merged\n}\n\nconst isSearch = (value: string, config?: ClarityUtilsConfig): boolean => {\n const c = resolveConfig(config)\n const lower = value.toLowerCase()\n\n const tokens = tokenize(lower)\n console.group(`[isSearch] \"${value}\" | mode=${c.mode} | tokens=[${tokens.join(', ')}]`)\n if (c.mode === 'mixed' || c.mode === 'list') {\n console.log(\n `lists: blackWordSet=${c.blackWordSet?.size ?? 0} blackPunctSet=${c.blackPunctSet?.size ?? 0} whiteSet=${c.whiteSet?.size ?? 0} whiteList=${c.whiteList?.length ?? 0}`\n )\n }\n\n let result: boolean\n if (c.mode === 'length') {\n result = checkLength(lower, c)\n } else if (c.mode === 'mixed') {\n result = checkList(lower, c) && checkLength(lower, c)\n } else if (c.mode === 'score') {\n result = scoreQuery(lower, c)\n } else {\n result = scoreQuery(lower, c)\n }\n\n console.log(`→ Result: ${result}`)\n console.groupEnd()\n return result\n}\n\nexport const clarityUtils = { setup, isSearch }\n","export const isPunct = (s: string) => !/\\w/.test(s)\n\nconst CONTRACTIONS: Record<string, string> = {\n \"won't\": 'will not',\n \"can't\": 'cannot',\n \"don't\": 'do not',\n \"doesn't\": 'does not',\n \"didn't\": 'did not',\n \"isn't\": 'is not',\n \"aren't\": 'are not',\n \"wasn't\": 'was not',\n \"weren't\": 'were not',\n \"haven't\": 'have not',\n \"hasn't\": 'has not',\n \"hadn't\": 'had not',\n \"wouldn't\": 'would not',\n \"shouldn't\": 'should not',\n \"couldn't\": 'could not',\n \"what's\": 'what is',\n \"what're\": 'what are',\n \"how's\": 'how is',\n \"where's\": 'where is',\n \"who's\": 'who is',\n \"that's\": 'that is',\n \"there's\": 'there is',\n \"it's\": 'it is',\n \"i'm\": 'i am',\n \"i'd\": 'i would',\n \"i'll\": 'i will',\n \"i've\": 'i have',\n \"we're\": 'we are',\n \"we've\": 'we have',\n \"we'd\": 'we would',\n \"they're\": 'they are',\n \"they've\": 'they have',\n \"you're\": 'you are',\n \"you've\": 'you have',\n \"you'd\": 'you would',\n}\n\nconst expandContractions = (query: string) =>\n query.replace(/[\\w']+/g, word => CONTRACTIONS[word] ?? word)\n\nexport const tokenize = (query: string) =>\n expandContractions(query).split(/\\s+/).filter(Boolean)\n","import type { ResolvedConfig } from '../types'\nimport { tokenize } from '../utils'\n\nexport const checkLength = (value: string, c: ResolvedConfig): boolean => {\n if (!c.maxLength) {\n console.log(' checkLength → true (no maxLength configured)')\n return true\n }\n const wordCount = tokenize(value).length\n const result = wordCount <= c.maxLength\n console.log(` checkLength → ${result} (wordCount=${wordCount} maxLength=${c.maxLength})`)\n return result\n}\n","import type { ResolvedConfig } from '../types'\nimport { tokenize } from '../utils'\n\nconst checkPuncts = (lower: string, c: ResolvedConfig): boolean => {\n for (const punct of c.blackPunctSet ?? []) {\n if (lower.includes(punct)) {\n console.log(` punct \"${punct}\" found in sentence → false (blacklisted)`)\n return false\n }\n }\n return true\n}\n\nconst checkWord = (word: string, c: ResolvedConfig): boolean => {\n if (c.blackWordSet?.has(word)) {\n console.log(` word \"${word}\" → false (blacklisted)`)\n return false\n }\n const hasWhite = (c.whiteSet?.size ?? 0) > 0 || (c.whiteList?.length ?? 0) > 0\n if (hasWhite) {\n const result = !!(c.whiteSet?.has(word) || c.whiteList?.some((s: string) => s.toLowerCase() === word))\n console.log(` word \"${word}\" → ${result} (whitelist check)`)\n return result\n }\n console.log(` word \"${word}\" → true`)\n return true\n}\n\nexport const checkList = (lower: string, c: ResolvedConfig): boolean =>\n checkPuncts(lower, c) && tokenize(lower).every(word => checkWord(word, c))\n","export const DEFAULT_QUESTION_WORDS = [\n 'who',\n 'what',\n 'when',\n 'where',\n 'why',\n 'how',\n 'which',\n 'can',\n 'should',\n 'could',\n 'would',\n 'will',\n 'have',\n 'has',\n 'is',\n 'are',\n 'do',\n 'does',\n 'did',\n]\n\nexport const DEFAULT_PRONOUNS = [\n 'i',\n 'me',\n 'my',\n 'mine',\n 'we',\n 'us',\n 'our',\n 'you',\n 'your',\n 'it',\n 'he',\n 'him',\n 'his',\n 'she',\n 'her',\n 'they',\n 'them',\n 'their',\n]\n\nexport const DEFAULT_COMMON_VERBS = [\n 'is',\n 'are',\n 'was',\n 'were',\n 'do',\n 'does',\n 'did',\n 'have',\n 'need',\n 'want',\n 'look',\n 'help',\n 'know',\n 'think',\n 'make',\n 'create',\n 'find',\n 'get',\n 'buy',\n 'use',\n 'install',\n 'fix',\n 'recommend',\n 'tell',\n 'show',\n 'compare',\n 'explain',\n]\n\nexport const DEFAULT_STOPWORDS = [\n 'the',\n 'a',\n 'an',\n 'i',\n 'me',\n 'my',\n 'is',\n 'it',\n 'in',\n 'on',\n 'at',\n 'to',\n 'for',\n 'of',\n 'and',\n 'or',\n 'but',\n 'not',\n 'so',\n 'if',\n 'by',\n 'with',\n 'from',\n 'that',\n 'this',\n 'about',\n]\n","import { DEFAULT_COMMON_VERBS, DEFAULT_PRONOUNS, DEFAULT_QUESTION_WORDS, DEFAULT_STOPWORDS } from '../enums'\nimport type { ResolvedConfig } from '../types'\nimport { tokenize } from '../utils'\n\nexport const scoreQuery = (query: string, c: ResolvedConfig): boolean => {\n const tokens = tokenize(query)\n if (tokens.length === 0) return true\n\n const questionWords = c.scoreQuestionWords ?? DEFAULT_QUESTION_WORDS\n const pronouns = c.scorePronouns ?? DEFAULT_PRONOUNS\n const commonVerbs = c.scoreCommonVerbs ?? DEFAULT_COMMON_VERBS\n const stopwords = c.scoreStopwords ?? DEFAULT_STOPWORDS\n\n let scoreKeyword = 0\n let scoreConversational = 0\n\n if (tokens.length <= 3) {\n scoreKeyword += 2\n console.log(` [A] token count: word count=${tokens.length} ≤3 → keyword +2`)\n } else if (tokens.length >= 6) {\n scoreConversational += 2\n console.log(` [A] token count: word count=${tokens.length} ≥6 → conversational +2`)\n } else {\n console.log(` [A] token count: word count=${tokens.length} (no score)`)\n }\n\n const matchedQuestionWords = tokens.filter(t => questionWords.includes(t))\n if (matchedQuestionWords.length > 0) {\n scoreConversational += 2\n console.log(` [B] question words: found [${matchedQuestionWords.join(', ')}] → conversational +2`)\n } else {\n console.log(` [B] question words: none`)\n }\n\n const matchedPronouns = tokens.filter(t => pronouns.includes(t))\n if (matchedPronouns.length > 0) {\n scoreConversational += 1\n console.log(` [C] pronouns: found [${matchedPronouns.join(', ')}] → conversational +1`)\n } else {\n console.log(` [C] pronouns: none`)\n }\n\n const matchedVerbs = tokens.filter(t => commonVerbs.includes(t))\n if (matchedVerbs.length > 0) {\n scoreConversational += 1\n console.log(` [D] common verbs: found [${matchedVerbs.join(', ')}] → conversational +1`)\n } else {\n console.log(` [D] common verbs: none`)\n }\n\n if (query.includes('?')) {\n scoreConversational += 3\n console.log(` [E] question mark: found → conversational +3`)\n } else {\n console.log(` [E] question mark: none`)\n }\n\n const stopwordCount = tokens.filter(t => stopwords.includes(t)).length\n const stopwordRatio = stopwordCount / tokens.length\n if (stopwordRatio > 0.4) {\n scoreConversational += 2\n console.log(\n ` [F] stopword ratio: ${stopwordRatio.toFixed(2)} (${stopwordCount}/${tokens.length}) >0.4 → conversational +2`\n )\n } else {\n scoreKeyword += 1\n console.log(\n ` [F] stopword ratio: ${stopwordRatio.toFixed(2)} (${stopwordCount}/${tokens.length}) ≤0.4 → keyword +1`\n )\n }\n\n const avgLen = tokens.reduce((sum, t) => sum + t.length, 0) / tokens.length\n if (avgLen >= 6) {\n scoreKeyword += 1\n console.log(` [G] avg token length: ${avgLen.toFixed(2)} ≥6 → keyword +1`)\n } else {\n console.log(` [G] avg token length: ${avgLen.toFixed(2)} (no score)`)\n }\n\n const result = scoreKeyword >= scoreConversational\n console.log(\n ` scores: keyword=${scoreKeyword} conversational=${scoreConversational} → ${result ? 'keyword' : 'conversational'}`\n )\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,UAAU,CAAC,MAAc,CAAC,KAAK,KAAK,CAAC;AAElD,IAAM,eAAuC;AAAA,EAC3C,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,WAAW;AAAA,EACX,UAAU;AAAA,EACV,SAAS;AAAA,EACT,UAAU;AAAA,EACV,UAAU;AAAA,EACV,WAAW;AAAA,EACX,WAAW;AAAA,EACX,UAAU;AAAA,EACV,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,UAAU;AAAA,EACV,WAAW;AAAA,EACX,SAAS;AAAA,EACT,WAAW;AAAA,EACX,SAAS;AAAA,EACT,UAAU;AAAA,EACV,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,WAAW;A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S;","names":["_a","_b"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/utils.ts","../src/modes/length.ts","../src/modes/list.ts","../src/enums.ts","../src/modes/score.ts"],"sourcesContent":["import { checkLength } from './modes/length'\nimport { checkList } from './modes/list'\nimport { scoreQuery } from './modes/score'\nimport type { ClarityUtilsConfig, ResolvedConfig } from './types'\nimport { isPunct, tokenize } from './utils'\n\nlet globalResolved: ResolvedConfig = {}\n\nconst setup = async (\n config: ClarityUtilsConfig\n): Promise<{ success: true } | { success: false; error: unknown }> => {\n globalResolved = { ...config }\n const blackJsonPunctSet = new Set<string>()\n const blackJsonWordSet = new Set<string>()\n const whiteSet = new Set<string>()\n\n try {\n await Promise.all([\n config.whiteListJson\n ? fetch(config.whiteListJson)\n .then(r => r.json())\n .then((arr: string[]) => {\n arr.forEach(s => whiteSet.add(s.toLowerCase()))\n })\n : null,\n config.blackListJson\n ? fetch(config.blackListJson)\n .then(r => r.json())\n .then((arr: string[]) => {\n arr.forEach(s => {\n const lower = s.toLowerCase()\n if (isPunct(lower)) blackJsonPunctSet.add(lower)\n else blackJsonWordSet.add(lower)\n })\n })\n : null,\n ])\n globalResolved = {\n ...globalResolved,\n blackJsonPunctSet,\n blackJsonWordSet,\n whiteSet,\n }\n return { success: true }\n } catch (error) {\n return { success: false, error }\n }\n}\n\nconst resolveConfig = (config?: ClarityUtilsConfig): ResolvedConfig => {\n const merged = { ...globalResolved, ...(config ?? {}) }\n merged.blackPunctSet = new Set([...(merged.blackJsonPunctSet ?? [])])\n merged.blackWordSet = new Set([...(merged.blackJsonWordSet ?? [])])\n merged.blackList?.forEach(s => {\n const lower = s.toLowerCase()\n if (isPunct(lower)) {\n merged.blackPunctSet?.add(lower)\n } else {\n merged.blackWordSet?.add(lower)\n }\n })\n\n if (merged.scoreQuestionWords)\n merged.scoreQuestionWords = merged.scoreQuestionWords.map(s => s.toLowerCase())\n if (merged.scorePronouns) merged.scorePronouns = merged.scorePronouns.map(s => s.toLowerCase())\n if (merged.scoreCommonVerbs) merged.scoreCommonVerbs = merged.scoreCommonVerbs.map(s => s.toLowerCase())\n if (merged.scoreStopwords) merged.scoreStopwords = merged.scoreStopwords.map(s => s.toLowerCase())\n if (merged.scoreSupportWords) merged.scoreSupportWords = merged.scoreSupportWords.map(s => s.toLowerCase())\n\n return merged\n}\n\nconst isSearch = (value: string, config?: ClarityUtilsConfig): boolean => {\n const c = resolveConfig(config)\n const lower = value.toLowerCase()\n\n const tokens = tokenize(lower)\n console.group(`[isSearch] \"${value}\" | mode=${c.mode} | tokens=[${tokens.join(', ')}]`)\n if (c.mode === 'mixed' || c.mode === 'list') {\n console.log(\n `lists: blackWordSet=${c.blackWordSet?.size ?? 0} blackPunctSet=${c.blackPunctSet?.size ?? 0} whiteSet=${c.whiteSet?.size ?? 0} whiteList=${c.whiteList?.length ?? 0}`\n )\n }\n\n let result: boolean\n if (c.mode === 'length') {\n result = checkLength(lower, c)\n } else if (c.mode === 'mixed') {\n result = checkList(lower, c) && checkLength(lower, c)\n } else if (c.mode === 'score') {\n result = scoreQuery(lower, c)\n } else {\n result = scoreQuery(lower, c)\n }\n\n console.log(`→ Result: ${result}`)\n console.groupEnd()\n return result\n}\n\nexport const clarityUtils = { setup, isSearch }\n","export const isPunct = (s: string) => !/\\w/.test(s)\n\nconst CONTRACTIONS: Record<string, string> = {\n \"won't\": 'will not',\n \"can't\": 'cannot',\n \"don't\": 'do not',\n \"doesn't\": 'does not',\n \"didn't\": 'did not',\n \"isn't\": 'is not',\n \"aren't\": 'are not',\n \"wasn't\": 'was not',\n \"weren't\": 'were not',\n \"haven't\": 'have not',\n \"hasn't\": 'has not',\n \"hadn't\": 'had not',\n \"wouldn't\": 'would not',\n \"shouldn't\": 'should not',\n \"couldn't\": 'could not',\n \"what's\": 'what is',\n \"what're\": 'what are',\n \"how's\": 'how is',\n \"where's\": 'where is',\n \"who's\": 'who is',\n \"that's\": 'that is',\n \"there's\": 'there is',\n \"it's\": 'it is',\n \"i'm\": 'i am',\n \"i'd\": 'i would',\n \"i'll\": 'i will',\n \"i've\": 'i have',\n \"we're\": 'we are',\n \"we've\": 'we have',\n \"we'd\": 'we would',\n \"they're\": 'they are',\n \"they've\": 'they have',\n \"you're\": 'you are',\n \"you've\": 'you have',\n \"you'd\": 'you would',\n}\n\nconst expandContractions = (query: string) => query.replace(/[\\w']+/g, word => CONTRACTIONS[word] ?? word)\n\nexport const tokenize = (query: string) => expandContractions(query).split(/\\s+/).filter(Boolean)\n","import type { ResolvedConfig } from '../types'\nimport { tokenize } from '../utils'\n\nexport const checkLength = (value: string, c: ResolvedConfig): boolean => {\n if (!c.maxLength) {\n console.log(' checkLength → true (no maxLength configured)')\n return true\n }\n const wordCount = tokenize(value).length\n const result = wordCount <= c.maxLength\n console.log(` checkLength → ${result} (wordCount=${wordCount} maxLength=${c.maxLength})`)\n return result\n}\n","import type { ResolvedConfig } from '../types'\nimport { tokenize } from '../utils'\n\nconst checkPuncts = (lower: string, c: ResolvedConfig): boolean => {\n for (const punct of c.blackPunctSet ?? []) {\n if (lower.includes(punct)) {\n console.log(` punct \"${punct}\" found in sentence → false (blacklisted)`)\n return false\n }\n }\n return true\n}\n\nconst checkWord = (word: string, c: ResolvedConfig): boolean => {\n if (c.blackWordSet?.has(word)) {\n console.log(` word \"${word}\" → false (blacklisted)`)\n return false\n }\n const hasWhite = (c.whiteSet?.size ?? 0) > 0 || (c.whiteList?.length ?? 0) > 0\n if (hasWhite) {\n const result = !!(c.whiteSet?.has(word) || c.whiteList?.some((s: string) => s.toLowerCase() === word))\n console.log(` word \"${word}\" → ${result} (whitelist check)`)\n return result\n }\n console.log(` word \"${word}\" → true`)\n return true\n}\n\nexport const checkList = (lower: string, c: ResolvedConfig): boolean =>\n checkPuncts(lower, c) && tokenize(lower).every(word => checkWord(word, c))\n","export const DEFAULT_SUPPORT_WORDS = [\n // Orders / tracking / delivery\n 'order',\n 'package',\n 'shipment',\n 'tracking',\n 'delivery',\n 'delayed',\n 'late',\n 'lost',\n 'missing',\n 'cancel',\n 'modify',\n\n // Returns / refunds / exchanges\n 'return',\n 'exchange',\n 'refund',\n 'replacement',\n 'eligible',\n 'eligibility',\n // 'money back',\n\n // Product issues\n 'warranty',\n 'damaged',\n 'broken',\n 'defective',\n 'wrong',\n 'incorrect',\n\n // Account / login\n 'password',\n 'login',\n // 'sign in',\n 'account',\n 'locked',\n 'verification',\n 'otp',\n\n // Loyalty / promos / gift cards\n 'loyalty',\n 'rewards',\n 'points',\n 'promo',\n 'coupon',\n 'discount',\n 'gift',\n\n // Shipping / payments / billing\n 'shipping',\n 'payment',\n 'billing',\n 'charged',\n 'charge',\n 'invoice',\n 'receipt',\n 'declined',\n\n // Product info / sizing / inventory\n 'size',\n 'sizing',\n 'fit',\n 'care',\n 'stock',\n 'restock',\n 'availability',\n\n // Company / policy\n 'sustainability',\n 'ethics',\n 'careers',\n 'privacy',\n 'terms',\n\n // Human support\n 'agent',\n 'representative',\n 'support',\n 'human',\n 'talk',\n 'speak',\n 'help',\n\n // Technical / service issues\n 'api',\n 'failure',\n 'server',\n 'technical',\n 'website',\n 'checkout',\n 'app',\n 'something',\n]\n\nexport const DEFAULT_QUESTION_WORDS = [\n 'who',\n 'what',\n 'when',\n 'where',\n 'why',\n 'how',\n 'which',\n 'can',\n 'should',\n 'could',\n 'would',\n 'will',\n 'have',\n 'has',\n 'is',\n 'are',\n 'do',\n 'does',\n 'did',\n]\n\nexport const DEFAULT_PRONOUNS = [\n 'i',\n 'me',\n 'my',\n 'mine',\n 'we',\n 'us',\n 'our',\n 'you',\n 'your',\n 'it',\n 'he',\n 'him',\n 'his',\n 'she',\n 'her',\n 'they',\n 'them',\n 'their',\n]\n\nexport const DEFAULT_COMMON_VERBS = [\n 'is',\n 'are',\n 'was',\n 'were',\n 'do',\n 'does',\n 'did',\n 'have',\n 'need',\n 'want',\n 'look',\n 'help',\n 'know',\n 'think',\n 'make',\n 'create',\n 'find',\n 'get',\n 'buy',\n 'use',\n 'install',\n 'fix',\n 'recommend',\n 'tell',\n 'show',\n 'compare',\n 'explain',\n]\n\nexport const DEFAULT_STOPWORDS = [\n 'the',\n 'a',\n 'an',\n 'i',\n 'me',\n 'my',\n 'is',\n 'it',\n 'in',\n 'on',\n 'at',\n 'to',\n 'for',\n 'of',\n 'and',\n 'or',\n 'but',\n 'not',\n 'so',\n 'if',\n 'by',\n 'with',\n 'from',\n 'that',\n 'this',\n 'about',\n]\n","import {\n DEFAULT_COMMON_VERBS,\n DEFAULT_PRONOUNS,\n DEFAULT_QUESTION_WORDS,\n DEFAULT_STOPWORDS,\n DEFAULT_SUPPORT_WORDS,\n} from '../enums'\nimport type { ResolvedConfig } from '../types'\nimport { tokenize } from '../utils'\n\nexport const scoreQuery = (query: string, c: ResolvedConfig): boolean => {\n const tokens = tokenize(query)\n if (tokens.length === 0) return true\n\n const questionWords = c.scoreQuestionWords ?? DEFAULT_QUESTION_WORDS\n const pronouns = c.scorePronouns ?? DEFAULT_PRONOUNS\n const commonVerbs = c.scoreCommonVerbs ?? DEFAULT_COMMON_VERBS\n const stopwords = c.scoreStopwords ?? DEFAULT_STOPWORDS\n const supportWords = c.scoreSupportWords ?? DEFAULT_SUPPORT_WORDS\n\n const matchedSupportWords = tokens.filter(t => supportWords.includes(t))\n if (matchedSupportWords.length > 0) {\n console.log(` [H] support words: found [${matchedSupportWords.join(', ')}] → conversational (override)`)\n return false\n }\n\n let scoreKeyword = 0\n let scoreConversational = 0\n\n if (tokens.length <= 3) {\n scoreKeyword += 2\n console.log(` [A] token count: word count=${tokens.length} ≤3 → keyword +2`)\n } else if (tokens.length >= 6) {\n scoreConversational += 2\n console.log(` [A] token count: word count=${tokens.length} ≥6 → conversational +2`)\n } else {\n console.log(` [A] token count: word count=${tokens.length} (no score)`)\n }\n\n const matchedQuestionWords = tokens.filter(t => questionWords.includes(t))\n if (matchedQuestionWords.length > 0) {\n scoreConversational += 2\n console.log(` [B] question words: found [${matchedQuestionWords.join(', ')}] → conversational +2`)\n } else {\n console.log(` [B] question words: none`)\n }\n\n const matchedPronouns = tokens.filter(t => pronouns.includes(t))\n if (matchedPronouns.length > 0) {\n scoreConversational += 1\n console.log(` [C] pronouns: found [${matchedPronouns.join(', ')}] → conversational +1`)\n } else {\n console.log(` [C] pronouns: none`)\n }\n\n const matchedVerbs = tokens.filter(t => commonVerbs.includes(t))\n if (matchedVerbs.length > 0) {\n scoreConversational += 1\n console.log(` [D] common verbs: found [${matchedVerbs.join(', ')}] → conversational +1`)\n } else {\n console.log(` [D] common verbs: none`)\n }\n\n if (query.includes('?')) {\n scoreConversational += 3\n console.log(` [E] question mark: found → conversational +3`)\n } else {\n console.log(` [E] question mark: none`)\n }\n\n const stopwordCount = tokens.filter(t => stopwords.includes(t)).length\n const stopwordRatio = stopwordCount / tokens.length\n if (stopwordRatio > 0.4) {\n scoreConversational += 2\n console.log(\n ` [F] stopword ratio: ${stopwordRatio.toFixed(2)} (${stopwordCount}/${tokens.length}) >0.4 → conversational +2`\n )\n } else {\n scoreKeyword += 1\n console.log(\n ` [F] stopword ratio: ${stopwordRatio.toFixed(2)} (${stopwordCount}/${tokens.length}) ≤0.4 → keyword +1`\n )\n }\n\n const avgLen = tokens.reduce((sum, t) => sum + t.length, 0) / tokens.length\n if (avgLen >= 6) {\n scoreKeyword += 1\n console.log(` [G] avg token length: ${avgLen.toFixed(2)} ≥6 → keyword +1`)\n } else {\n console.log(` [G] avg token length: ${avgLen.toFixed(2)} (no score)`)\n }\n\n const result = scoreKeyword >= scoreConversational\n console.log(\n ` scores: keyword=${scoreKeyword} conversational=${scoreConversational} → ${result ? 'keyword' : 'conversational'}`\n )\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,UAAU,CAAC,MAAc,CAAC,KAAK,KAAK,CAAC;AAElD,IAAM,eAAuC;AAAA,EAC3C,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,WAAW;AAAA,EACX,UAA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AAA,IACtK;AAAA,EACF;AAEA,MAAI;AACJ,MAAI,EAAE,SAAS,UAAU;AACvB,aAAS,YAAY,OAAO,CAAC;AAAA,EAC/B,WAAW,EAAE,SAAS,SAAS;AAC7B,aAAS,UAAU,OAAO,CAAC,KAAK,YAAY,OAAO,CAAC;AAAA,EACtD,WAAW,EAAE,SAAS,SAAS;AAC7B,aAAS,WAAW,OAAO,CAAC;AAAA,EAC9B,OAAO;AACL,aAAS,WAAW,OAAO,CAAC;AAAA,EAC9B;AAEA,UAAQ,IAAI,kBAAa,MAAM,EAAE;AACjC,UAAQ,SAAS;AACjB,SAAO;AACT;AAEO,IAAM,eAAe,EAAE,OAAO,SAAS;","names":["_a","_b"]}
|
package/dist/index.mjs
CHANGED
|
@@ -84,6 +84,91 @@ var checkWord = (word, c) => {
|
|
|
84
84
|
var checkList = (lower, c) => checkPuncts(lower, c) && tokenize(lower).every((word) => checkWord(word, c));
|
|
85
85
|
|
|
86
86
|
// src/enums.ts
|
|
87
|
+
var DEFAULT_SUPPORT_WORDS = [
|
|
88
|
+
// Orders / tracking / delivery
|
|
89
|
+
"order",
|
|
90
|
+
"package",
|
|
91
|
+
"shipment",
|
|
92
|
+
"tracking",
|
|
93
|
+
"delivery",
|
|
94
|
+
"delayed",
|
|
95
|
+
"late",
|
|
96
|
+
"lost",
|
|
97
|
+
"missing",
|
|
98
|
+
"cancel",
|
|
99
|
+
"modify",
|
|
100
|
+
// Returns / refunds / exchanges
|
|
101
|
+
"return",
|
|
102
|
+
"exchange",
|
|
103
|
+
"refund",
|
|
104
|
+
"replacement",
|
|
105
|
+
"eligible",
|
|
106
|
+
"eligibility",
|
|
107
|
+
// 'money back',
|
|
108
|
+
// Product issues
|
|
109
|
+
"warranty",
|
|
110
|
+
"damaged",
|
|
111
|
+
"broken",
|
|
112
|
+
"defective",
|
|
113
|
+
"wrong",
|
|
114
|
+
"incorrect",
|
|
115
|
+
// Account / login
|
|
116
|
+
"password",
|
|
117
|
+
"login",
|
|
118
|
+
// 'sign in',
|
|
119
|
+
"account",
|
|
120
|
+
"locked",
|
|
121
|
+
"verification",
|
|
122
|
+
"otp",
|
|
123
|
+
// Loyalty / promos / gift cards
|
|
124
|
+
"loyalty",
|
|
125
|
+
"rewards",
|
|
126
|
+
"points",
|
|
127
|
+
"promo",
|
|
128
|
+
"coupon",
|
|
129
|
+
"discount",
|
|
130
|
+
"gift",
|
|
131
|
+
// Shipping / payments / billing
|
|
132
|
+
"shipping",
|
|
133
|
+
"payment",
|
|
134
|
+
"billing",
|
|
135
|
+
"charged",
|
|
136
|
+
"charge",
|
|
137
|
+
"invoice",
|
|
138
|
+
"receipt",
|
|
139
|
+
"declined",
|
|
140
|
+
// Product info / sizing / inventory
|
|
141
|
+
"size",
|
|
142
|
+
"sizing",
|
|
143
|
+
"fit",
|
|
144
|
+
"care",
|
|
145
|
+
"stock",
|
|
146
|
+
"restock",
|
|
147
|
+
"availability",
|
|
148
|
+
// Company / policy
|
|
149
|
+
"sustainability",
|
|
150
|
+
"ethics",
|
|
151
|
+
"careers",
|
|
152
|
+
"privacy",
|
|
153
|
+
"terms",
|
|
154
|
+
// Human support
|
|
155
|
+
"agent",
|
|
156
|
+
"representative",
|
|
157
|
+
"support",
|
|
158
|
+
"human",
|
|
159
|
+
"talk",
|
|
160
|
+
"speak",
|
|
161
|
+
"help",
|
|
162
|
+
// Technical / service issues
|
|
163
|
+
"api",
|
|
164
|
+
"failure",
|
|
165
|
+
"server",
|
|
166
|
+
"technical",
|
|
167
|
+
"website",
|
|
168
|
+
"checkout",
|
|
169
|
+
"app",
|
|
170
|
+
"something"
|
|
171
|
+
];
|
|
87
172
|
var DEFAULT_QUESTION_WORDS = [
|
|
88
173
|
"who",
|
|
89
174
|
"what",
|
|
@@ -185,13 +270,19 @@ var DEFAULT_STOPWORDS = [
|
|
|
185
270
|
|
|
186
271
|
// src/modes/score.ts
|
|
187
272
|
var scoreQuery = (query, c) => {
|
|
188
|
-
var _a, _b, _c, _d;
|
|
273
|
+
var _a, _b, _c, _d, _e;
|
|
189
274
|
const tokens = tokenize(query);
|
|
190
275
|
if (tokens.length === 0) return true;
|
|
191
276
|
const questionWords = (_a = c.scoreQuestionWords) != null ? _a : DEFAULT_QUESTION_WORDS;
|
|
192
277
|
const pronouns = (_b = c.scorePronouns) != null ? _b : DEFAULT_PRONOUNS;
|
|
193
278
|
const commonVerbs = (_c = c.scoreCommonVerbs) != null ? _c : DEFAULT_COMMON_VERBS;
|
|
194
279
|
const stopwords = (_d = c.scoreStopwords) != null ? _d : DEFAULT_STOPWORDS;
|
|
280
|
+
const supportWords = (_e = c.scoreSupportWords) != null ? _e : DEFAULT_SUPPORT_WORDS;
|
|
281
|
+
const matchedSupportWords = tokens.filter((t) => supportWords.includes(t));
|
|
282
|
+
if (matchedSupportWords.length > 0) {
|
|
283
|
+
console.log(` [H] support words: found [${matchedSupportWords.join(", ")}] \u2192 conversational (override)`);
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
195
286
|
let scoreKeyword = 0;
|
|
196
287
|
let scoreConversational = 0;
|
|
197
288
|
if (tokens.length <= 3) {
|
|
@@ -307,6 +398,7 @@ var resolveConfig = (config) => {
|
|
|
307
398
|
if (merged.scorePronouns) merged.scorePronouns = merged.scorePronouns.map((s) => s.toLowerCase());
|
|
308
399
|
if (merged.scoreCommonVerbs) merged.scoreCommonVerbs = merged.scoreCommonVerbs.map((s) => s.toLowerCase());
|
|
309
400
|
if (merged.scoreStopwords) merged.scoreStopwords = merged.scoreStopwords.map((s) => s.toLowerCase());
|
|
401
|
+
if (merged.scoreSupportWords) merged.scoreSupportWords = merged.scoreSupportWords.map((s) => s.toLowerCase());
|
|
310
402
|
return merged;
|
|
311
403
|
};
|
|
312
404
|
var isSearch = (value, config) => {
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils.ts","../src/modes/length.ts","../src/modes/list.ts","../src/enums.ts","../src/modes/score.ts","../src/index.ts"],"sourcesContent":["export const isPunct = (s: string) => !/\\w/.test(s)\n\nconst CONTRACTIONS: Record<string, string> = {\n \"won't\": 'will not',\n \"can't\": 'cannot',\n \"don't\": 'do not',\n \"doesn't\": 'does not',\n \"didn't\": 'did not',\n \"isn't\": 'is not',\n \"aren't\": 'are not',\n \"wasn't\": 'was not',\n \"weren't\": 'were not',\n \"haven't\": 'have not',\n \"hasn't\": 'has not',\n \"hadn't\": 'had not',\n \"wouldn't\": 'would not',\n \"shouldn't\": 'should not',\n \"couldn't\": 'could not',\n \"what's\": 'what is',\n \"what're\": 'what are',\n \"how's\": 'how is',\n \"where's\": 'where is',\n \"who's\": 'who is',\n \"that's\": 'that is',\n \"there's\": 'there is',\n \"it's\": 'it is',\n \"i'm\": 'i am',\n \"i'd\": 'i would',\n \"i'll\": 'i will',\n \"i've\": 'i have',\n \"we're\": 'we are',\n \"we've\": 'we have',\n \"we'd\": 'we would',\n \"they're\": 'they are',\n \"they've\": 'they have',\n \"you're\": 'you are',\n \"you've\": 'you have',\n \"you'd\": 'you would',\n}\n\nconst expandContractions = (query: string) =>\n query.replace(/[\\w']+/g, word => CONTRACTIONS[word] ?? word)\n\nexport const tokenize = (query: string) =>\n expandContractions(query).split(/\\s+/).filter(Boolean)\n","import type { ResolvedConfig } from '../types'\nimport { tokenize } from '../utils'\n\nexport const checkLength = (value: string, c: ResolvedConfig): boolean => {\n if (!c.maxLength) {\n console.log(' checkLength → true (no maxLength configured)')\n return true\n }\n const wordCount = tokenize(value).length\n const result = wordCount <= c.maxLength\n console.log(` checkLength → ${result} (wordCount=${wordCount} maxLength=${c.maxLength})`)\n return result\n}\n","import type { ResolvedConfig } from '../types'\nimport { tokenize } from '../utils'\n\nconst checkPuncts = (lower: string, c: ResolvedConfig): boolean => {\n for (const punct of c.blackPunctSet ?? []) {\n if (lower.includes(punct)) {\n console.log(` punct \"${punct}\" found in sentence → false (blacklisted)`)\n return false\n }\n }\n return true\n}\n\nconst checkWord = (word: string, c: ResolvedConfig): boolean => {\n if (c.blackWordSet?.has(word)) {\n console.log(` word \"${word}\" → false (blacklisted)`)\n return false\n }\n const hasWhite = (c.whiteSet?.size ?? 0) > 0 || (c.whiteList?.length ?? 0) > 0\n if (hasWhite) {\n const result = !!(c.whiteSet?.has(word) || c.whiteList?.some((s: string) => s.toLowerCase() === word))\n console.log(` word \"${word}\" → ${result} (whitelist check)`)\n return result\n }\n console.log(` word \"${word}\" → true`)\n return true\n}\n\nexport const checkList = (lower: string, c: ResolvedConfig): boolean =>\n checkPuncts(lower, c) && tokenize(lower).every(word => checkWord(word, c))\n","export const DEFAULT_QUESTION_WORDS = [\n 'who',\n 'what',\n 'when',\n 'where',\n 'why',\n 'how',\n 'which',\n 'can',\n 'should',\n 'could',\n 'would',\n 'will',\n 'have',\n 'has',\n 'is',\n 'are',\n 'do',\n 'does',\n 'did',\n]\n\nexport const DEFAULT_PRONOUNS = [\n 'i',\n 'me',\n 'my',\n 'mine',\n 'we',\n 'us',\n 'our',\n 'you',\n 'your',\n 'it',\n 'he',\n 'him',\n 'his',\n 'she',\n 'her',\n 'they',\n 'them',\n 'their',\n]\n\nexport const DEFAULT_COMMON_VERBS = [\n 'is',\n 'are',\n 'was',\n 'were',\n 'do',\n 'does',\n 'did',\n 'have',\n 'need',\n 'want',\n 'look',\n 'help',\n 'know',\n 'think',\n 'make',\n 'create',\n 'find',\n 'get',\n 'buy',\n 'use',\n 'install',\n 'fix',\n 'recommend',\n 'tell',\n 'show',\n 'compare',\n 'explain',\n]\n\nexport const DEFAULT_STOPWORDS = [\n 'the',\n 'a',\n 'an',\n 'i',\n 'me',\n 'my',\n 'is',\n 'it',\n 'in',\n 'on',\n 'at',\n 'to',\n 'for',\n 'of',\n 'and',\n 'or',\n 'but',\n 'not',\n 'so',\n 'if',\n 'by',\n 'with',\n 'from',\n 'that',\n 'this',\n 'about',\n]\n","import { DEFAULT_COMMON_VERBS, DEFAULT_PRONOUNS, DEFAULT_QUESTION_WORDS, DEFAULT_STOPWORDS } from '../enums'\nimport type { ResolvedConfig } from '../types'\nimport { tokenize } from '../utils'\n\nexport const scoreQuery = (query: string, c: ResolvedConfig): boolean => {\n const tokens = tokenize(query)\n if (tokens.length === 0) return true\n\n const questionWords = c.scoreQuestionWords ?? DEFAULT_QUESTION_WORDS\n const pronouns = c.scorePronouns ?? DEFAULT_PRONOUNS\n const commonVerbs = c.scoreCommonVerbs ?? DEFAULT_COMMON_VERBS\n const stopwords = c.scoreStopwords ?? DEFAULT_STOPWORDS\n\n let scoreKeyword = 0\n let scoreConversational = 0\n\n if (tokens.length <= 3) {\n scoreKeyword += 2\n console.log(` [A] token count: word count=${tokens.length} ≤3 → keyword +2`)\n } else if (tokens.length >= 6) {\n scoreConversational += 2\n console.log(` [A] token count: word count=${tokens.length} ≥6 → conversational +2`)\n } else {\n console.log(` [A] token count: word count=${tokens.length} (no score)`)\n }\n\n const matchedQuestionWords = tokens.filter(t => questionWords.includes(t))\n if (matchedQuestionWords.length > 0) {\n scoreConversational += 2\n console.log(` [B] question words: found [${matchedQuestionWords.join(', ')}] → conversational +2`)\n } else {\n console.log(` [B] question words: none`)\n }\n\n const matchedPronouns = tokens.filter(t => pronouns.includes(t))\n if (matchedPronouns.length > 0) {\n scoreConversational += 1\n console.log(` [C] pronouns: found [${matchedPronouns.join(', ')}] → conversational +1`)\n } else {\n console.log(` [C] pronouns: none`)\n }\n\n const matchedVerbs = tokens.filter(t => commonVerbs.includes(t))\n if (matchedVerbs.length > 0) {\n scoreConversational += 1\n console.log(` [D] common verbs: found [${matchedVerbs.join(', ')}] → conversational +1`)\n } else {\n console.log(` [D] common verbs: none`)\n }\n\n if (query.includes('?')) {\n scoreConversational += 3\n console.log(` [E] question mark: found → conversational +3`)\n } else {\n console.log(` [E] question mark: none`)\n }\n\n const stopwordCount = tokens.filter(t => stopwords.includes(t)).length\n const stopwordRatio = stopwordCount / tokens.length\n if (stopwordRatio > 0.4) {\n scoreConversational += 2\n console.log(\n ` [F] stopword ratio: ${stopwordRatio.toFixed(2)} (${stopwordCount}/${tokens.length}) >0.4 → conversational +2`\n )\n } else {\n scoreKeyword += 1\n console.log(\n ` [F] stopword ratio: ${stopwordRatio.toFixed(2)} (${stopwordCount}/${tokens.length}) ≤0.4 → keyword +1`\n )\n }\n\n const avgLen = tokens.reduce((sum, t) => sum + t.length, 0) / tokens.length\n if (avgLen >= 6) {\n scoreKeyword += 1\n console.log(` [G] avg token length: ${avgLen.toFixed(2)} ≥6 → keyword +1`)\n } else {\n console.log(` [G] avg token length: ${avgLen.toFixed(2)} (no score)`)\n }\n\n const result = scoreKeyword >= scoreConversational\n console.log(\n ` scores: keyword=${scoreKeyword} conversational=${scoreConversational} → ${result ? 'keyword' : 'conversational'}`\n )\n return result\n}\n","import { checkLength } from './modes/length'\nimport { checkList } from './modes/list'\nimport { scoreQuery } from './modes/score'\nimport type { ClarityUtilsConfig, ResolvedConfig } from './types'\nimport { isPunct, tokenize } from './utils'\n\nlet globalResolved: ResolvedConfig = {}\n\nconst setup = async (\n config: ClarityUtilsConfig\n): Promise<{ success: true } | { success: false; error: unknown }> => {\n globalResolved = { ...config }\n const blackJsonPunctSet = new Set<string>()\n const blackJsonWordSet = new Set<string>()\n const whiteSet = new Set<string>()\n\n try {\n await Promise.all([\n config.whiteListJson\n ? fetch(config.whiteListJson)\n .then(r => r.json())\n .then((arr: string[]) => {\n arr.forEach(s => whiteSet.add(s.toLowerCase()))\n })\n : null,\n config.blackListJson\n ? fetch(config.blackListJson)\n .then(r => r.json())\n .then((arr: string[]) => {\n arr.forEach(s => {\n const lower = s.toLowerCase()\n if (isPunct(lower)) blackJsonPunctSet.add(lower)\n else blackJsonWordSet.add(lower)\n })\n })\n : null,\n ])\n globalResolved = {\n ...globalResolved,\n blackJsonPunctSet,\n blackJsonWordSet,\n whiteSet,\n }\n return { success: true }\n } catch (error) {\n return { success: false, error }\n }\n}\n\nconst resolveConfig = (config?: ClarityUtilsConfig): ResolvedConfig => {\n const merged = { ...globalResolved, ...(config ?? {}) }\n merged.blackPunctSet = new Set([...(merged.blackJsonPunctSet ?? [])])\n merged.blackWordSet = new Set([...(merged.blackJsonWordSet ?? [])])\n merged.blackList?.forEach(s => {\n const lower = s.toLowerCase()\n if (isPunct(lower)) {\n merged.blackPunctSet?.add(lower)\n } else {\n merged.blackWordSet?.add(lower)\n }\n })\n\n if (merged.scoreQuestionWords)\n merged.scoreQuestionWords = merged.scoreQuestionWords.map(s => s.toLowerCase())\n if (merged.scorePronouns) merged.scorePronouns = merged.scorePronouns.map(s => s.toLowerCase())\n if (merged.scoreCommonVerbs) merged.scoreCommonVerbs = merged.scoreCommonVerbs.map(s => s.toLowerCase())\n if (merged.scoreStopwords) merged.scoreStopwords = merged.scoreStopwords.map(s => s.toLowerCase())\n\n return merged\n}\n\nconst isSearch = (value: string, config?: ClarityUtilsConfig): boolean => {\n const c = resolveConfig(config)\n const lower = value.toLowerCase()\n\n const tokens = tokenize(lower)\n console.group(`[isSearch] \"${value}\" | mode=${c.mode} | tokens=[${tokens.join(', ')}]`)\n if (c.mode === 'mixed' || c.mode === 'list') {\n console.log(\n `lists: blackWordSet=${c.blackWordSet?.size ?? 0} blackPunctSet=${c.blackPunctSet?.size ?? 0} whiteSet=${c.whiteSet?.size ?? 0} whiteList=${c.whiteList?.length ?? 0}`\n )\n }\n\n let result: boolean\n if (c.mode === 'length') {\n result = checkLength(lower, c)\n } else if (c.mode === 'mixed') {\n result = checkList(lower, c) && checkLength(lower, c)\n } else if (c.mode === 'score') {\n result = scoreQuery(lower, c)\n } else {\n result = scoreQuery(lower, c)\n }\n\n console.log(`→ Result: ${result}`)\n console.groupEnd()\n return result\n}\n\nexport const clarityUtils = { setup, isSearch }\n"],"mappings":";AAAO,IAAM,UAAU,CAAC,MAAc,CAAC,KAAK,KAAK,CAAC;AAElD,IAAM,eAAuC;AAAA,EAC3C,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,WAAW;AAAA,EACX,UAAU;AAAA,EACV,SAAS;AAAA,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b,YAAuB,CAAC;AAAA,IACtK;AAAA,EACF;AAEA,MAAI;AACJ,MAAI,EAAE,SAAS,UAAU;AACvB,aAAS,YAAY,OAAO,CAAC;AAAA,EAC/B,WAAW,EAAE,SAAS,SAAS;AAC7B,aAAS,UAAU,OAAO,CAAC,KAAK,YAAY,OAAO,CAAC;AAAA,EACtD,WAAW,EAAE,SAAS,SAAS;AAC7B,aAAS,WAAW,OAAO,CAAC;AAAA,EAC9B,OAAO;AACL,aAAS,WAAW,OAAO,CAAC;AAAA,EAC9B;AAEA,UAAQ,IAAI,kBAAa,MAAM,EAAE;AACjC,UAAQ,SAAS;AACjB,SAAO;AACT;AAEO,IAAM,eAAe,EAAE,OAAO,SAAS;","names":["_a","_b"]}
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts","../src/modes/length.ts","../src/modes/list.ts","../src/enums.ts","../src/modes/score.ts","../src/index.ts"],"sourcesContent":["export const isPunct = (s: string) => !/\\w/.test(s)\n\nconst CONTRACTIONS: Record<string, string> = {\n \"won't\": 'will not',\n \"can't\": 'cannot',\n \"don't\": 'do not',\n \"doesn't\": 'does not',\n \"didn't\": 'did not',\n \"isn't\": 'is not',\n \"aren't\": 'are not',\n \"wasn't\": 'was not',\n \"weren't\": 'were not',\n \"haven't\": 'have not',\n \"hasn't\": 'has not',\n \"hadn't\": 'had not',\n \"wouldn't\": 'would not',\n \"shouldn't\": 'should not',\n \"couldn't\": 'could not',\n \"what's\": 'what is',\n \"what're\": 'what are',\n \"how's\": 'how is',\n \"where's\": 'where is',\n \"who's\": 'who is',\n \"that's\": 'that is',\n \"there's\": 'there is',\n \"it's\": 'it is',\n \"i'm\": 'i am',\n \"i'd\": 'i would',\n \"i'll\": 'i will',\n \"i've\": 'i have',\n \"we're\": 'we are',\n \"we've\": 'we have',\n \"we'd\": 'we would',\n \"they're\": 'they are',\n \"they've\": 'they have',\n \"you're\": 'you are',\n \"you've\": 'you have',\n \"you'd\": 'you would',\n}\n\nconst expandContractions = (query: string) => query.replace(/[\\w']+/g, word => CONTRACTIONS[word] ?? word)\n\nexport const tokenize = (query: string) => expandContractions(query).split(/\\s+/).filter(Boolean)\n","import type { ResolvedConfig } from '../types'\nimport { tokenize } from '../utils'\n\nexport const checkLength = (value: string, c: ResolvedConfig): boolean => {\n if (!c.maxLength) {\n console.log(' checkLength → true (no maxLength configured)')\n return true\n }\n const wordCount = tokenize(value).length\n const result = wordCount <= c.maxLength\n console.log(` checkLength → ${result} (wordCount=${wordCount} maxLength=${c.maxLength})`)\n return result\n}\n","import type { ResolvedConfig } from '../types'\nimport { tokenize } from '../utils'\n\nconst checkPuncts = (lower: string, c: ResolvedConfig): boolean => {\n for (const punct of c.blackPunctSet ?? []) {\n if (lower.includes(punct)) {\n console.log(` punct \"${punct}\" found in sentence → false (blacklisted)`)\n return false\n }\n }\n return true\n}\n\nconst checkWord = (word: string, c: ResolvedConfig): boolean => {\n if (c.blackWordSet?.has(word)) {\n console.log(` word \"${word}\" → false (blacklisted)`)\n return false\n }\n const hasWhite = (c.whiteSet?.size ?? 0) > 0 || (c.whiteList?.length ?? 0) > 0\n if (hasWhite) {\n const result = !!(c.whiteSet?.has(word) || c.whiteList?.some((s: string) => s.toLowerCase() === word))\n console.log(` word \"${word}\" → ${result} (whitelist check)`)\n return result\n }\n console.log(` word \"${word}\" → true`)\n return true\n}\n\nexport const checkList = (lower: string, c: ResolvedConfig): boolean =>\n checkPuncts(lower, c) && tokenize(lower).every(word => checkWord(word, c))\n","export const DEFAULT_SUPPORT_WORDS = [\n // Orders / tracking / delivery\n 'order',\n 'package',\n 'shipment',\n 'tracking',\n 'delivery',\n 'delayed',\n 'late',\n 'lost',\n 'missing',\n 'cancel',\n 'modify',\n\n // Returns / refunds / exchanges\n 'return',\n 'exchange',\n 'refund',\n 'replacement',\n 'eligible',\n 'eligibility',\n // 'money back',\n\n // Product issues\n 'warranty',\n 'damaged',\n 'broken',\n 'defective',\n 'wrong',\n 'incorrect',\n\n // Account / login\n 'password',\n 'login',\n // 'sign in',\n 'account',\n 'locked',\n 'verification',\n 'otp',\n\n // Loyalty / promos / gift cards\n 'loyalty',\n 'rewards',\n 'points',\n 'promo',\n 'coupon',\n 'discount',\n 'gift',\n\n // Shipping / payments / billing\n 'shipping',\n 'payment',\n 'billing',\n 'charged',\n 'charge',\n 'invoice',\n 'receipt',\n 'declined',\n\n // Product info / sizing / inventory\n 'size',\n 'sizing',\n 'fit',\n 'care',\n 'stock',\n 'restock',\n 'availability',\n\n // Company / policy\n 'sustainability',\n 'ethics',\n 'careers',\n 'privacy',\n 'terms',\n\n // Human support\n 'agent',\n 'representative',\n 'support',\n 'human',\n 'talk',\n 'speak',\n 'help',\n\n // Technical / service issues\n 'api',\n 'failure',\n 'server',\n 'technical',\n 'website',\n 'checkout',\n 'app',\n 'something',\n]\n\nexport const DEFAULT_QUESTION_WORDS = [\n 'who',\n 'what',\n 'when',\n 'where',\n 'why',\n 'how',\n 'which',\n 'can',\n 'should',\n 'could',\n 'would',\n 'will',\n 'have',\n 'has',\n 'is',\n 'are',\n 'do',\n 'does',\n 'did',\n]\n\nexport const DEFAULT_PRONOUNS = [\n 'i',\n 'me',\n 'my',\n 'mine',\n 'we',\n 'us',\n 'our',\n 'you',\n 'your',\n 'it',\n 'he',\n 'him',\n 'his',\n 'she',\n 'her',\n 'they',\n 'them',\n 'their',\n]\n\nexport const DEFAULT_COMMON_VERBS = [\n 'is',\n 'are',\n 'was',\n 'were',\n 'do',\n 'does',\n 'did',\n 'have',\n 'need',\n 'want',\n 'look',\n 'help',\n 'know',\n 'think',\n 'make',\n 'create',\n 'find',\n 'get',\n 'buy',\n 'use',\n 'install',\n 'fix',\n 'recommend',\n 'tell',\n 'show',\n 'compare',\n 'explain',\n]\n\nexport const DEFAULT_STOPWORDS = [\n 'the',\n 'a',\n 'an',\n 'i',\n 'me',\n 'my',\n 'is',\n 'it',\n 'in',\n 'on',\n 'at',\n 'to',\n 'for',\n 'of',\n 'and',\n 'or',\n 'but',\n 'not',\n 'so',\n 'if',\n 'by',\n 'with',\n 'from',\n 'that',\n 'this',\n 'about',\n]\n","import {\n DEFAULT_COMMON_VERBS,\n DEFAULT_PRONOUNS,\n DEFAULT_QUESTION_WORDS,\n DEFAULT_STOPWORDS,\n DEFAULT_SUPPORT_WORDS,\n} from '../enums'\nimport type { ResolvedConfig } from '../types'\nimport { tokenize } from '../utils'\n\nexport const scoreQuery = (query: string, c: ResolvedConfig): boolean => {\n const tokens = tokenize(query)\n if (tokens.length === 0) return true\n\n const questionWords = c.scoreQuestionWords ?? DEFAULT_QUESTION_WORDS\n const pronouns = c.scorePronouns ?? DEFAULT_PRONOUNS\n const commonVerbs = c.scoreCommonVerbs ?? DEFAULT_COMMON_VERBS\n const stopwords = c.scoreStopwords ?? DEFAULT_STOPWORDS\n const supportWords = c.scoreSupportWords ?? DEFAULT_SUPPORT_WORDS\n\n const matchedSupportWords = tokens.filter(t => supportWords.includes(t))\n if (matchedSupportWords.length > 0) {\n console.log(` [H] support words: found [${matchedSupportWords.join(', ')}] → conversational (override)`)\n return false\n }\n\n let scoreKeyword = 0\n let scoreConversational = 0\n\n if (tokens.length <= 3) {\n scoreKeyword += 2\n console.log(` [A] token count: word count=${tokens.length} ≤3 → keyword +2`)\n } else if (tokens.length >= 6) {\n scoreConversational += 2\n console.log(` [A] token count: word count=${tokens.length} ≥6 → conversational +2`)\n } else {\n console.log(` [A] token count: word count=${tokens.length} (no score)`)\n }\n\n const matchedQuestionWords = tokens.filter(t => questionWords.includes(t))\n if (matchedQuestionWords.length > 0) {\n scoreConversational += 2\n console.log(` [B] question words: found [${matchedQuestionWords.join(', ')}] → conversational +2`)\n } else {\n console.log(` [B] question words: none`)\n }\n\n const matchedPronouns = tokens.filter(t => pronouns.includes(t))\n if (matchedPronouns.length > 0) {\n scoreConversational += 1\n console.log(` [C] pronouns: found [${matchedPronouns.join(', ')}] → conversational +1`)\n } else {\n console.log(` [C] pronouns: none`)\n }\n\n const matchedVerbs = tokens.filter(t => commonVerbs.includes(t))\n if (matchedVerbs.length > 0) {\n scoreConversational += 1\n console.log(` [D] common verbs: found [${matchedVerbs.join(', ')}] → conversational +1`)\n } else {\n console.log(` [D] common verbs: none`)\n }\n\n if (query.includes('?')) {\n scoreConversational += 3\n console.log(` [E] question mark: found → conversational +3`)\n } else {\n console.log(` [E] question mark: none`)\n }\n\n const stopwordCount = tokens.filter(t => stopwords.includes(t)).length\n const stopwordRatio = stopwordCount / tokens.length\n if (stopwordRatio > 0.4) {\n scoreConversational += 2\n console.log(\n ` [F] stopword ratio: ${stopwordRatio.toFixed(2)} (${stopwordCount}/${tokens.length}) >0.4 → conversational +2`\n )\n } else {\n scoreKeyword += 1\n console.log(\n ` [F] stopword ratio: ${stopwordRatio.toFixed(2)} (${stopwordCount}/${tokens.length}) ≤0.4 → keyword +1`\n )\n }\n\n const avgLen = tokens.reduce((sum, t) => sum + t.length, 0) / tokens.length\n if (avgLen >= 6) {\n scoreKeyword += 1\n console.log(` [G] avg token length: ${avgLen.toFixed(2)} ≥6 → keyword +1`)\n } else {\n console.log(` [G] avg token length: ${avgLen.toFixed(2)} (no score)`)\n }\n\n const result = scoreKeyword >= scoreConversational\n console.log(\n ` scores: keyword=${scoreKeyword} conversational=${scoreConversational} → ${result ? 'keyword' : 'conversational'}`\n )\n return result\n}\n","import { checkLength } from './modes/length'\nimport { checkList } from './modes/list'\nimport { scoreQuery } from './modes/score'\nimport type { ClarityUtilsConfig, ResolvedConfig } from './types'\nimport { isPunct, tokenize } from './utils'\n\nlet globalResolved: ResolvedConfig = {}\n\nconst setup = async (\n config: ClarityUtilsConfig\n): Promise<{ success: true } | { success: false; error: unknown }> => {\n globalResolved = { ...config }\n const blackJsonPunctSet = new Set<string>()\n const blackJsonWordSet = new Set<string>()\n const whiteSet = new Set<string>()\n\n try {\n await Promise.all([\n config.whiteListJson\n ? fetch(config.whiteListJson)\n .then(r => r.json())\n .then((arr: string[]) => {\n arr.forEach(s => whiteSet.add(s.toLowerCase()))\n })\n : null,\n config.blackListJson\n ? fetch(config.blackListJson)\n .then(r => r.json())\n .then((arr: string[]) => {\n arr.forEach(s => {\n const lower = s.toLowerCase()\n if (isPunct(lower)) blackJsonPunctSet.add(lower)\n else blackJsonWordSet.add(lower)\n })\n })\n : null,\n ])\n globalResolved = {\n ...globalResolved,\n blackJsonPunctSet,\n blackJsonWordSet,\n whiteSet,\n }\n return { success: true }\n } catch (error) {\n return { success: false, error }\n }\n}\n\nconst resolveConfig = (config?: ClarityUtilsConfig): ResolvedConfig => {\n const merged = { ...globalResolved, ...(config ?? {}) }\n merged.blackPunctSet = new Set([...(merged.blackJsonPunctSet ?? [])])\n merged.blackWordSet = new Set([...(merged.blackJsonWordSet ?? [])])\n merged.blackList?.forEach(s => {\n const lower = s.toLowerCase()\n if (isPunct(lower)) {\n merged.blackPunctSet?.add(lower)\n } else {\n merged.blackWordSet?.add(lower)\n }\n })\n\n if (merged.scoreQuestionWords)\n merged.scoreQuestionWords = merged.scoreQuestionWords.map(s => s.toLowerCase())\n if (merged.scorePronouns) merged.scorePronouns = merged.scorePronouns.map(s => s.toLowerCase())\n if (merged.scoreCommonVerbs) merged.scoreCommonVerbs = merged.scoreCommonVerbs.map(s => s.toLowerCase())\n if (merged.scoreStopwords) merged.scoreStopwords = merged.scoreStopwords.map(s => s.toLowerCase())\n if (merged.scoreSupportWords) merged.scoreSupportWords = merged.scoreSupportWords.map(s => s.toLowerCase())\n\n return merged\n}\n\nconst isSearch = (value: string, config?: ClarityUtilsConfig): boolean => {\n const c = resolveConfig(config)\n const lower = value.toLowerCase()\n\n const tokens = tokenize(lower)\n console.group(`[isSearch] \"${value}\" | mode=${c.mode} | tokens=[${tokens.join(', ')}]`)\n if (c.mode === 'mixed' || c.mode === 'list') {\n console.log(\n `lists: blackWordSet=${c.blackWordSet?.size ?? 0} blackPunctSet=${c.blackPunctSet?.size ?? 0} whiteSet=${c.whiteSet?.size ?? 0} whiteList=${c.whiteList?.length ?? 0}`\n )\n }\n\n let result: boolean\n if (c.mode === 'length') {\n result = checkLength(lower, c)\n } else if (c.mode === 'mixed') {\n result = checkList(lower, c) && checkLength(lower, c)\n } else if (c.mode === 'score') {\n result = scoreQuery(lower, c)\n } else {\n result = scoreQuery(lower, c)\n }\n\n console.log(`→ Result: ${result}`)\n console.groupEnd()\n return result\n}\n\nexport const clarityUtils = { setup, isSearch }\n"],"mappings":";AAAO,IAAM,UAAU,CAAC,MAAc,CAAC,KAAK,KAAK,CAAC;AAElD,IAAM,eAAuC;AAAA,EAC3C,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,WAAW;AAAA,EACX,UAAU;AAAA,EACV,SAAS;AAAA,EACT,UAAU;AAAA,EACV,UAAU;AAAA,EACV,WAAW;AAAA,EACX,WAAW;AAAA,EACX,UAAU;AAAA,EACV,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,UAAU;AAAA,EACV,WAAW;AAAA,EACX,SAAS;AAAA,EACT,WAAW;AAAA,EACX,SAAS;AAAA,EACT,UAAU;AAAA,EACV,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,WAAW;AAAA,EACX,UAAU;AAAA,EACV,UAAU;AAAA,EACV,SAAS;AACX;AAEA,IAAM,qBAAqB,CAAC,UAAkB,MAAM,QAAQ,WAAW,UAAK;AAxC5E;AAwC+E,4BAAa,IAAI,MAAjB,YAAsB;AAAA,CAAI;AAElG,IAAM,WAAW,CAAC,UAAkB,mBAAmB,KAAK,EAAE,MAAM,KAAK,EAAE,OAAO,OAAO;;;ACvCzF,IAAM,cAAc,CAAC,OAAe,MAA+B;AACxE,MAAI,CAAC,EAAE,WAAW;AAChB,YAAQ,IAAI,qDAAgD;AAC5D,WAAO;AAAA,EACT;AACA,Q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