@bloomreach/clarity-utils 1.0.1 → 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 +172 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +172 -7
- 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
|
@@ -26,7 +26,48 @@ module.exports = __toCommonJS(index_exports);
|
|
|
26
26
|
|
|
27
27
|
// src/utils.ts
|
|
28
28
|
var isPunct = (s) => !/\w/.test(s);
|
|
29
|
-
var
|
|
29
|
+
var CONTRACTIONS = {
|
|
30
|
+
"won't": "will not",
|
|
31
|
+
"can't": "cannot",
|
|
32
|
+
"don't": "do not",
|
|
33
|
+
"doesn't": "does not",
|
|
34
|
+
"didn't": "did not",
|
|
35
|
+
"isn't": "is not",
|
|
36
|
+
"aren't": "are not",
|
|
37
|
+
"wasn't": "was not",
|
|
38
|
+
"weren't": "were not",
|
|
39
|
+
"haven't": "have not",
|
|
40
|
+
"hasn't": "has not",
|
|
41
|
+
"hadn't": "had not",
|
|
42
|
+
"wouldn't": "would not",
|
|
43
|
+
"shouldn't": "should not",
|
|
44
|
+
"couldn't": "could not",
|
|
45
|
+
"what's": "what is",
|
|
46
|
+
"what're": "what are",
|
|
47
|
+
"how's": "how is",
|
|
48
|
+
"where's": "where is",
|
|
49
|
+
"who's": "who is",
|
|
50
|
+
"that's": "that is",
|
|
51
|
+
"there's": "there is",
|
|
52
|
+
"it's": "it is",
|
|
53
|
+
"i'm": "i am",
|
|
54
|
+
"i'd": "i would",
|
|
55
|
+
"i'll": "i will",
|
|
56
|
+
"i've": "i have",
|
|
57
|
+
"we're": "we are",
|
|
58
|
+
"we've": "we have",
|
|
59
|
+
"we'd": "we would",
|
|
60
|
+
"they're": "they are",
|
|
61
|
+
"they've": "they have",
|
|
62
|
+
"you're": "you are",
|
|
63
|
+
"you've": "you have",
|
|
64
|
+
"you'd": "you would"
|
|
65
|
+
};
|
|
66
|
+
var expandContractions = (query) => query.replace(/[\w']+/g, (word) => {
|
|
67
|
+
var _a;
|
|
68
|
+
return (_a = CONTRACTIONS[word]) != null ? _a : word;
|
|
69
|
+
});
|
|
70
|
+
var tokenize = (query) => expandContractions(query).split(/\s+/).filter(Boolean);
|
|
30
71
|
|
|
31
72
|
// src/modes/length.ts
|
|
32
73
|
var checkLength = (value, c) => {
|
|
@@ -69,6 +110,91 @@ var checkWord = (word, c) => {
|
|
|
69
110
|
var checkList = (lower, c) => checkPuncts(lower, c) && tokenize(lower).every((word) => checkWord(word, c));
|
|
70
111
|
|
|
71
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
|
+
];
|
|
72
198
|
var DEFAULT_QUESTION_WORDS = [
|
|
73
199
|
"who",
|
|
74
200
|
"what",
|
|
@@ -76,10 +202,14 @@ var DEFAULT_QUESTION_WORDS = [
|
|
|
76
202
|
"where",
|
|
77
203
|
"why",
|
|
78
204
|
"how",
|
|
205
|
+
"which",
|
|
79
206
|
"can",
|
|
80
207
|
"should",
|
|
81
208
|
"could",
|
|
82
209
|
"would",
|
|
210
|
+
"will",
|
|
211
|
+
"have",
|
|
212
|
+
"has",
|
|
83
213
|
"is",
|
|
84
214
|
"are",
|
|
85
215
|
"do",
|
|
@@ -97,8 +227,14 @@ var DEFAULT_PRONOUNS = [
|
|
|
97
227
|
"you",
|
|
98
228
|
"your",
|
|
99
229
|
"it",
|
|
230
|
+
"he",
|
|
231
|
+
"him",
|
|
232
|
+
"his",
|
|
233
|
+
"she",
|
|
234
|
+
"her",
|
|
100
235
|
"they",
|
|
101
|
-
"them"
|
|
236
|
+
"them",
|
|
237
|
+
"their"
|
|
102
238
|
];
|
|
103
239
|
var DEFAULT_COMMON_VERBS = [
|
|
104
240
|
"is",
|
|
@@ -108,6 +244,13 @@ var DEFAULT_COMMON_VERBS = [
|
|
|
108
244
|
"do",
|
|
109
245
|
"does",
|
|
110
246
|
"did",
|
|
247
|
+
"have",
|
|
248
|
+
"need",
|
|
249
|
+
"want",
|
|
250
|
+
"look",
|
|
251
|
+
"help",
|
|
252
|
+
"know",
|
|
253
|
+
"think",
|
|
111
254
|
"make",
|
|
112
255
|
"create",
|
|
113
256
|
"find",
|
|
@@ -118,11 +261,19 @@ var DEFAULT_COMMON_VERBS = [
|
|
|
118
261
|
"fix",
|
|
119
262
|
"recommend",
|
|
120
263
|
"tell",
|
|
121
|
-
"show"
|
|
264
|
+
"show",
|
|
265
|
+
"compare",
|
|
266
|
+
"explain"
|
|
122
267
|
];
|
|
123
268
|
var DEFAULT_STOPWORDS = [
|
|
124
269
|
"the",
|
|
270
|
+
"a",
|
|
271
|
+
"an",
|
|
272
|
+
"i",
|
|
273
|
+
"me",
|
|
274
|
+
"my",
|
|
125
275
|
"is",
|
|
276
|
+
"it",
|
|
126
277
|
"in",
|
|
127
278
|
"on",
|
|
128
279
|
"at",
|
|
@@ -130,21 +281,34 @@ var DEFAULT_STOPWORDS = [
|
|
|
130
281
|
"for",
|
|
131
282
|
"of",
|
|
132
283
|
"and",
|
|
133
|
-
"
|
|
134
|
-
"
|
|
284
|
+
"or",
|
|
285
|
+
"but",
|
|
286
|
+
"not",
|
|
287
|
+
"so",
|
|
288
|
+
"if",
|
|
289
|
+
"by",
|
|
135
290
|
"with",
|
|
136
|
-
"from"
|
|
291
|
+
"from",
|
|
292
|
+
"that",
|
|
293
|
+
"this",
|
|
294
|
+
"about"
|
|
137
295
|
];
|
|
138
296
|
|
|
139
297
|
// src/modes/score.ts
|
|
140
298
|
var scoreQuery = (query, c) => {
|
|
141
|
-
var _a, _b, _c, _d;
|
|
299
|
+
var _a, _b, _c, _d, _e;
|
|
142
300
|
const tokens = tokenize(query);
|
|
143
301
|
if (tokens.length === 0) return true;
|
|
144
302
|
const questionWords = (_a = c.scoreQuestionWords) != null ? _a : DEFAULT_QUESTION_WORDS;
|
|
145
303
|
const pronouns = (_b = c.scorePronouns) != null ? _b : DEFAULT_PRONOUNS;
|
|
146
304
|
const commonVerbs = (_c = c.scoreCommonVerbs) != null ? _c : DEFAULT_COMMON_VERBS;
|
|
147
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
|
+
}
|
|
148
312
|
let scoreKeyword = 0;
|
|
149
313
|
let scoreConversational = 0;
|
|
150
314
|
if (tokens.length <= 3) {
|
|
@@ -260,6 +424,7 @@ var resolveConfig = (config) => {
|
|
|
260
424
|
if (merged.scorePronouns) merged.scorePronouns = merged.scorePronouns.map((s) => s.toLowerCase());
|
|
261
425
|
if (merged.scoreCommonVerbs) merged.scoreCommonVerbs = merged.scoreCommonVerbs.map((s) => s.toLowerCase());
|
|
262
426
|
if (merged.scoreStopwords) merged.scoreStopwords = merged.scoreStopwords.map((s) => s.toLowerCase());
|
|
427
|
+
if (merged.scoreSupportWords) merged.scoreSupportWords = merged.scoreSupportWords.map((s) => s.toLowerCase());
|
|
263
428
|
return merged;
|
|
264
429
|
};
|
|
265
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\nexport const tokenize = (query: string) => 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 'can',\n 'should',\n 'could',\n 'would',\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 'they',\n 'them',\n]\n\nexport const DEFAULT_COMMON_VERBS = [\n 'is',\n 'are',\n 'was',\n 'were',\n 'do',\n 'does',\n 'did',\n 'make',\n 'create',\n 'find',\n 'get',\n 'buy',\n 'use',\n 'install',\n 'fix',\n 'recommend',\n 'tell',\n 'show',\n]\n\nexport const DEFAULT_STOPWORDS = [\n 'the',\n 'is',\n 'in',\n 'on',\n 'at',\n 'to',\n 'for',\n 'of',\n 'and',\n 'a',\n 'an',\n 'with',\n 'from',\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"],"mapp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M,YAAY;AAEhC,QAAM,SAAS,SAAS,KAAK;AAC7B,UAAQ,MAAM,eAAe,KAAK,YAAY,EAAE,IAAI,cAAc,OAAO,KAAK,IAAI,CAAC,GAAG;AACtF,MAAI,EAAE,SAAS,WAAW,EAAE,SAAS,QAAQ;AAC3C,YAAQ;AAAA,MACN,wBAAuB,aAAE,iBAAF,mBAAgB,SAAhB,YAAwB,CAAC,mBAAkB,aAAE,kBAAF,mBAAiB,SAAjB,YAAyB,CAAC,cAAa,aAAE,aAAF,mBAAY,SAAZ,YAAoB,CAAC,eAAc,aAAE,cAAF,mBAAa,WAAb,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/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,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;AA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AAO,SAAS;","names":["_a","_b"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
// src/utils.ts
|
|
2
2
|
var isPunct = (s) => !/\w/.test(s);
|
|
3
|
-
var
|
|
3
|
+
var CONTRACTIONS = {
|
|
4
|
+
"won't": "will not",
|
|
5
|
+
"can't": "cannot",
|
|
6
|
+
"don't": "do not",
|
|
7
|
+
"doesn't": "does not",
|
|
8
|
+
"didn't": "did not",
|
|
9
|
+
"isn't": "is not",
|
|
10
|
+
"aren't": "are not",
|
|
11
|
+
"wasn't": "was not",
|
|
12
|
+
"weren't": "were not",
|
|
13
|
+
"haven't": "have not",
|
|
14
|
+
"hasn't": "has not",
|
|
15
|
+
"hadn't": "had not",
|
|
16
|
+
"wouldn't": "would not",
|
|
17
|
+
"shouldn't": "should not",
|
|
18
|
+
"couldn't": "could not",
|
|
19
|
+
"what's": "what is",
|
|
20
|
+
"what're": "what are",
|
|
21
|
+
"how's": "how is",
|
|
22
|
+
"where's": "where is",
|
|
23
|
+
"who's": "who is",
|
|
24
|
+
"that's": "that is",
|
|
25
|
+
"there's": "there is",
|
|
26
|
+
"it's": "it is",
|
|
27
|
+
"i'm": "i am",
|
|
28
|
+
"i'd": "i would",
|
|
29
|
+
"i'll": "i will",
|
|
30
|
+
"i've": "i have",
|
|
31
|
+
"we're": "we are",
|
|
32
|
+
"we've": "we have",
|
|
33
|
+
"we'd": "we would",
|
|
34
|
+
"they're": "they are",
|
|
35
|
+
"they've": "they have",
|
|
36
|
+
"you're": "you are",
|
|
37
|
+
"you've": "you have",
|
|
38
|
+
"you'd": "you would"
|
|
39
|
+
};
|
|
40
|
+
var expandContractions = (query) => query.replace(/[\w']+/g, (word) => {
|
|
41
|
+
var _a;
|
|
42
|
+
return (_a = CONTRACTIONS[word]) != null ? _a : word;
|
|
43
|
+
});
|
|
44
|
+
var tokenize = (query) => expandContractions(query).split(/\s+/).filter(Boolean);
|
|
4
45
|
|
|
5
46
|
// src/modes/length.ts
|
|
6
47
|
var checkLength = (value, c) => {
|
|
@@ -43,6 +84,91 @@ var checkWord = (word, c) => {
|
|
|
43
84
|
var checkList = (lower, c) => checkPuncts(lower, c) && tokenize(lower).every((word) => checkWord(word, c));
|
|
44
85
|
|
|
45
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
|
+
];
|
|
46
172
|
var DEFAULT_QUESTION_WORDS = [
|
|
47
173
|
"who",
|
|
48
174
|
"what",
|
|
@@ -50,10 +176,14 @@ var DEFAULT_QUESTION_WORDS = [
|
|
|
50
176
|
"where",
|
|
51
177
|
"why",
|
|
52
178
|
"how",
|
|
179
|
+
"which",
|
|
53
180
|
"can",
|
|
54
181
|
"should",
|
|
55
182
|
"could",
|
|
56
183
|
"would",
|
|
184
|
+
"will",
|
|
185
|
+
"have",
|
|
186
|
+
"has",
|
|
57
187
|
"is",
|
|
58
188
|
"are",
|
|
59
189
|
"do",
|
|
@@ -71,8 +201,14 @@ var DEFAULT_PRONOUNS = [
|
|
|
71
201
|
"you",
|
|
72
202
|
"your",
|
|
73
203
|
"it",
|
|
204
|
+
"he",
|
|
205
|
+
"him",
|
|
206
|
+
"his",
|
|
207
|
+
"she",
|
|
208
|
+
"her",
|
|
74
209
|
"they",
|
|
75
|
-
"them"
|
|
210
|
+
"them",
|
|
211
|
+
"their"
|
|
76
212
|
];
|
|
77
213
|
var DEFAULT_COMMON_VERBS = [
|
|
78
214
|
"is",
|
|
@@ -82,6 +218,13 @@ var DEFAULT_COMMON_VERBS = [
|
|
|
82
218
|
"do",
|
|
83
219
|
"does",
|
|
84
220
|
"did",
|
|
221
|
+
"have",
|
|
222
|
+
"need",
|
|
223
|
+
"want",
|
|
224
|
+
"look",
|
|
225
|
+
"help",
|
|
226
|
+
"know",
|
|
227
|
+
"think",
|
|
85
228
|
"make",
|
|
86
229
|
"create",
|
|
87
230
|
"find",
|
|
@@ -92,11 +235,19 @@ var DEFAULT_COMMON_VERBS = [
|
|
|
92
235
|
"fix",
|
|
93
236
|
"recommend",
|
|
94
237
|
"tell",
|
|
95
|
-
"show"
|
|
238
|
+
"show",
|
|
239
|
+
"compare",
|
|
240
|
+
"explain"
|
|
96
241
|
];
|
|
97
242
|
var DEFAULT_STOPWORDS = [
|
|
98
243
|
"the",
|
|
244
|
+
"a",
|
|
245
|
+
"an",
|
|
246
|
+
"i",
|
|
247
|
+
"me",
|
|
248
|
+
"my",
|
|
99
249
|
"is",
|
|
250
|
+
"it",
|
|
100
251
|
"in",
|
|
101
252
|
"on",
|
|
102
253
|
"at",
|
|
@@ -104,21 +255,34 @@ var DEFAULT_STOPWORDS = [
|
|
|
104
255
|
"for",
|
|
105
256
|
"of",
|
|
106
257
|
"and",
|
|
107
|
-
"
|
|
108
|
-
"
|
|
258
|
+
"or",
|
|
259
|
+
"but",
|
|
260
|
+
"not",
|
|
261
|
+
"so",
|
|
262
|
+
"if",
|
|
263
|
+
"by",
|
|
109
264
|
"with",
|
|
110
|
-
"from"
|
|
265
|
+
"from",
|
|
266
|
+
"that",
|
|
267
|
+
"this",
|
|
268
|
+
"about"
|
|
111
269
|
];
|
|
112
270
|
|
|
113
271
|
// src/modes/score.ts
|
|
114
272
|
var scoreQuery = (query, c) => {
|
|
115
|
-
var _a, _b, _c, _d;
|
|
273
|
+
var _a, _b, _c, _d, _e;
|
|
116
274
|
const tokens = tokenize(query);
|
|
117
275
|
if (tokens.length === 0) return true;
|
|
118
276
|
const questionWords = (_a = c.scoreQuestionWords) != null ? _a : DEFAULT_QUESTION_WORDS;
|
|
119
277
|
const pronouns = (_b = c.scorePronouns) != null ? _b : DEFAULT_PRONOUNS;
|
|
120
278
|
const commonVerbs = (_c = c.scoreCommonVerbs) != null ? _c : DEFAULT_COMMON_VERBS;
|
|
121
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
|
+
}
|
|
122
286
|
let scoreKeyword = 0;
|
|
123
287
|
let scoreConversational = 0;
|
|
124
288
|
if (tokens.length <= 3) {
|
|
@@ -234,6 +398,7 @@ var resolveConfig = (config) => {
|
|
|
234
398
|
if (merged.scorePronouns) merged.scorePronouns = merged.scorePronouns.map((s) => s.toLowerCase());
|
|
235
399
|
if (merged.scoreCommonVerbs) merged.scoreCommonVerbs = merged.scoreCommonVerbs.map((s) => s.toLowerCase());
|
|
236
400
|
if (merged.scoreStopwords) merged.scoreStopwords = merged.scoreStopwords.map((s) => s.toLowerCase());
|
|
401
|
+
if (merged.scoreSupportWords) merged.scoreSupportWords = merged.scoreSupportWords.map((s) => s.toLowerCase());
|
|
237
402
|
return merged;
|
|
238
403
|
};
|
|
239
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\nexport const tokenize = (query: string) => 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 'can',\n 'should',\n 'could',\n 'would',\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 'they',\n 'them',\n]\n\nexport const DEFAULT_COMMON_VERBS = [\n 'is',\n 'are',\n 'was',\n 'were',\n 'do',\n 'does',\n 'did',\n 'make',\n 'create',\n 'find',\n 'get',\n 'buy',\n 'use',\n 'install',\n 'fix',\n 'recommend',\n 'tell',\n 'show',\n]\n\nexport const DEFAULT_STOPWORDS = [\n 'the',\n 'is',\n 'in',\n 'on',\n 'at',\n 'to',\n 'for',\n 'of',\n 'and',\n 'a',\n 'an',\n 'with',\n 'from',\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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AEhC,QAAM,SAAS,SAAS,KAAK;AAC7B,UAAQ,MAAM,eAAe,KAAK,YAAY,EAAE,IAAI,cAAc,OAAO,KAAK,IAAI,CAAC,GAAG;AACtF,MAAI,EAAE,SAAS,WAAW,EAAE,SAAS,QAAQ;AAC3C,YAAQ;AAAA,MACN,wBAAuB,aAAE,iBAAF,mBAAgB,SAAhB,YAAwB,CAAC,mBAAkB,aAAE,kBAAF,mBAAiB,SAAjB,YAAyB,CAAC,cAAa,aAAE,aAAF,mBAAY,SAAZ,YAAoB,CAAC,eAAc,aAAE,cAAF,mBAAa,WAAb,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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