@bloomreach/clarity-utils 1.0.0 → 1.0.2

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.
@@ -1,2 +1,2 @@
1
- "use strict";var tmp=(()=>{var k=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var _=(t,o)=>{for(var e in o)k(t,e,{get:o[e],enumerable:!0})},A=(t,o,e,s)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of F(o))!T.call(t,n)&&n!==e&&k(t,n,{get:()=>o[n],enumerable:!(s=D(o,n))||s.enumerable});return t};var z=t=>A(k({},"__esModule",{value:!0}),t);var M={};_(M,{clarityUtils:()=>B});var S=t=>!/\w/.test(t),g=t=>t.split(/\s+/).filter(Boolean);var C=(t,o)=>{if(!o.maxLength)return console.log(" checkLength \u2192 true (no maxLength configured)"),!0;let e=g(t).length,s=e<=o.maxLength;return console.log(` checkLength \u2192 ${s} (wordCount=${e} maxLength=${o.maxLength})`),s};var Q=(t,o)=>{var e;for(let s of(e=o.blackPunctSet)!=null?e:[])if(t.includes(s))return console.log(` punct "${s}" found in sentence \u2192 false (blacklisted)`),!1;return!0},J=(t,o)=>{var s,n,r,c,i,l,d;if((s=o.blackWordSet)!=null&&s.has(t))return console.log(` word "${t}" \u2192 false (blacklisted)`),!1;if(((r=(n=o.whiteSet)==null?void 0:n.size)!=null?r:0)>0||((i=(c=o.whiteList)==null?void 0:c.length)!=null?i:0)>0){let u=!!((l=o.whiteSet)!=null&&l.has(t)||(d=o.whiteList)!=null&&d.some(h=>h.toLowerCase()===t));return console.log(` word "${t}" \u2192 ${u} (whitelist check)`),u}return console.log(` word "${t}" \u2192 true`),!0},L=(t,o)=>Q(t,o)&&g(t).every(e=>J(e,o));var x=["who","what","when","where","why","how","can","should","could","would","is","are","do","does","did"],P=["i","me","my","mine","we","us","our","you","your","it","they","them"],W=["is","are","was","were","do","does","did","make","create","find","get","buy","use","install","fix","recommend","tell","show"],E=["the","is","in","on","at","to","for","of","and","a","an","with","from"];var U=(t,o)=>{var $,y,v,R;let e=g(t);if(e.length===0)return!0;let s=($=o.scoreQuestionWords)!=null?$:x,n=(y=o.scorePronouns)!=null?y:P,r=(v=o.scoreCommonVerbs)!=null?v:W,c=(R=o.scoreStopwords)!=null?R:E,i=0,l=0;e.length<=3?(i+=2,console.log(` [A] word count=${e.length} \u22643 \u2192 keyword +2`)):e.length>=6?(l+=2,console.log(` [A] word count=${e.length} \u22656 \u2192 conversational +2`)):console.log(` [A] word count=${e.length} (no score)`);let d=e.filter(a=>s.includes(a));d.length>0?(l+=2,console.log(` [B] question words found: [${d.join(", ")}] \u2192 conversational +2`)):console.log(" [B] no question words");let u=e.filter(a=>n.includes(a));u.length>0?(l+=1,console.log(` [C] pronouns found: [${u.join(", ")}] \u2192 conversational +1`)):console.log(" [C] no pronouns");let h=e.filter(a=>r.includes(a));h.length>0?(l+=1,console.log(` [D] verbs found: [${h.join(", ")}] \u2192 conversational +1`)):console.log(" [D] no common verbs"),t.includes("?")?(l+=3,console.log(' [E] "?" found \u2192 conversational +3')):console.log(' [E] no "?"');let f=e.filter(a=>c.includes(a)).length,m=f/e.length;m>.4?(l+=2,console.log(` [F] stopword ratio=${m.toFixed(2)} (${f}/${e.length}) >0.4 \u2192 conversational +2`)):(i+=1,console.log(` [F] stopword ratio=${m.toFixed(2)} (${f}/${e.length}) \u22640.4 \u2192 keyword +1`));let p=e.reduce((a,O)=>a+O.length,0)/e.length;p>=6?(i+=1,console.log(` [G] avg token length=${p.toFixed(2)} \u22656 \u2192 keyword +1`)):console.log(` [G] avg token length=${p.toFixed(2)} (no score)`);let b=i>=l;return console.log(` scores: keyword=${i} conversational=${l} \u2192 ${b?"keyword":"conversational"}`),b};var w={},N=async t=>{w={...t};let o=new Set,e=new Set,s=new Set;try{return await Promise.all([t.whiteListJson?fetch(t.whiteListJson).then(n=>n.json()).then(n=>{n.forEach(r=>s.add(r.toLowerCase()))}):null,t.blackListJson?fetch(t.blackListJson).then(n=>n.json()).then(n=>{n.forEach(r=>{let c=r.toLowerCase();S(c)?o.add(c):e.add(c)})}):null]),w={...w,blackJsonPunctSet:o,blackJsonWordSet:e,whiteSet:s},{success:!0}}catch(n){return{success:!1,error:n}}},V=t=>{var e,s,n;let o={...w,...t!=null?t:{}};return o.blackPunctSet=new Set([...(e=o.blackJsonPunctSet)!=null?e:[]]),o.blackWordSet=new Set([...(s=o.blackJsonWordSet)!=null?s:[]]),(n=o.blackList)==null||n.forEach(r=>{var i,l;let c=r.toLowerCase();S(c)?(i=o.blackPunctSet)==null||i.add(c):(l=o.blackWordSet)==null||l.add(c)}),o.scoreQuestionWords&&(o.scoreQuestionWords=o.scoreQuestionWords.map(r=>r.toLowerCase())),o.scorePronouns&&(o.scorePronouns=o.scorePronouns.map(r=>r.toLowerCase())),o.scoreCommonVerbs&&(o.scoreCommonVerbs=o.scoreCommonVerbs.map(r=>r.toLowerCase())),o.scoreStopwords&&(o.scoreStopwords=o.scoreStopwords.map(r=>r.toLowerCase())),o},j=(t,o)=>{var c,i,l,d,u,h,f,m;let e=V(o),s=t.toLowerCase(),n=g(s);console.group(`[isSearch] "${t}" | mode=${e.mode} | tokens=[${n.join(", ")}]`),console.log(`lists: blackWordSet=${(i=(c=e.blackWordSet)==null?void 0:c.size)!=null?i:0} blackPunctSet=${(d=(l=e.blackPunctSet)==null?void 0:l.size)!=null?d:0} whiteSet=${(h=(u=e.whiteSet)==null?void 0:u.size)!=null?h:0} whiteList=${(m=(f=e.whiteList)==null?void 0:f.length)!=null?m:0}`);let r;return e.mode==="length"?r=C(s,e):e.mode==="mixed"?r=L(s,e)&&C(s,e):e.mode==="score"?r=U(s,e):r=L(s,e),console.log(`\u2192 Result: ${r}`),console.groupEnd(),r},B={setup:N,isSearch:j};return z(M);})();
1
+ "use strict";var tmp=(()=>{var k=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var A=(t,o)=>{for(var e in o)k(t,e,{get:o[e],enumerable:!0})},_=(t,o,e,n)=>{if(o&&typeof o=="object"||typeof o=="function")for(let s of F(o))!T.call(t,s)&&s!==e&&k(t,s,{get:()=>o[s],enumerable:!(n=D(o,s))||n.enumerable});return t};var N=t=>_(k({},"__esModule",{value:!0}),t);var I={};A(I,{clarityUtils:()=>M});var C=t=>!/\w/.test(t),z={"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"},Q=t=>t.replace(/[\w']+/g,o=>{var e;return(e=z[o])!=null?e:o}),u=t=>Q(t).split(/\s+/).filter(Boolean);var S=(t,o)=>{if(!o.maxLength)return console.log(" checkLength \u2192 true (no maxLength configured)"),!0;let e=u(t).length,n=e<=o.maxLength;return console.log(` checkLength \u2192 ${n} (wordCount=${e} maxLength=${o.maxLength})`),n};var J=(t,o)=>{var e;for(let n of(e=o.blackPunctSet)!=null?e:[])if(t.includes(n))return console.log(` punct "${n}" found in sentence \u2192 false (blacklisted)`),!1;return!0},V=(t,o)=>{var n,s,r,i,c,l,h;if((n=o.blackWordSet)!=null&&n.has(t))return console.log(` word "${t}" \u2192 false (blacklisted)`),!1;if(((r=(s=o.whiteSet)==null?void 0:s.size)!=null?r:0)>0||((c=(i=o.whiteList)==null?void 0:i.length)!=null?c:0)>0){let d=!!((l=o.whiteSet)!=null&&l.has(t)||(h=o.whiteList)!=null&&h.some(w=>w.toLowerCase()===t));return console.log(` word "${t}" \u2192 ${d} (whitelist check)`),d}return console.log(` word "${t}" \u2192 true`),!0},R=(t,o)=>J(t,o)&&u(t).every(e=>V(e,o));var P=["who","what","when","where","why","how","which","can","should","could","would","will","have","has","is","are","do","does","did"],W=["i","me","my","mine","we","us","our","you","your","it","he","him","his","she","her","they","them","their"],E=["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"],O=["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 y=(t,o)=>{var v,L,$,x;let e=u(t);if(e.length===0)return!0;let n=(v=o.scoreQuestionWords)!=null?v:P,s=(L=o.scorePronouns)!=null?L:W,r=($=o.scoreCommonVerbs)!=null?$:E,i=(x=o.scoreStopwords)!=null?x:O,c=0,l=0;e.length<=3?(c+=2,console.log(` [A] token count: word count=${e.length} \u22643 \u2192 keyword +2`)):e.length>=6?(l+=2,console.log(` [A] token count: word count=${e.length} \u22656 \u2192 conversational +2`)):console.log(` [A] token count: word count=${e.length} (no score)`);let h=e.filter(a=>n.includes(a));h.length>0?(l+=2,console.log(` [B] question words: found [${h.join(", ")}] \u2192 conversational +2`)):console.log(" [B] question words: none");let d=e.filter(a=>s.includes(a));d.length>0?(l+=1,console.log(` [C] pronouns: found [${d.join(", ")}] \u2192 conversational +1`)):console.log(" [C] pronouns: none");let w=e.filter(a=>r.includes(a));w.length>0?(l+=1,console.log(` [D] common verbs: found [${w.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 g=e.filter(a=>i.includes(a)).length,m=g/e.length;m>.4?(l+=2,console.log(` [F] stopword ratio: ${m.toFixed(2)} (${g}/${e.length}) >0.4 \u2192 conversational +2`)):(c+=1,console.log(` [F] stopword ratio: ${m.toFixed(2)} (${g}/${e.length}) \u22640.4 \u2192 keyword +1`));let p=e.reduce((a,U)=>a+U.length,0)/e.length;p>=6?(c+=1,console.log(` [G] avg token length: ${p.toFixed(2)} \u22656 \u2192 keyword +1`)):console.log(` [G] avg token length: ${p.toFixed(2)} (no score)`);let b=c>=l;return console.log(` scores: keyword=${c} conversational=${l} \u2192 ${b?"keyword":"conversational"}`),b};var f={},j=async t=>{f={...t};let o=new Set,e=new Set,n=new Set;try{return await Promise.all([t.whiteListJson?fetch(t.whiteListJson).then(s=>s.json()).then(s=>{s.forEach(r=>n.add(r.toLowerCase()))}):null,t.blackListJson?fetch(t.blackListJson).then(s=>s.json()).then(s=>{s.forEach(r=>{let i=r.toLowerCase();C(i)?o.add(i):e.add(i)})}):null]),f={...f,blackJsonPunctSet:o,blackJsonWordSet:e,whiteSet:n},{success:!0}}catch(s){return{success:!1,error:s}}},B=t=>{var e,n,s;let o={...f,...t!=null?t:{}};return o.blackPunctSet=new Set([...(e=o.blackJsonPunctSet)!=null?e:[]]),o.blackWordSet=new Set([...(n=o.blackJsonWordSet)!=null?n:[]]),(s=o.blackList)==null||s.forEach(r=>{var c,l;let i=r.toLowerCase();C(i)?(c=o.blackPunctSet)==null||c.add(i):(l=o.blackWordSet)==null||l.add(i)}),o.scoreQuestionWords&&(o.scoreQuestionWords=o.scoreQuestionWords.map(r=>r.toLowerCase())),o.scorePronouns&&(o.scorePronouns=o.scorePronouns.map(r=>r.toLowerCase())),o.scoreCommonVerbs&&(o.scoreCommonVerbs=o.scoreCommonVerbs.map(r=>r.toLowerCase())),o.scoreStopwords&&(o.scoreStopwords=o.scoreStopwords.map(r=>r.toLowerCase())),o},q=(t,o)=>{var i,c,l,h,d,w,g,m;let e=B(o),n=t.toLowerCase(),s=u(n);console.group(`[isSearch] "${t}" | mode=${e.mode} | tokens=[${s.join(", ")}]`),(e.mode==="mixed"||e.mode==="list")&&console.log(`lists: blackWordSet=${(c=(i=e.blackWordSet)==null?void 0:i.size)!=null?c:0} blackPunctSet=${(h=(l=e.blackPunctSet)==null?void 0:l.size)!=null?h:0} whiteSet=${(w=(d=e.whiteSet)==null?void 0:d.size)!=null?w:0} whiteList=${(m=(g=e.whiteList)==null?void 0:g.length)!=null?m:0}`);let r;return e.mode==="length"?r=S(n,e):e.mode==="mixed"?r=R(n,e)&&S(n,e):e.mode==="score"?r=y(n,e):r=y(n,e),console.log(`\u2192 Result: ${r}`),console.groupEnd(),r},M={setup:j,isSearch:q};return N(I);})();
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 tokenize = (query) => query.split(/\s+/).filter(Boolean);
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) => {
@@ -76,10 +117,14 @@ var DEFAULT_QUESTION_WORDS = [
76
117
  "where",
77
118
  "why",
78
119
  "how",
120
+ "which",
79
121
  "can",
80
122
  "should",
81
123
  "could",
82
124
  "would",
125
+ "will",
126
+ "have",
127
+ "has",
83
128
  "is",
84
129
  "are",
85
130
  "do",
@@ -97,8 +142,14 @@ var DEFAULT_PRONOUNS = [
97
142
  "you",
98
143
  "your",
99
144
  "it",
145
+ "he",
146
+ "him",
147
+ "his",
148
+ "she",
149
+ "her",
100
150
  "they",
101
- "them"
151
+ "them",
152
+ "their"
102
153
  ];
103
154
  var DEFAULT_COMMON_VERBS = [
104
155
  "is",
@@ -108,6 +159,13 @@ var DEFAULT_COMMON_VERBS = [
108
159
  "do",
109
160
  "does",
110
161
  "did",
162
+ "have",
163
+ "need",
164
+ "want",
165
+ "look",
166
+ "help",
167
+ "know",
168
+ "think",
111
169
  "make",
112
170
  "create",
113
171
  "find",
@@ -118,11 +176,19 @@ var DEFAULT_COMMON_VERBS = [
118
176
  "fix",
119
177
  "recommend",
120
178
  "tell",
121
- "show"
179
+ "show",
180
+ "compare",
181
+ "explain"
122
182
  ];
123
183
  var DEFAULT_STOPWORDS = [
124
184
  "the",
185
+ "a",
186
+ "an",
187
+ "i",
188
+ "me",
189
+ "my",
125
190
  "is",
191
+ "it",
126
192
  "in",
127
193
  "on",
128
194
  "at",
@@ -130,10 +196,17 @@ var DEFAULT_STOPWORDS = [
130
196
  "for",
131
197
  "of",
132
198
  "and",
133
- "a",
134
- "an",
199
+ "or",
200
+ "but",
201
+ "not",
202
+ "so",
203
+ "if",
204
+ "by",
135
205
  "with",
136
- "from"
206
+ "from",
207
+ "that",
208
+ "this",
209
+ "about"
137
210
  ];
138
211
 
139
212
  // src/modes/score.ts
@@ -149,59 +222,59 @@ var scoreQuery = (query, c) => {
149
222
  let scoreConversational = 0;
150
223
  if (tokens.length <= 3) {
151
224
  scoreKeyword += 2;
152
- console.log(` [A] word count=${tokens.length} \u22643 \u2192 keyword +2`);
225
+ console.log(` [A] token count: word count=${tokens.length} \u22643 \u2192 keyword +2`);
153
226
  } else if (tokens.length >= 6) {
154
227
  scoreConversational += 2;
155
- console.log(` [A] word count=${tokens.length} \u22656 \u2192 conversational +2`);
228
+ console.log(` [A] token count: word count=${tokens.length} \u22656 \u2192 conversational +2`);
156
229
  } else {
157
- console.log(` [A] word count=${tokens.length} (no score)`);
230
+ console.log(` [A] token count: word count=${tokens.length} (no score)`);
158
231
  }
159
232
  const matchedQuestionWords = tokens.filter((t) => questionWords.includes(t));
160
233
  if (matchedQuestionWords.length > 0) {
161
234
  scoreConversational += 2;
162
- console.log(` [B] question words found: [${matchedQuestionWords.join(", ")}] \u2192 conversational +2`);
235
+ console.log(` [B] question words: found [${matchedQuestionWords.join(", ")}] \u2192 conversational +2`);
163
236
  } else {
164
- console.log(` [B] no question words`);
237
+ console.log(` [B] question words: none`);
165
238
  }
166
239
  const matchedPronouns = tokens.filter((t) => pronouns.includes(t));
167
240
  if (matchedPronouns.length > 0) {
168
241
  scoreConversational += 1;
169
- console.log(` [C] pronouns found: [${matchedPronouns.join(", ")}] \u2192 conversational +1`);
242
+ console.log(` [C] pronouns: found [${matchedPronouns.join(", ")}] \u2192 conversational +1`);
170
243
  } else {
171
- console.log(` [C] no pronouns`);
244
+ console.log(` [C] pronouns: none`);
172
245
  }
173
246
  const matchedVerbs = tokens.filter((t) => commonVerbs.includes(t));
174
247
  if (matchedVerbs.length > 0) {
175
248
  scoreConversational += 1;
176
- console.log(` [D] verbs found: [${matchedVerbs.join(", ")}] \u2192 conversational +1`);
249
+ console.log(` [D] common verbs: found [${matchedVerbs.join(", ")}] \u2192 conversational +1`);
177
250
  } else {
178
- console.log(` [D] no common verbs`);
251
+ console.log(` [D] common verbs: none`);
179
252
  }
180
253
  if (query.includes("?")) {
181
254
  scoreConversational += 3;
182
- console.log(` [E] "?" found \u2192 conversational +3`);
255
+ console.log(` [E] question mark: found \u2192 conversational +3`);
183
256
  } else {
184
- console.log(` [E] no "?"`);
257
+ console.log(` [E] question mark: none`);
185
258
  }
186
259
  const stopwordCount = tokens.filter((t) => stopwords.includes(t)).length;
187
260
  const stopwordRatio = stopwordCount / tokens.length;
188
261
  if (stopwordRatio > 0.4) {
189
262
  scoreConversational += 2;
190
263
  console.log(
191
- ` [F] stopword ratio=${stopwordRatio.toFixed(2)} (${stopwordCount}/${tokens.length}) >0.4 \u2192 conversational +2`
264
+ ` [F] stopword ratio: ${stopwordRatio.toFixed(2)} (${stopwordCount}/${tokens.length}) >0.4 \u2192 conversational +2`
192
265
  );
193
266
  } else {
194
267
  scoreKeyword += 1;
195
268
  console.log(
196
- ` [F] stopword ratio=${stopwordRatio.toFixed(2)} (${stopwordCount}/${tokens.length}) \u22640.4 \u2192 keyword +1`
269
+ ` [F] stopword ratio: ${stopwordRatio.toFixed(2)} (${stopwordCount}/${tokens.length}) \u22640.4 \u2192 keyword +1`
197
270
  );
198
271
  }
199
272
  const avgLen = tokens.reduce((sum, t) => sum + t.length, 0) / tokens.length;
200
273
  if (avgLen >= 6) {
201
274
  scoreKeyword += 1;
202
- console.log(` [G] avg token length=${avgLen.toFixed(2)} \u22656 \u2192 keyword +1`);
275
+ console.log(` [G] avg token length: ${avgLen.toFixed(2)} \u22656 \u2192 keyword +1`);
203
276
  } else {
204
- console.log(` [G] avg token length=${avgLen.toFixed(2)} (no score)`);
277
+ console.log(` [G] avg token length: ${avgLen.toFixed(2)} (no score)`);
205
278
  }
206
279
  const result = scoreKeyword >= scoreConversational;
207
280
  console.log(
@@ -268,9 +341,11 @@ var isSearch = (value, config) => {
268
341
  const lower = value.toLowerCase();
269
342
  const tokens = tokenize(lower);
270
343
  console.group(`[isSearch] "${value}" | mode=${c.mode} | tokens=[${tokens.join(", ")}]`);
271
- console.log(
272
- `lists: blackWordSet=${(_b = (_a = c.blackWordSet) == null ? void 0 : _a.size) != null ? _b : 0} blackPunctSet=${(_d = (_c = c.blackPunctSet) == null ? void 0 : _c.size) != null ? _d : 0} whiteSet=${(_f = (_e = c.whiteSet) == null ? void 0 : _e.size) != null ? _f : 0} whiteList=${(_h = (_g = c.whiteList) == null ? void 0 : _g.length) != null ? _h : 0}`
273
- );
344
+ if (c.mode === "mixed" || c.mode === "list") {
345
+ console.log(
346
+ `lists: blackWordSet=${(_b = (_a = c.blackWordSet) == null ? void 0 : _a.size) != null ? _b : 0} blackPunctSet=${(_d = (_c = c.blackPunctSet) == null ? void 0 : _c.size) != null ? _d : 0} whiteSet=${(_f = (_e = c.whiteSet) == null ? void 0 : _e.size) != null ? _f : 0} whiteList=${(_h = (_g = c.whiteList) == null ? void 0 : _g.length) != null ? _h : 0}`
347
+ );
348
+ }
274
349
  let result;
275
350
  if (c.mode === "length") {
276
351
  result = checkLength(lower, c);
@@ -279,7 +354,7 @@ var isSearch = (value, config) => {
279
354
  } else if (c.mode === "score") {
280
355
  result = scoreQuery(lower, c);
281
356
  } else {
282
- result = checkList(lower, c);
357
+ result = scoreQuery(lower, c);
283
358
  }
284
359
  console.log(`\u2192 Result: ${result}`);
285
360
  console.groupEnd();
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 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 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 = checkList(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] word count=${tokens.length} ≤3 → keyword +2`)\n } else if (tokens.length >= 6) {\n scoreConversational += 2\n console.log(` [A] word count=${tokens.length} ≥6 → conversational +2`)\n } else {\n console.log(` [A] 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] no question words`)\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] no pronouns`)\n }\n\n const matchedVerbs = tokens.filter(t => commonVerbs.includes(t))\n if (matchedVerbs.length > 0) {\n scoreConversational += 1\n console.log(` [D] verbs found: [${matchedVerbs.join(', ')}] → conversational +1`)\n } else {\n console.log(` [D] no common verbs`)\n }\n\n if (query.includes('?')) {\n scoreConversational += 3\n console.log(` [E] \"?\" found → conversational +3`)\n } else {\n console.log(` [E] no \"?\"`)\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;AAE3C,IAAM,WAAW,CAAC,UAAkB,MAAM,MAAM,KAAK,EAAE,OAAO,OAAO;;;ACCrE,IAAM,cAAc,CAAC,OAAe,MAA+B;AACxE,MAAI,CAAC,EAAE,WAAW;AAChB,YAAQ,IAAI,qDAAgD;AAC5D,WAAO;AAAA,EACT;AACA,QAAM,YAAY,SAAS,KAAK,EAAE;AAClC,QAAM,SAAS,aAAa,EAAE;AAC9B,UAAQ,IAAI,wBAAmB,MAAM,eAAe,SA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O,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,UAAU,OAAO,CAAC;AAAA,EAC7B;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\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;AAAA,EACX,UAAU;AAAA,EACV,UAAU;AAAA,EACV,SAAS;AACX;AAEA,IAAM,qBAAqB,CAAC,UAC1B,MAAM,QAAQ,WAAW,UAAK;AAzChC;AAyCmC,4BAAa,IAAI,MAAjB,YAAsB;AAAA,CAAI;AAEtD,IAAM,WAAW,CAAC,UACvB,mBAAmB,KAAK,EAAE,MAAM,KAAK,EAAE,OAAO,OAAO;;;ACzChD,IAAM,cAAc,CAAC,OAAe,MA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AY,CAAC;AAEjG,SAAO;AACT;AAEA,IAAM,WAAW,CAAC,OAAe,WAAyC;AAvE1E;AAwEE,QAAM,IAAI,cAAc,MAAM;AAC9B,QAAM,QAAQ,MAAM,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"]}
package/dist/index.mjs CHANGED
@@ -1,6 +1,47 @@
1
1
  // src/utils.ts
2
2
  var isPunct = (s) => !/\w/.test(s);
3
- var tokenize = (query) => query.split(/\s+/).filter(Boolean);
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) => {
@@ -50,10 +91,14 @@ var DEFAULT_QUESTION_WORDS = [
50
91
  "where",
51
92
  "why",
52
93
  "how",
94
+ "which",
53
95
  "can",
54
96
  "should",
55
97
  "could",
56
98
  "would",
99
+ "will",
100
+ "have",
101
+ "has",
57
102
  "is",
58
103
  "are",
59
104
  "do",
@@ -71,8 +116,14 @@ var DEFAULT_PRONOUNS = [
71
116
  "you",
72
117
  "your",
73
118
  "it",
119
+ "he",
120
+ "him",
121
+ "his",
122
+ "she",
123
+ "her",
74
124
  "they",
75
- "them"
125
+ "them",
126
+ "their"
76
127
  ];
77
128
  var DEFAULT_COMMON_VERBS = [
78
129
  "is",
@@ -82,6 +133,13 @@ var DEFAULT_COMMON_VERBS = [
82
133
  "do",
83
134
  "does",
84
135
  "did",
136
+ "have",
137
+ "need",
138
+ "want",
139
+ "look",
140
+ "help",
141
+ "know",
142
+ "think",
85
143
  "make",
86
144
  "create",
87
145
  "find",
@@ -92,11 +150,19 @@ var DEFAULT_COMMON_VERBS = [
92
150
  "fix",
93
151
  "recommend",
94
152
  "tell",
95
- "show"
153
+ "show",
154
+ "compare",
155
+ "explain"
96
156
  ];
97
157
  var DEFAULT_STOPWORDS = [
98
158
  "the",
159
+ "a",
160
+ "an",
161
+ "i",
162
+ "me",
163
+ "my",
99
164
  "is",
165
+ "it",
100
166
  "in",
101
167
  "on",
102
168
  "at",
@@ -104,10 +170,17 @@ var DEFAULT_STOPWORDS = [
104
170
  "for",
105
171
  "of",
106
172
  "and",
107
- "a",
108
- "an",
173
+ "or",
174
+ "but",
175
+ "not",
176
+ "so",
177
+ "if",
178
+ "by",
109
179
  "with",
110
- "from"
180
+ "from",
181
+ "that",
182
+ "this",
183
+ "about"
111
184
  ];
112
185
 
113
186
  // src/modes/score.ts
@@ -123,59 +196,59 @@ var scoreQuery = (query, c) => {
123
196
  let scoreConversational = 0;
124
197
  if (tokens.length <= 3) {
125
198
  scoreKeyword += 2;
126
- console.log(` [A] word count=${tokens.length} \u22643 \u2192 keyword +2`);
199
+ console.log(` [A] token count: word count=${tokens.length} \u22643 \u2192 keyword +2`);
127
200
  } else if (tokens.length >= 6) {
128
201
  scoreConversational += 2;
129
- console.log(` [A] word count=${tokens.length} \u22656 \u2192 conversational +2`);
202
+ console.log(` [A] token count: word count=${tokens.length} \u22656 \u2192 conversational +2`);
130
203
  } else {
131
- console.log(` [A] word count=${tokens.length} (no score)`);
204
+ console.log(` [A] token count: word count=${tokens.length} (no score)`);
132
205
  }
133
206
  const matchedQuestionWords = tokens.filter((t) => questionWords.includes(t));
134
207
  if (matchedQuestionWords.length > 0) {
135
208
  scoreConversational += 2;
136
- console.log(` [B] question words found: [${matchedQuestionWords.join(", ")}] \u2192 conversational +2`);
209
+ console.log(` [B] question words: found [${matchedQuestionWords.join(", ")}] \u2192 conversational +2`);
137
210
  } else {
138
- console.log(` [B] no question words`);
211
+ console.log(` [B] question words: none`);
139
212
  }
140
213
  const matchedPronouns = tokens.filter((t) => pronouns.includes(t));
141
214
  if (matchedPronouns.length > 0) {
142
215
  scoreConversational += 1;
143
- console.log(` [C] pronouns found: [${matchedPronouns.join(", ")}] \u2192 conversational +1`);
216
+ console.log(` [C] pronouns: found [${matchedPronouns.join(", ")}] \u2192 conversational +1`);
144
217
  } else {
145
- console.log(` [C] no pronouns`);
218
+ console.log(` [C] pronouns: none`);
146
219
  }
147
220
  const matchedVerbs = tokens.filter((t) => commonVerbs.includes(t));
148
221
  if (matchedVerbs.length > 0) {
149
222
  scoreConversational += 1;
150
- console.log(` [D] verbs found: [${matchedVerbs.join(", ")}] \u2192 conversational +1`);
223
+ console.log(` [D] common verbs: found [${matchedVerbs.join(", ")}] \u2192 conversational +1`);
151
224
  } else {
152
- console.log(` [D] no common verbs`);
225
+ console.log(` [D] common verbs: none`);
153
226
  }
154
227
  if (query.includes("?")) {
155
228
  scoreConversational += 3;
156
- console.log(` [E] "?" found \u2192 conversational +3`);
229
+ console.log(` [E] question mark: found \u2192 conversational +3`);
157
230
  } else {
158
- console.log(` [E] no "?"`);
231
+ console.log(` [E] question mark: none`);
159
232
  }
160
233
  const stopwordCount = tokens.filter((t) => stopwords.includes(t)).length;
161
234
  const stopwordRatio = stopwordCount / tokens.length;
162
235
  if (stopwordRatio > 0.4) {
163
236
  scoreConversational += 2;
164
237
  console.log(
165
- ` [F] stopword ratio=${stopwordRatio.toFixed(2)} (${stopwordCount}/${tokens.length}) >0.4 \u2192 conversational +2`
238
+ ` [F] stopword ratio: ${stopwordRatio.toFixed(2)} (${stopwordCount}/${tokens.length}) >0.4 \u2192 conversational +2`
166
239
  );
167
240
  } else {
168
241
  scoreKeyword += 1;
169
242
  console.log(
170
- ` [F] stopword ratio=${stopwordRatio.toFixed(2)} (${stopwordCount}/${tokens.length}) \u22640.4 \u2192 keyword +1`
243
+ ` [F] stopword ratio: ${stopwordRatio.toFixed(2)} (${stopwordCount}/${tokens.length}) \u22640.4 \u2192 keyword +1`
171
244
  );
172
245
  }
173
246
  const avgLen = tokens.reduce((sum, t) => sum + t.length, 0) / tokens.length;
174
247
  if (avgLen >= 6) {
175
248
  scoreKeyword += 1;
176
- console.log(` [G] avg token length=${avgLen.toFixed(2)} \u22656 \u2192 keyword +1`);
249
+ console.log(` [G] avg token length: ${avgLen.toFixed(2)} \u22656 \u2192 keyword +1`);
177
250
  } else {
178
- console.log(` [G] avg token length=${avgLen.toFixed(2)} (no score)`);
251
+ console.log(` [G] avg token length: ${avgLen.toFixed(2)} (no score)`);
179
252
  }
180
253
  const result = scoreKeyword >= scoreConversational;
181
254
  console.log(
@@ -242,9 +315,11 @@ var isSearch = (value, config) => {
242
315
  const lower = value.toLowerCase();
243
316
  const tokens = tokenize(lower);
244
317
  console.group(`[isSearch] "${value}" | mode=${c.mode} | tokens=[${tokens.join(", ")}]`);
245
- console.log(
246
- `lists: blackWordSet=${(_b = (_a = c.blackWordSet) == null ? void 0 : _a.size) != null ? _b : 0} blackPunctSet=${(_d = (_c = c.blackPunctSet) == null ? void 0 : _c.size) != null ? _d : 0} whiteSet=${(_f = (_e = c.whiteSet) == null ? void 0 : _e.size) != null ? _f : 0} whiteList=${(_h = (_g = c.whiteList) == null ? void 0 : _g.length) != null ? _h : 0}`
247
- );
318
+ if (c.mode === "mixed" || c.mode === "list") {
319
+ console.log(
320
+ `lists: blackWordSet=${(_b = (_a = c.blackWordSet) == null ? void 0 : _a.size) != null ? _b : 0} blackPunctSet=${(_d = (_c = c.blackPunctSet) == null ? void 0 : _c.size) != null ? _d : 0} whiteSet=${(_f = (_e = c.whiteSet) == null ? void 0 : _e.size) != null ? _f : 0} whiteList=${(_h = (_g = c.whiteList) == null ? void 0 : _g.length) != null ? _h : 0}`
321
+ );
322
+ }
248
323
  let result;
249
324
  if (c.mode === "length") {
250
325
  result = checkLength(lower, c);
@@ -253,7 +328,7 @@ var isSearch = (value, config) => {
253
328
  } else if (c.mode === "score") {
254
329
  result = scoreQuery(lower, c);
255
330
  } else {
256
- result = checkList(lower, c);
331
+ result = scoreQuery(lower, c);
257
332
  }
258
333
  console.log(`\u2192 Result: ${result}`);
259
334
  console.groupEnd();
@@ -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] word count=${tokens.length} ≤3 → keyword +2`)\n } else if (tokens.length >= 6) {\n scoreConversational += 2\n console.log(` [A] word count=${tokens.length} ≥6 → conversational +2`)\n } else {\n console.log(` [A] 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] no question words`)\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] no pronouns`)\n }\n\n const matchedVerbs = tokens.filter(t => commonVerbs.includes(t))\n if (matchedVerbs.length > 0) {\n scoreConversational += 1\n console.log(` [D] verbs found: [${matchedVerbs.join(', ')}] → conversational +1`)\n } else {\n console.log(` [D] no common verbs`)\n }\n\n if (query.includes('?')) {\n scoreConversational += 3\n console.log(` [E] \"?\" found → conversational +3`)\n } else {\n console.log(` [E] no \"?\"`)\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 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 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 = checkList(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;AAE3C,IAAM,WAAW,CAAC,UAAkB,MAAM,MAAM,KAAK,EAAE,OAAO,OAAO;;;ACCrE,IAAM,cAAc,CAAC,OAAe,MAA+B;AACxE,MAAI,CAAC,EAAE,WAAW;AAChB,YAAQ,IAAI,qDAAgD;AAC5D,WAAO;AAAA,EACT;AACA,QAAM,YAAY,SAAS,KAAK,EAAE;AAClC,QAAM,SAAS,aAAa,EAAE;AAC9B,UAAQ,IAAI,wBAAmB,MAAM,eAAe,SAAS,cAAc,EAAE,SAAS,GAAG;AACzF,SAAO;AACT;;;ACTA,IAAM,cAAc,CAAC,OAAe,MAA+B;AAHnE;AAIE,aAAW,UAAS,OAAE,kBAAF,YAAmB,CAAC,GAAG;AACzC,QAAI,MAAM,SAAS,KAAK,GAAG;AACzB,cAAQ,IAAI,YAAY,KAAK,gDAA2C;AACxE,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAEA,IAAM,YAAY,CAAC,MAAc,MAA+B;AAbhE;AAcE,OAAI,OAAE,iBAAF,mBAAgB,IAAI,OAAO;AAC7B,YAAQ,IAAI,WAAW,IAAI,8BAAyB;AACpD,WAAO;AAAA,EACT;AACA,QAAM,aAAY,aAAE,aAAF,mBAAY,SAAZ,YAAoB,KAAK,OAAM,aAAE,cAAF,mBAAa,WAAb,YAAuB,KAAK;AAC7E,MAAI,UAAU;AACZ,UAAM,SAAS,CAAC,IAAE,OAAE,aAAF,mBAAY,IAAI,YAAS,OAAE,cAAF,m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vG,MAAI,OAAO,eAAgB,QAAO,iBAAiB,OAAO,eAAe,IAAI,OAAK,EAAE,YAAY,CAAC;AAEjG,SAAO;AACT;AAEA,IAAM,WAAW,CAAC,OAAe,WAAyC;AAvE1E;AAwEE,QAAM,IAAI,cAAc,MAAM;AAC9B,QAAM,QAAQ,MAAM,YAAY;AAEhC,QAAM,SAAS,SAAS,KAAK;AAC7B,UAAQ,MAAM,eAAe,KAAK,YAAY,EAAE,IAAI,cAAc,OAAO,KAAK,IAAI,CAAC,GAAG;AACtF,UAAQ;AAAA,IACN,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,EACtK;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,UAAU,OAAO,CAAC;AAAA,EAC7B;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) =>\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,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;A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,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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bloomreach/clarity-utils",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Utility functions for Bloomreach Clarity integrations",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",