@bloomreach/clarity-utils 1.0.0

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.
@@ -0,0 +1,24 @@
1
+ type ClarityUtilsConfig = {
2
+ mode?: 'list' | 'length' | 'mixed' | 'score';
3
+ whiteList?: string[];
4
+ blackList?: string[];
5
+ whiteListJson?: string;
6
+ blackListJson?: string;
7
+ maxLength?: number | null;
8
+ scoreQuestionWords?: string[];
9
+ scorePronouns?: string[];
10
+ scoreCommonVerbs?: string[];
11
+ scoreStopwords?: string[];
12
+ };
13
+
14
+ declare const clarityUtils: {
15
+ setup: (config: ClarityUtilsConfig) => Promise<{
16
+ success: true;
17
+ } | {
18
+ success: false;
19
+ error: unknown;
20
+ }>;
21
+ isSearch: (value: string, config?: ClarityUtilsConfig) => boolean;
22
+ };
23
+
24
+ export { clarityUtils };
@@ -0,0 +1,24 @@
1
+ type ClarityUtilsConfig = {
2
+ mode?: 'list' | 'length' | 'mixed' | 'score';
3
+ whiteList?: string[];
4
+ blackList?: string[];
5
+ whiteListJson?: string;
6
+ blackListJson?: string;
7
+ maxLength?: number | null;
8
+ scoreQuestionWords?: string[];
9
+ scorePronouns?: string[];
10
+ scoreCommonVerbs?: string[];
11
+ scoreStopwords?: string[];
12
+ };
13
+
14
+ declare const clarityUtils: {
15
+ setup: (config: ClarityUtilsConfig) => Promise<{
16
+ success: true;
17
+ } | {
18
+ success: false;
19
+ error: unknown;
20
+ }>;
21
+ isSearch: (value: string, config?: ClarityUtilsConfig) => boolean;
22
+ };
23
+
24
+ export { clarityUtils };
@@ -0,0 +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);})();
2
+ window.clarityUtils=tmp.clarityUtils;
package/dist/index.js ADDED
@@ -0,0 +1,293 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ clarityUtils: () => clarityUtils
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+
27
+ // src/utils.ts
28
+ var isPunct = (s) => !/\w/.test(s);
29
+ var tokenize = (query) => query.split(/\s+/).filter(Boolean);
30
+
31
+ // src/modes/length.ts
32
+ var checkLength = (value, c) => {
33
+ if (!c.maxLength) {
34
+ console.log(" checkLength \u2192 true (no maxLength configured)");
35
+ return true;
36
+ }
37
+ const wordCount = tokenize(value).length;
38
+ const result = wordCount <= c.maxLength;
39
+ console.log(` checkLength \u2192 ${result} (wordCount=${wordCount} maxLength=${c.maxLength})`);
40
+ return result;
41
+ };
42
+
43
+ // src/modes/list.ts
44
+ var checkPuncts = (lower, c) => {
45
+ var _a;
46
+ for (const punct of (_a = c.blackPunctSet) != null ? _a : []) {
47
+ if (lower.includes(punct)) {
48
+ console.log(` punct "${punct}" found in sentence \u2192 false (blacklisted)`);
49
+ return false;
50
+ }
51
+ }
52
+ return true;
53
+ };
54
+ var checkWord = (word, c) => {
55
+ var _a, _b, _c, _d, _e, _f, _g;
56
+ if ((_a = c.blackWordSet) == null ? void 0 : _a.has(word)) {
57
+ console.log(` word "${word}" \u2192 false (blacklisted)`);
58
+ return false;
59
+ }
60
+ const hasWhite = ((_c = (_b = c.whiteSet) == null ? void 0 : _b.size) != null ? _c : 0) > 0 || ((_e = (_d = c.whiteList) == null ? void 0 : _d.length) != null ? _e : 0) > 0;
61
+ if (hasWhite) {
62
+ const result = !!(((_f = c.whiteSet) == null ? void 0 : _f.has(word)) || ((_g = c.whiteList) == null ? void 0 : _g.some((s) => s.toLowerCase() === word)));
63
+ console.log(` word "${word}" \u2192 ${result} (whitelist check)`);
64
+ return result;
65
+ }
66
+ console.log(` word "${word}" \u2192 true`);
67
+ return true;
68
+ };
69
+ var checkList = (lower, c) => checkPuncts(lower, c) && tokenize(lower).every((word) => checkWord(word, c));
70
+
71
+ // src/enums.ts
72
+ var DEFAULT_QUESTION_WORDS = [
73
+ "who",
74
+ "what",
75
+ "when",
76
+ "where",
77
+ "why",
78
+ "how",
79
+ "can",
80
+ "should",
81
+ "could",
82
+ "would",
83
+ "is",
84
+ "are",
85
+ "do",
86
+ "does",
87
+ "did"
88
+ ];
89
+ var DEFAULT_PRONOUNS = [
90
+ "i",
91
+ "me",
92
+ "my",
93
+ "mine",
94
+ "we",
95
+ "us",
96
+ "our",
97
+ "you",
98
+ "your",
99
+ "it",
100
+ "they",
101
+ "them"
102
+ ];
103
+ var DEFAULT_COMMON_VERBS = [
104
+ "is",
105
+ "are",
106
+ "was",
107
+ "were",
108
+ "do",
109
+ "does",
110
+ "did",
111
+ "make",
112
+ "create",
113
+ "find",
114
+ "get",
115
+ "buy",
116
+ "use",
117
+ "install",
118
+ "fix",
119
+ "recommend",
120
+ "tell",
121
+ "show"
122
+ ];
123
+ var DEFAULT_STOPWORDS = [
124
+ "the",
125
+ "is",
126
+ "in",
127
+ "on",
128
+ "at",
129
+ "to",
130
+ "for",
131
+ "of",
132
+ "and",
133
+ "a",
134
+ "an",
135
+ "with",
136
+ "from"
137
+ ];
138
+
139
+ // src/modes/score.ts
140
+ var scoreQuery = (query, c) => {
141
+ var _a, _b, _c, _d;
142
+ const tokens = tokenize(query);
143
+ if (tokens.length === 0) return true;
144
+ const questionWords = (_a = c.scoreQuestionWords) != null ? _a : DEFAULT_QUESTION_WORDS;
145
+ const pronouns = (_b = c.scorePronouns) != null ? _b : DEFAULT_PRONOUNS;
146
+ const commonVerbs = (_c = c.scoreCommonVerbs) != null ? _c : DEFAULT_COMMON_VERBS;
147
+ const stopwords = (_d = c.scoreStopwords) != null ? _d : DEFAULT_STOPWORDS;
148
+ let scoreKeyword = 0;
149
+ let scoreConversational = 0;
150
+ if (tokens.length <= 3) {
151
+ scoreKeyword += 2;
152
+ console.log(` [A] word count=${tokens.length} \u22643 \u2192 keyword +2`);
153
+ } else if (tokens.length >= 6) {
154
+ scoreConversational += 2;
155
+ console.log(` [A] word count=${tokens.length} \u22656 \u2192 conversational +2`);
156
+ } else {
157
+ console.log(` [A] word count=${tokens.length} (no score)`);
158
+ }
159
+ const matchedQuestionWords = tokens.filter((t) => questionWords.includes(t));
160
+ if (matchedQuestionWords.length > 0) {
161
+ scoreConversational += 2;
162
+ console.log(` [B] question words found: [${matchedQuestionWords.join(", ")}] \u2192 conversational +2`);
163
+ } else {
164
+ console.log(` [B] no question words`);
165
+ }
166
+ const matchedPronouns = tokens.filter((t) => pronouns.includes(t));
167
+ if (matchedPronouns.length > 0) {
168
+ scoreConversational += 1;
169
+ console.log(` [C] pronouns found: [${matchedPronouns.join(", ")}] \u2192 conversational +1`);
170
+ } else {
171
+ console.log(` [C] no pronouns`);
172
+ }
173
+ const matchedVerbs = tokens.filter((t) => commonVerbs.includes(t));
174
+ if (matchedVerbs.length > 0) {
175
+ scoreConversational += 1;
176
+ console.log(` [D] verbs found: [${matchedVerbs.join(", ")}] \u2192 conversational +1`);
177
+ } else {
178
+ console.log(` [D] no common verbs`);
179
+ }
180
+ if (query.includes("?")) {
181
+ scoreConversational += 3;
182
+ console.log(` [E] "?" found \u2192 conversational +3`);
183
+ } else {
184
+ console.log(` [E] no "?"`);
185
+ }
186
+ const stopwordCount = tokens.filter((t) => stopwords.includes(t)).length;
187
+ const stopwordRatio = stopwordCount / tokens.length;
188
+ if (stopwordRatio > 0.4) {
189
+ scoreConversational += 2;
190
+ console.log(
191
+ ` [F] stopword ratio=${stopwordRatio.toFixed(2)} (${stopwordCount}/${tokens.length}) >0.4 \u2192 conversational +2`
192
+ );
193
+ } else {
194
+ scoreKeyword += 1;
195
+ console.log(
196
+ ` [F] stopword ratio=${stopwordRatio.toFixed(2)} (${stopwordCount}/${tokens.length}) \u22640.4 \u2192 keyword +1`
197
+ );
198
+ }
199
+ const avgLen = tokens.reduce((sum, t) => sum + t.length, 0) / tokens.length;
200
+ if (avgLen >= 6) {
201
+ scoreKeyword += 1;
202
+ console.log(` [G] avg token length=${avgLen.toFixed(2)} \u22656 \u2192 keyword +1`);
203
+ } else {
204
+ console.log(` [G] avg token length=${avgLen.toFixed(2)} (no score)`);
205
+ }
206
+ const result = scoreKeyword >= scoreConversational;
207
+ console.log(
208
+ ` scores: keyword=${scoreKeyword} conversational=${scoreConversational} \u2192 ${result ? "keyword" : "conversational"}`
209
+ );
210
+ return result;
211
+ };
212
+
213
+ // src/index.ts
214
+ var globalResolved = {};
215
+ var setup = async (config) => {
216
+ globalResolved = { ...config };
217
+ const blackJsonPunctSet = /* @__PURE__ */ new Set();
218
+ const blackJsonWordSet = /* @__PURE__ */ new Set();
219
+ const whiteSet = /* @__PURE__ */ new Set();
220
+ try {
221
+ await Promise.all([
222
+ config.whiteListJson ? fetch(config.whiteListJson).then((r) => r.json()).then((arr) => {
223
+ arr.forEach((s) => whiteSet.add(s.toLowerCase()));
224
+ }) : null,
225
+ config.blackListJson ? fetch(config.blackListJson).then((r) => r.json()).then((arr) => {
226
+ arr.forEach((s) => {
227
+ const lower = s.toLowerCase();
228
+ if (isPunct(lower)) blackJsonPunctSet.add(lower);
229
+ else blackJsonWordSet.add(lower);
230
+ });
231
+ }) : null
232
+ ]);
233
+ globalResolved = {
234
+ ...globalResolved,
235
+ blackJsonPunctSet,
236
+ blackJsonWordSet,
237
+ whiteSet
238
+ };
239
+ return { success: true };
240
+ } catch (error) {
241
+ return { success: false, error };
242
+ }
243
+ };
244
+ var resolveConfig = (config) => {
245
+ var _a, _b, _c;
246
+ const merged = { ...globalResolved, ...config != null ? config : {} };
247
+ merged.blackPunctSet = /* @__PURE__ */ new Set([...(_a = merged.blackJsonPunctSet) != null ? _a : []]);
248
+ merged.blackWordSet = /* @__PURE__ */ new Set([...(_b = merged.blackJsonWordSet) != null ? _b : []]);
249
+ (_c = merged.blackList) == null ? void 0 : _c.forEach((s) => {
250
+ var _a2, _b2;
251
+ const lower = s.toLowerCase();
252
+ if (isPunct(lower)) {
253
+ (_a2 = merged.blackPunctSet) == null ? void 0 : _a2.add(lower);
254
+ } else {
255
+ (_b2 = merged.blackWordSet) == null ? void 0 : _b2.add(lower);
256
+ }
257
+ });
258
+ if (merged.scoreQuestionWords)
259
+ merged.scoreQuestionWords = merged.scoreQuestionWords.map((s) => s.toLowerCase());
260
+ if (merged.scorePronouns) merged.scorePronouns = merged.scorePronouns.map((s) => s.toLowerCase());
261
+ if (merged.scoreCommonVerbs) merged.scoreCommonVerbs = merged.scoreCommonVerbs.map((s) => s.toLowerCase());
262
+ if (merged.scoreStopwords) merged.scoreStopwords = merged.scoreStopwords.map((s) => s.toLowerCase());
263
+ return merged;
264
+ };
265
+ var isSearch = (value, config) => {
266
+ var _a, _b, _c, _d, _e, _f, _g, _h;
267
+ const c = resolveConfig(config);
268
+ const lower = value.toLowerCase();
269
+ const tokens = tokenize(lower);
270
+ 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
+ );
274
+ let result;
275
+ if (c.mode === "length") {
276
+ result = checkLength(lower, c);
277
+ } else if (c.mode === "mixed") {
278
+ result = checkList(lower, c) && checkLength(lower, c);
279
+ } else if (c.mode === "score") {
280
+ result = scoreQuery(lower, c);
281
+ } else {
282
+ result = checkList(lower, c);
283
+ }
284
+ console.log(`\u2192 Result: ${result}`);
285
+ console.groupEnd();
286
+ return result;
287
+ };
288
+ var clarityUtils = { setup, isSearch };
289
+ // Annotate the CommonJS export names for ESM import in node:
290
+ 0 && (module.exports = {
291
+ clarityUtils
292
+ });
293
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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,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,SAA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AO,mBAAmB,OAAO,iBAAiB,IAAI,OAAK,EAAE,YAAY,CAAC;AACvG,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"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,266 @@
1
+ // src/utils.ts
2
+ var isPunct = (s) => !/\w/.test(s);
3
+ var tokenize = (query) => query.split(/\s+/).filter(Boolean);
4
+
5
+ // src/modes/length.ts
6
+ var checkLength = (value, c) => {
7
+ if (!c.maxLength) {
8
+ console.log(" checkLength \u2192 true (no maxLength configured)");
9
+ return true;
10
+ }
11
+ const wordCount = tokenize(value).length;
12
+ const result = wordCount <= c.maxLength;
13
+ console.log(` checkLength \u2192 ${result} (wordCount=${wordCount} maxLength=${c.maxLength})`);
14
+ return result;
15
+ };
16
+
17
+ // src/modes/list.ts
18
+ var checkPuncts = (lower, c) => {
19
+ var _a;
20
+ for (const punct of (_a = c.blackPunctSet) != null ? _a : []) {
21
+ if (lower.includes(punct)) {
22
+ console.log(` punct "${punct}" found in sentence \u2192 false (blacklisted)`);
23
+ return false;
24
+ }
25
+ }
26
+ return true;
27
+ };
28
+ var checkWord = (word, c) => {
29
+ var _a, _b, _c, _d, _e, _f, _g;
30
+ if ((_a = c.blackWordSet) == null ? void 0 : _a.has(word)) {
31
+ console.log(` word "${word}" \u2192 false (blacklisted)`);
32
+ return false;
33
+ }
34
+ const hasWhite = ((_c = (_b = c.whiteSet) == null ? void 0 : _b.size) != null ? _c : 0) > 0 || ((_e = (_d = c.whiteList) == null ? void 0 : _d.length) != null ? _e : 0) > 0;
35
+ if (hasWhite) {
36
+ const result = !!(((_f = c.whiteSet) == null ? void 0 : _f.has(word)) || ((_g = c.whiteList) == null ? void 0 : _g.some((s) => s.toLowerCase() === word)));
37
+ console.log(` word "${word}" \u2192 ${result} (whitelist check)`);
38
+ return result;
39
+ }
40
+ console.log(` word "${word}" \u2192 true`);
41
+ return true;
42
+ };
43
+ var checkList = (lower, c) => checkPuncts(lower, c) && tokenize(lower).every((word) => checkWord(word, c));
44
+
45
+ // src/enums.ts
46
+ var DEFAULT_QUESTION_WORDS = [
47
+ "who",
48
+ "what",
49
+ "when",
50
+ "where",
51
+ "why",
52
+ "how",
53
+ "can",
54
+ "should",
55
+ "could",
56
+ "would",
57
+ "is",
58
+ "are",
59
+ "do",
60
+ "does",
61
+ "did"
62
+ ];
63
+ var DEFAULT_PRONOUNS = [
64
+ "i",
65
+ "me",
66
+ "my",
67
+ "mine",
68
+ "we",
69
+ "us",
70
+ "our",
71
+ "you",
72
+ "your",
73
+ "it",
74
+ "they",
75
+ "them"
76
+ ];
77
+ var DEFAULT_COMMON_VERBS = [
78
+ "is",
79
+ "are",
80
+ "was",
81
+ "were",
82
+ "do",
83
+ "does",
84
+ "did",
85
+ "make",
86
+ "create",
87
+ "find",
88
+ "get",
89
+ "buy",
90
+ "use",
91
+ "install",
92
+ "fix",
93
+ "recommend",
94
+ "tell",
95
+ "show"
96
+ ];
97
+ var DEFAULT_STOPWORDS = [
98
+ "the",
99
+ "is",
100
+ "in",
101
+ "on",
102
+ "at",
103
+ "to",
104
+ "for",
105
+ "of",
106
+ "and",
107
+ "a",
108
+ "an",
109
+ "with",
110
+ "from"
111
+ ];
112
+
113
+ // src/modes/score.ts
114
+ var scoreQuery = (query, c) => {
115
+ var _a, _b, _c, _d;
116
+ const tokens = tokenize(query);
117
+ if (tokens.length === 0) return true;
118
+ const questionWords = (_a = c.scoreQuestionWords) != null ? _a : DEFAULT_QUESTION_WORDS;
119
+ const pronouns = (_b = c.scorePronouns) != null ? _b : DEFAULT_PRONOUNS;
120
+ const commonVerbs = (_c = c.scoreCommonVerbs) != null ? _c : DEFAULT_COMMON_VERBS;
121
+ const stopwords = (_d = c.scoreStopwords) != null ? _d : DEFAULT_STOPWORDS;
122
+ let scoreKeyword = 0;
123
+ let scoreConversational = 0;
124
+ if (tokens.length <= 3) {
125
+ scoreKeyword += 2;
126
+ console.log(` [A] word count=${tokens.length} \u22643 \u2192 keyword +2`);
127
+ } else if (tokens.length >= 6) {
128
+ scoreConversational += 2;
129
+ console.log(` [A] word count=${tokens.length} \u22656 \u2192 conversational +2`);
130
+ } else {
131
+ console.log(` [A] word count=${tokens.length} (no score)`);
132
+ }
133
+ const matchedQuestionWords = tokens.filter((t) => questionWords.includes(t));
134
+ if (matchedQuestionWords.length > 0) {
135
+ scoreConversational += 2;
136
+ console.log(` [B] question words found: [${matchedQuestionWords.join(", ")}] \u2192 conversational +2`);
137
+ } else {
138
+ console.log(` [B] no question words`);
139
+ }
140
+ const matchedPronouns = tokens.filter((t) => pronouns.includes(t));
141
+ if (matchedPronouns.length > 0) {
142
+ scoreConversational += 1;
143
+ console.log(` [C] pronouns found: [${matchedPronouns.join(", ")}] \u2192 conversational +1`);
144
+ } else {
145
+ console.log(` [C] no pronouns`);
146
+ }
147
+ const matchedVerbs = tokens.filter((t) => commonVerbs.includes(t));
148
+ if (matchedVerbs.length > 0) {
149
+ scoreConversational += 1;
150
+ console.log(` [D] verbs found: [${matchedVerbs.join(", ")}] \u2192 conversational +1`);
151
+ } else {
152
+ console.log(` [D] no common verbs`);
153
+ }
154
+ if (query.includes("?")) {
155
+ scoreConversational += 3;
156
+ console.log(` [E] "?" found \u2192 conversational +3`);
157
+ } else {
158
+ console.log(` [E] no "?"`);
159
+ }
160
+ const stopwordCount = tokens.filter((t) => stopwords.includes(t)).length;
161
+ const stopwordRatio = stopwordCount / tokens.length;
162
+ if (stopwordRatio > 0.4) {
163
+ scoreConversational += 2;
164
+ console.log(
165
+ ` [F] stopword ratio=${stopwordRatio.toFixed(2)} (${stopwordCount}/${tokens.length}) >0.4 \u2192 conversational +2`
166
+ );
167
+ } else {
168
+ scoreKeyword += 1;
169
+ console.log(
170
+ ` [F] stopword ratio=${stopwordRatio.toFixed(2)} (${stopwordCount}/${tokens.length}) \u22640.4 \u2192 keyword +1`
171
+ );
172
+ }
173
+ const avgLen = tokens.reduce((sum, t) => sum + t.length, 0) / tokens.length;
174
+ if (avgLen >= 6) {
175
+ scoreKeyword += 1;
176
+ console.log(` [G] avg token length=${avgLen.toFixed(2)} \u22656 \u2192 keyword +1`);
177
+ } else {
178
+ console.log(` [G] avg token length=${avgLen.toFixed(2)} (no score)`);
179
+ }
180
+ const result = scoreKeyword >= scoreConversational;
181
+ console.log(
182
+ ` scores: keyword=${scoreKeyword} conversational=${scoreConversational} \u2192 ${result ? "keyword" : "conversational"}`
183
+ );
184
+ return result;
185
+ };
186
+
187
+ // src/index.ts
188
+ var globalResolved = {};
189
+ var setup = async (config) => {
190
+ globalResolved = { ...config };
191
+ const blackJsonPunctSet = /* @__PURE__ */ new Set();
192
+ const blackJsonWordSet = /* @__PURE__ */ new Set();
193
+ const whiteSet = /* @__PURE__ */ new Set();
194
+ try {
195
+ await Promise.all([
196
+ config.whiteListJson ? fetch(config.whiteListJson).then((r) => r.json()).then((arr) => {
197
+ arr.forEach((s) => whiteSet.add(s.toLowerCase()));
198
+ }) : null,
199
+ config.blackListJson ? fetch(config.blackListJson).then((r) => r.json()).then((arr) => {
200
+ arr.forEach((s) => {
201
+ const lower = s.toLowerCase();
202
+ if (isPunct(lower)) blackJsonPunctSet.add(lower);
203
+ else blackJsonWordSet.add(lower);
204
+ });
205
+ }) : null
206
+ ]);
207
+ globalResolved = {
208
+ ...globalResolved,
209
+ blackJsonPunctSet,
210
+ blackJsonWordSet,
211
+ whiteSet
212
+ };
213
+ return { success: true };
214
+ } catch (error) {
215
+ return { success: false, error };
216
+ }
217
+ };
218
+ var resolveConfig = (config) => {
219
+ var _a, _b, _c;
220
+ const merged = { ...globalResolved, ...config != null ? config : {} };
221
+ merged.blackPunctSet = /* @__PURE__ */ new Set([...(_a = merged.blackJsonPunctSet) != null ? _a : []]);
222
+ merged.blackWordSet = /* @__PURE__ */ new Set([...(_b = merged.blackJsonWordSet) != null ? _b : []]);
223
+ (_c = merged.blackList) == null ? void 0 : _c.forEach((s) => {
224
+ var _a2, _b2;
225
+ const lower = s.toLowerCase();
226
+ if (isPunct(lower)) {
227
+ (_a2 = merged.blackPunctSet) == null ? void 0 : _a2.add(lower);
228
+ } else {
229
+ (_b2 = merged.blackWordSet) == null ? void 0 : _b2.add(lower);
230
+ }
231
+ });
232
+ if (merged.scoreQuestionWords)
233
+ merged.scoreQuestionWords = merged.scoreQuestionWords.map((s) => s.toLowerCase());
234
+ if (merged.scorePronouns) merged.scorePronouns = merged.scorePronouns.map((s) => s.toLowerCase());
235
+ if (merged.scoreCommonVerbs) merged.scoreCommonVerbs = merged.scoreCommonVerbs.map((s) => s.toLowerCase());
236
+ if (merged.scoreStopwords) merged.scoreStopwords = merged.scoreStopwords.map((s) => s.toLowerCase());
237
+ return merged;
238
+ };
239
+ var isSearch = (value, config) => {
240
+ var _a, _b, _c, _d, _e, _f, _g, _h;
241
+ const c = resolveConfig(config);
242
+ const lower = value.toLowerCase();
243
+ const tokens = tokenize(lower);
244
+ 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
+ );
248
+ let result;
249
+ if (c.mode === "length") {
250
+ result = checkLength(lower, c);
251
+ } else if (c.mode === "mixed") {
252
+ result = checkList(lower, c) && checkLength(lower, c);
253
+ } else if (c.mode === "score") {
254
+ result = scoreQuery(lower, c);
255
+ } else {
256
+ result = checkList(lower, c);
257
+ }
258
+ console.log(`\u2192 Result: ${result}`);
259
+ console.groupEnd();
260
+ return result;
261
+ };
262
+ var clarityUtils = { setup, isSearch };
263
+ export {
264
+ clarityUtils
265
+ };
266
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +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,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AAyB,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"]}
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@bloomreach/clarity-utils",
3
+ "version": "1.0.0",
4
+ "description": "Utility functions for Bloomreach Clarity integrations",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.mjs",
11
+ "require": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsup",
20
+ "dev": "tsup --watch",
21
+ "prepublishOnly": "npm run build"
22
+ },
23
+ "devDependencies": {
24
+ "tsup": "^8.3.0",
25
+ "typescript": "^5.5.0"
26
+ }
27
+ }