@bloomreach/clarity-utils 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.global.js +1 -1
- package/dist/index.js +21 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +21 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.global.js
CHANGED
|
@@ -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
|
|
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 q={};_(q,{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},R=(t,o)=>Q(t,o)&&g(t).every(e=>J(e,o));var P=["who","what","when","where","why","how","can","should","could","would","is","are","do","does","did"],W=["i","me","my","mine","we","us","our","you","your","it","they","them"],E=["is","are","was","were","do","does","did","make","create","find","get","buy","use","install","fix","recommend","tell","show"],U=["the","is","in","on","at","to","for","of","and","a","an","with","from"];var L=(t,o)=>{var $,y,v,x;let e=g(t);if(e.length===0)return!0;let s=($=o.scoreQuestionWords)!=null?$:P,n=(y=o.scorePronouns)!=null?y:W,r=(v=o.scoreCommonVerbs)!=null?v:E,c=(x=o.scoreStopwords)!=null?x:U,i=0,l=0;e.length<=3?(i+=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 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] question words: none");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] pronouns: none");let h=e.filter(a=>r.includes(a));h.length>0?(l+=1,console.log(` [D] common verbs: found [${h.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 m=e.filter(a=>c.includes(a)).length,f=m/e.length;f>.4?(l+=2,console.log(` [F] stopword ratio: ${f.toFixed(2)} (${m}/${e.length}) >0.4 \u2192 conversational +2`)):(i+=1,console.log(` [F] stopword ratio: ${f.toFixed(2)} (${m}/${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,m,f;let e=V(o),s=t.toLowerCase(),n=g(s);console.group(`[isSearch] "${t}" | mode=${e.mode} | tokens=[${n.join(", ")}]`),(e.mode==="mixed"||e.mode==="list")&&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=${(f=(m=e.whiteList)==null?void 0:m.length)!=null?f:0}`);let r;return e.mode==="length"?r=C(s,e):e.mode==="mixed"?r=R(s,e)&&C(s,e):e.mode==="score"?r=L(s,e):r=L(s,e),console.log(`\u2192 Result: ${r}`),console.groupEnd(),r},B={setup:N,isSearch:j};return z(q);})();
|
|
2
2
|
window.clarityUtils=tmp.clarityUtils;
|
package/dist/index.js
CHANGED
|
@@ -149,59 +149,59 @@ var scoreQuery = (query, c) => {
|
|
|
149
149
|
let scoreConversational = 0;
|
|
150
150
|
if (tokens.length <= 3) {
|
|
151
151
|
scoreKeyword += 2;
|
|
152
|
-
console.log(` [A] word count=${tokens.length} \u22643 \u2192 keyword +2`);
|
|
152
|
+
console.log(` [A] token count: word count=${tokens.length} \u22643 \u2192 keyword +2`);
|
|
153
153
|
} else if (tokens.length >= 6) {
|
|
154
154
|
scoreConversational += 2;
|
|
155
|
-
console.log(` [A] word count=${tokens.length} \u22656 \u2192 conversational +2`);
|
|
155
|
+
console.log(` [A] token count: word count=${tokens.length} \u22656 \u2192 conversational +2`);
|
|
156
156
|
} else {
|
|
157
|
-
console.log(` [A] word count=${tokens.length} (no score)`);
|
|
157
|
+
console.log(` [A] token count: word count=${tokens.length} (no score)`);
|
|
158
158
|
}
|
|
159
159
|
const matchedQuestionWords = tokens.filter((t) => questionWords.includes(t));
|
|
160
160
|
if (matchedQuestionWords.length > 0) {
|
|
161
161
|
scoreConversational += 2;
|
|
162
|
-
console.log(` [B] question words found
|
|
162
|
+
console.log(` [B] question words: found [${matchedQuestionWords.join(", ")}] \u2192 conversational +2`);
|
|
163
163
|
} else {
|
|
164
|
-
console.log(` [B]
|
|
164
|
+
console.log(` [B] question words: none`);
|
|
165
165
|
}
|
|
166
166
|
const matchedPronouns = tokens.filter((t) => pronouns.includes(t));
|
|
167
167
|
if (matchedPronouns.length > 0) {
|
|
168
168
|
scoreConversational += 1;
|
|
169
|
-
console.log(` [C] pronouns found
|
|
169
|
+
console.log(` [C] pronouns: found [${matchedPronouns.join(", ")}] \u2192 conversational +1`);
|
|
170
170
|
} else {
|
|
171
|
-
console.log(` [C]
|
|
171
|
+
console.log(` [C] pronouns: none`);
|
|
172
172
|
}
|
|
173
173
|
const matchedVerbs = tokens.filter((t) => commonVerbs.includes(t));
|
|
174
174
|
if (matchedVerbs.length > 0) {
|
|
175
175
|
scoreConversational += 1;
|
|
176
|
-
console.log(` [D] verbs found
|
|
176
|
+
console.log(` [D] common verbs: found [${matchedVerbs.join(", ")}] \u2192 conversational +1`);
|
|
177
177
|
} else {
|
|
178
|
-
console.log(` [D]
|
|
178
|
+
console.log(` [D] common verbs: none`);
|
|
179
179
|
}
|
|
180
180
|
if (query.includes("?")) {
|
|
181
181
|
scoreConversational += 3;
|
|
182
|
-
console.log(` [E]
|
|
182
|
+
console.log(` [E] question mark: found \u2192 conversational +3`);
|
|
183
183
|
} else {
|
|
184
|
-
console.log(` [E]
|
|
184
|
+
console.log(` [E] question mark: none`);
|
|
185
185
|
}
|
|
186
186
|
const stopwordCount = tokens.filter((t) => stopwords.includes(t)).length;
|
|
187
187
|
const stopwordRatio = stopwordCount / tokens.length;
|
|
188
188
|
if (stopwordRatio > 0.4) {
|
|
189
189
|
scoreConversational += 2;
|
|
190
190
|
console.log(
|
|
191
|
-
` [F] stopword ratio
|
|
191
|
+
` [F] stopword ratio: ${stopwordRatio.toFixed(2)} (${stopwordCount}/${tokens.length}) >0.4 \u2192 conversational +2`
|
|
192
192
|
);
|
|
193
193
|
} else {
|
|
194
194
|
scoreKeyword += 1;
|
|
195
195
|
console.log(
|
|
196
|
-
` [F] stopword ratio
|
|
196
|
+
` [F] stopword ratio: ${stopwordRatio.toFixed(2)} (${stopwordCount}/${tokens.length}) \u22640.4 \u2192 keyword +1`
|
|
197
197
|
);
|
|
198
198
|
}
|
|
199
199
|
const avgLen = tokens.reduce((sum, t) => sum + t.length, 0) / tokens.length;
|
|
200
200
|
if (avgLen >= 6) {
|
|
201
201
|
scoreKeyword += 1;
|
|
202
|
-
console.log(` [G] avg token length
|
|
202
|
+
console.log(` [G] avg token length: ${avgLen.toFixed(2)} \u22656 \u2192 keyword +1`);
|
|
203
203
|
} else {
|
|
204
|
-
console.log(` [G] avg token length
|
|
204
|
+
console.log(` [G] avg token length: ${avgLen.toFixed(2)} (no score)`);
|
|
205
205
|
}
|
|
206
206
|
const result = scoreKeyword >= scoreConversational;
|
|
207
207
|
console.log(
|
|
@@ -268,9 +268,11 @@ var isSearch = (value, config) => {
|
|
|
268
268
|
const lower = value.toLowerCase();
|
|
269
269
|
const tokens = tokenize(lower);
|
|
270
270
|
console.group(`[isSearch] "${value}" | mode=${c.mode} | tokens=[${tokens.join(", ")}]`);
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
271
|
+
if (c.mode === "mixed" || c.mode === "list") {
|
|
272
|
+
console.log(
|
|
273
|
+
`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}`
|
|
274
|
+
);
|
|
275
|
+
}
|
|
274
276
|
let result;
|
|
275
277
|
if (c.mode === "length") {
|
|
276
278
|
result = checkLength(lower, c);
|
|
@@ -279,7 +281,7 @@ var isSearch = (value, config) => {
|
|
|
279
281
|
} else if (c.mode === "score") {
|
|
280
282
|
result = scoreQuery(lower, c);
|
|
281
283
|
} else {
|
|
282
|
-
result =
|
|
284
|
+
result = scoreQuery(lower, c);
|
|
283
285
|
}
|
|
284
286
|
console.log(`\u2192 Result: ${result}`);
|
|
285
287
|
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,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,cAA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Ac,IAAI,OAAK,EAAE,YAAY,CAAC;AAC9F,MAAI,OAAO,iBAAkB,QAAO,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"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/utils.ts","../src/modes/length.ts","../src/modes/list.ts","../src/enums.ts","../src/modes/score.ts"],"sourcesContent":["import { checkLength } from './modes/length'\nimport { checkList } from './modes/list'\nimport { scoreQuery } from './modes/score'\nimport type { ClarityUtilsConfig, ResolvedConfig } from './types'\nimport { isPunct, tokenize } from './utils'\n\nlet globalResolved: ResolvedConfig = {}\n\nconst setup = async (\n config: ClarityUtilsConfig\n): Promise<{ success: true } | { success: false; error: unknown }> => {\n globalResolved = { ...config }\n const blackJsonPunctSet = new Set<string>()\n const blackJsonWordSet = new Set<string>()\n const whiteSet = new Set<string>()\n\n try {\n await Promise.all([\n config.whiteListJson\n ? fetch(config.whiteListJson)\n .then(r => r.json())\n .then((arr: string[]) => {\n arr.forEach(s => whiteSet.add(s.toLowerCase()))\n })\n : null,\n config.blackListJson\n ? fetch(config.blackListJson)\n .then(r => r.json())\n .then((arr: string[]) => {\n arr.forEach(s => {\n const lower = s.toLowerCase()\n if (isPunct(lower)) blackJsonPunctSet.add(lower)\n else blackJsonWordSet.add(lower)\n })\n })\n : null,\n ])\n globalResolved = {\n ...globalResolved,\n blackJsonPunctSet,\n blackJsonWordSet,\n whiteSet,\n }\n return { success: true }\n } catch (error) {\n return { success: false, error }\n }\n}\n\nconst resolveConfig = (config?: ClarityUtilsConfig): ResolvedConfig => {\n const merged = { ...globalResolved, ...(config ?? {}) }\n merged.blackPunctSet = new Set([...(merged.blackJsonPunctSet ?? [])])\n merged.blackWordSet = new Set([...(merged.blackJsonWordSet ?? [])])\n merged.blackList?.forEach(s => {\n const lower = s.toLowerCase()\n if (isPunct(lower)) {\n merged.blackPunctSet?.add(lower)\n } else {\n merged.blackWordSet?.add(lower)\n }\n })\n\n if (merged.scoreQuestionWords)\n merged.scoreQuestionWords = merged.scoreQuestionWords.map(s => s.toLowerCase())\n if (merged.scorePronouns) merged.scorePronouns = merged.scorePronouns.map(s => s.toLowerCase())\n if (merged.scoreCommonVerbs) merged.scoreCommonVerbs = merged.scoreCommonVerbs.map(s => s.toLowerCase())\n if (merged.scoreStopwords) merged.scoreStopwords = merged.scoreStopwords.map(s => s.toLowerCase())\n\n return merged\n}\n\nconst isSearch = (value: string, config?: ClarityUtilsConfig): boolean => {\n const c = resolveConfig(config)\n const lower = value.toLowerCase()\n\n const tokens = tokenize(lower)\n console.group(`[isSearch] \"${value}\" | mode=${c.mode} | tokens=[${tokens.join(', ')}]`)\n if (c.mode === 'mixed' || c.mode === 'list') {\n console.log(\n `lists: blackWordSet=${c.blackWordSet?.size ?? 0} blackPunctSet=${c.blackPunctSet?.size ?? 0} whiteSet=${c.whiteSet?.size ?? 0} whiteList=${c.whiteList?.length ?? 0}`\n )\n }\n\n let result: boolean\n if (c.mode === 'length') {\n result = checkLength(lower, c)\n } else if (c.mode === 'mixed') {\n result = checkList(lower, c) && checkLength(lower, c)\n } else if (c.mode === 'score') {\n result = scoreQuery(lower, c)\n } else {\n result = scoreQuery(lower, c)\n }\n\n console.log(`→ Result: ${result}`)\n console.groupEnd()\n return result\n}\n\nexport const clarityUtils = { setup, isSearch }\n","export const isPunct = (s: string) => !/\\w/.test(s)\n\nexport const tokenize = (query: string) => query.split(/\\s+/).filter(Boolean)\n","import type { ResolvedConfig } from '../types'\nimport { tokenize } from '../utils'\n\nexport const checkLength = (value: string, c: ResolvedConfig): boolean => {\n if (!c.maxLength) {\n console.log(' checkLength → true (no maxLength configured)')\n return true\n }\n const wordCount = tokenize(value).length\n const result = wordCount <= c.maxLength\n console.log(` checkLength → ${result} (wordCount=${wordCount} maxLength=${c.maxLength})`)\n return result\n}\n","import type { ResolvedConfig } from '../types'\nimport { tokenize } from '../utils'\n\nconst checkPuncts = (lower: string, c: ResolvedConfig): boolean => {\n for (const punct of c.blackPunctSet ?? []) {\n if (lower.includes(punct)) {\n console.log(` punct \"${punct}\" found in sentence → false (blacklisted)`)\n return false\n }\n }\n return true\n}\n\nconst checkWord = (word: string, c: ResolvedConfig): boolean => {\n if (c.blackWordSet?.has(word)) {\n console.log(` word \"${word}\" → false (blacklisted)`)\n return false\n }\n const hasWhite = (c.whiteSet?.size ?? 0) > 0 || (c.whiteList?.length ?? 0) > 0\n if (hasWhite) {\n const result = !!(c.whiteSet?.has(word) || c.whiteList?.some((s: string) => s.toLowerCase() === word))\n console.log(` word \"${word}\" → ${result} (whitelist check)`)\n return result\n }\n console.log(` word \"${word}\" → true`)\n return true\n}\n\nexport const checkList = (lower: string, c: ResolvedConfig): boolean =>\n checkPuncts(lower, c) && tokenize(lower).every(word => checkWord(word, c))\n","export const DEFAULT_QUESTION_WORDS = [\n 'who',\n 'what',\n 'when',\n 'where',\n 'why',\n 'how',\n 'can',\n 'should',\n 'could',\n 'would',\n 'is',\n 'are',\n 'do',\n 'does',\n 'did',\n]\n\nexport const DEFAULT_PRONOUNS = [\n 'i',\n 'me',\n 'my',\n 'mine',\n 'we',\n 'us',\n 'our',\n 'you',\n 'your',\n 'it',\n 'they',\n 'them',\n]\n\nexport const DEFAULT_COMMON_VERBS = [\n 'is',\n 'are',\n 'was',\n 'were',\n 'do',\n 'does',\n 'did',\n 'make',\n 'create',\n 'find',\n 'get',\n 'buy',\n 'use',\n 'install',\n 'fix',\n 'recommend',\n 'tell',\n 'show',\n]\n\nexport const DEFAULT_STOPWORDS = [\n 'the',\n 'is',\n 'in',\n 'on',\n 'at',\n 'to',\n 'for',\n 'of',\n 'and',\n 'a',\n 'an',\n 'with',\n 'from',\n]\n","import { DEFAULT_COMMON_VERBS, DEFAULT_PRONOUNS, DEFAULT_QUESTION_WORDS, DEFAULT_STOPWORDS } from '../enums'\nimport type { ResolvedConfig } from '../types'\nimport { tokenize } from '../utils'\n\nexport const scoreQuery = (query: string, c: ResolvedConfig): boolean => {\n const tokens = tokenize(query)\n if (tokens.length === 0) return true\n\n const questionWords = c.scoreQuestionWords ?? DEFAULT_QUESTION_WORDS\n const pronouns = c.scorePronouns ?? DEFAULT_PRONOUNS\n const commonVerbs = c.scoreCommonVerbs ?? DEFAULT_COMMON_VERBS\n const stopwords = c.scoreStopwords ?? DEFAULT_STOPWORDS\n\n let scoreKeyword = 0\n let scoreConversational = 0\n\n if (tokens.length <= 3) {\n scoreKeyword += 2\n console.log(` [A] token count: word count=${tokens.length} ≤3 → keyword +2`)\n } else if (tokens.length >= 6) {\n scoreConversational += 2\n console.log(` [A] token count: word count=${tokens.length} ≥6 → conversational +2`)\n } else {\n console.log(` [A] token count: word count=${tokens.length} (no score)`)\n }\n\n const matchedQuestionWords = tokens.filter(t => questionWords.includes(t))\n if (matchedQuestionWords.length > 0) {\n scoreConversational += 2\n console.log(` [B] question words: found [${matchedQuestionWords.join(', ')}] → conversational +2`)\n } else {\n console.log(` [B] question words: none`)\n }\n\n const matchedPronouns = tokens.filter(t => pronouns.includes(t))\n if (matchedPronouns.length > 0) {\n scoreConversational += 1\n console.log(` [C] pronouns: found [${matchedPronouns.join(', ')}] → conversational +1`)\n } else {\n console.log(` [C] pronouns: none`)\n }\n\n const matchedVerbs = tokens.filter(t => commonVerbs.includes(t))\n if (matchedVerbs.length > 0) {\n scoreConversational += 1\n console.log(` [D] common verbs: found [${matchedVerbs.join(', ')}] → conversational +1`)\n } else {\n console.log(` [D] common verbs: none`)\n }\n\n if (query.includes('?')) {\n scoreConversational += 3\n console.log(` [E] question mark: found → conversational +3`)\n } else {\n console.log(` [E] question mark: none`)\n }\n\n const stopwordCount = tokens.filter(t => stopwords.includes(t)).length\n const stopwordRatio = stopwordCount / tokens.length\n if (stopwordRatio > 0.4) {\n scoreConversational += 2\n console.log(\n ` [F] stopword ratio: ${stopwordRatio.toFixed(2)} (${stopwordCount}/${tokens.length}) >0.4 → conversational +2`\n )\n } else {\n scoreKeyword += 1\n console.log(\n ` [F] stopword ratio: ${stopwordRatio.toFixed(2)} (${stopwordCount}/${tokens.length}) ≤0.4 → keyword +1`\n )\n }\n\n const avgLen = tokens.reduce((sum, t) => sum + t.length, 0) / tokens.length\n if (avgLen >= 6) {\n scoreKeyword += 1\n console.log(` [G] avg token length: ${avgLen.toFixed(2)} ≥6 → keyword +1`)\n } else {\n console.log(` [G] avg token length: ${avgLen.toFixed(2)} (no score)`)\n }\n\n const result = scoreKeyword >= scoreConversational\n console.log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W,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
|
@@ -123,59 +123,59 @@ var scoreQuery = (query, c) => {
|
|
|
123
123
|
let scoreConversational = 0;
|
|
124
124
|
if (tokens.length <= 3) {
|
|
125
125
|
scoreKeyword += 2;
|
|
126
|
-
console.log(` [A] word count=${tokens.length} \u22643 \u2192 keyword +2`);
|
|
126
|
+
console.log(` [A] token count: word count=${tokens.length} \u22643 \u2192 keyword +2`);
|
|
127
127
|
} else if (tokens.length >= 6) {
|
|
128
128
|
scoreConversational += 2;
|
|
129
|
-
console.log(` [A] word count=${tokens.length} \u22656 \u2192 conversational +2`);
|
|
129
|
+
console.log(` [A] token count: word count=${tokens.length} \u22656 \u2192 conversational +2`);
|
|
130
130
|
} else {
|
|
131
|
-
console.log(` [A] word count=${tokens.length} (no score)`);
|
|
131
|
+
console.log(` [A] token count: word count=${tokens.length} (no score)`);
|
|
132
132
|
}
|
|
133
133
|
const matchedQuestionWords = tokens.filter((t) => questionWords.includes(t));
|
|
134
134
|
if (matchedQuestionWords.length > 0) {
|
|
135
135
|
scoreConversational += 2;
|
|
136
|
-
console.log(` [B] question words found
|
|
136
|
+
console.log(` [B] question words: found [${matchedQuestionWords.join(", ")}] \u2192 conversational +2`);
|
|
137
137
|
} else {
|
|
138
|
-
console.log(` [B]
|
|
138
|
+
console.log(` [B] question words: none`);
|
|
139
139
|
}
|
|
140
140
|
const matchedPronouns = tokens.filter((t) => pronouns.includes(t));
|
|
141
141
|
if (matchedPronouns.length > 0) {
|
|
142
142
|
scoreConversational += 1;
|
|
143
|
-
console.log(` [C] pronouns found
|
|
143
|
+
console.log(` [C] pronouns: found [${matchedPronouns.join(", ")}] \u2192 conversational +1`);
|
|
144
144
|
} else {
|
|
145
|
-
console.log(` [C]
|
|
145
|
+
console.log(` [C] pronouns: none`);
|
|
146
146
|
}
|
|
147
147
|
const matchedVerbs = tokens.filter((t) => commonVerbs.includes(t));
|
|
148
148
|
if (matchedVerbs.length > 0) {
|
|
149
149
|
scoreConversational += 1;
|
|
150
|
-
console.log(` [D] verbs found
|
|
150
|
+
console.log(` [D] common verbs: found [${matchedVerbs.join(", ")}] \u2192 conversational +1`);
|
|
151
151
|
} else {
|
|
152
|
-
console.log(` [D]
|
|
152
|
+
console.log(` [D] common verbs: none`);
|
|
153
153
|
}
|
|
154
154
|
if (query.includes("?")) {
|
|
155
155
|
scoreConversational += 3;
|
|
156
|
-
console.log(` [E]
|
|
156
|
+
console.log(` [E] question mark: found \u2192 conversational +3`);
|
|
157
157
|
} else {
|
|
158
|
-
console.log(` [E]
|
|
158
|
+
console.log(` [E] question mark: none`);
|
|
159
159
|
}
|
|
160
160
|
const stopwordCount = tokens.filter((t) => stopwords.includes(t)).length;
|
|
161
161
|
const stopwordRatio = stopwordCount / tokens.length;
|
|
162
162
|
if (stopwordRatio > 0.4) {
|
|
163
163
|
scoreConversational += 2;
|
|
164
164
|
console.log(
|
|
165
|
-
` [F] stopword ratio
|
|
165
|
+
` [F] stopword ratio: ${stopwordRatio.toFixed(2)} (${stopwordCount}/${tokens.length}) >0.4 \u2192 conversational +2`
|
|
166
166
|
);
|
|
167
167
|
} else {
|
|
168
168
|
scoreKeyword += 1;
|
|
169
169
|
console.log(
|
|
170
|
-
` [F] stopword ratio
|
|
170
|
+
` [F] stopword ratio: ${stopwordRatio.toFixed(2)} (${stopwordCount}/${tokens.length}) \u22640.4 \u2192 keyword +1`
|
|
171
171
|
);
|
|
172
172
|
}
|
|
173
173
|
const avgLen = tokens.reduce((sum, t) => sum + t.length, 0) / tokens.length;
|
|
174
174
|
if (avgLen >= 6) {
|
|
175
175
|
scoreKeyword += 1;
|
|
176
|
-
console.log(` [G] avg token length
|
|
176
|
+
console.log(` [G] avg token length: ${avgLen.toFixed(2)} \u22656 \u2192 keyword +1`);
|
|
177
177
|
} else {
|
|
178
|
-
console.log(` [G] avg token length
|
|
178
|
+
console.log(` [G] avg token length: ${avgLen.toFixed(2)} (no score)`);
|
|
179
179
|
}
|
|
180
180
|
const result = scoreKeyword >= scoreConversational;
|
|
181
181
|
console.log(
|
|
@@ -242,9 +242,11 @@ var isSearch = (value, config) => {
|
|
|
242
242
|
const lower = value.toLowerCase();
|
|
243
243
|
const tokens = tokenize(lower);
|
|
244
244
|
console.group(`[isSearch] "${value}" | mode=${c.mode} | tokens=[${tokens.join(", ")}]`);
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
245
|
+
if (c.mode === "mixed" || c.mode === "list") {
|
|
246
|
+
console.log(
|
|
247
|
+
`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}`
|
|
248
|
+
);
|
|
249
|
+
}
|
|
248
250
|
let result;
|
|
249
251
|
if (c.mode === "length") {
|
|
250
252
|
result = checkLength(lower, c);
|
|
@@ -253,7 +255,7 @@ var isSearch = (value, config) => {
|
|
|
253
255
|
} else if (c.mode === "score") {
|
|
254
256
|
result = scoreQuery(lower, c);
|
|
255
257
|
} else {
|
|
256
|
-
result =
|
|
258
|
+
result = scoreQuery(lower, c);
|
|
257
259
|
}
|
|
258
260
|
console.log(`\u2192 Result: ${result}`);
|
|
259
261
|
console.groupEnd();
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils.ts","../src/modes/length.ts","../src/modes/list.ts","../src/enums.ts","../src/modes/score.ts","../src/index.ts"],"sourcesContent":["export const isPunct = (s: string) => !/\\w/.test(s)\n\nexport const tokenize = (query: string) => query.split(/\\s+/).filter(Boolean)\n","import type { ResolvedConfig } from '../types'\nimport { tokenize } from '../utils'\n\nexport const checkLength = (value: string, c: ResolvedConfig): boolean => {\n if (!c.maxLength) {\n console.log(' checkLength → true (no maxLength configured)')\n return true\n }\n const wordCount = tokenize(value).length\n const result = wordCount <= c.maxLength\n console.log(` checkLength → ${result} (wordCount=${wordCount} maxLength=${c.maxLength})`)\n return result\n}\n","import type { ResolvedConfig } from '../types'\nimport { tokenize } from '../utils'\n\nconst checkPuncts = (lower: string, c: ResolvedConfig): boolean => {\n for (const punct of c.blackPunctSet ?? []) {\n if (lower.includes(punct)) {\n console.log(` punct \"${punct}\" found in sentence → false (blacklisted)`)\n return false\n }\n }\n return true\n}\n\nconst checkWord = (word: string, c: ResolvedConfig): boolean => {\n if (c.blackWordSet?.has(word)) {\n console.log(` word \"${word}\" → false (blacklisted)`)\n return false\n }\n const hasWhite = (c.whiteSet?.size ?? 0) > 0 || (c.whiteList?.length ?? 0) > 0\n if (hasWhite) {\n const result = !!(c.whiteSet?.has(word) || c.whiteList?.some((s: string) => s.toLowerCase() === word))\n console.log(` word \"${word}\" → ${result} (whitelist check)`)\n return result\n }\n console.log(` word \"${word}\" → true`)\n return true\n}\n\nexport const checkList = (lower: string, c: ResolvedConfig): boolean =>\n checkPuncts(lower, c) && tokenize(lower).every(word => checkWord(word, c))\n","export const DEFAULT_QUESTION_WORDS = [\n 'who',\n 'what',\n 'when',\n 'where',\n 'why',\n 'how',\n 'can',\n 'should',\n 'could',\n 'would',\n 'is',\n 'are',\n 'do',\n 'does',\n 'did',\n]\n\nexport const DEFAULT_PRONOUNS = [\n 'i',\n 'me',\n 'my',\n 'mine',\n 'we',\n 'us',\n 'our',\n 'you',\n 'your',\n 'it',\n 'they',\n 'them',\n]\n\nexport const DEFAULT_COMMON_VERBS = [\n 'is',\n 'are',\n 'was',\n 'were',\n 'do',\n 'does',\n 'did',\n 'make',\n 'create',\n 'find',\n 'get',\n 'buy',\n 'use',\n 'install',\n 'fix',\n 'recommend',\n 'tell',\n 'show',\n]\n\nexport const DEFAULT_STOPWORDS = [\n 'the',\n 'is',\n 'in',\n 'on',\n 'at',\n 'to',\n 'for',\n 'of',\n 'and',\n 'a',\n 'an',\n 'with',\n 'from',\n]\n","import { DEFAULT_COMMON_VERBS, DEFAULT_PRONOUNS, DEFAULT_QUESTION_WORDS, DEFAULT_STOPWORDS } from '../enums'\nimport type { ResolvedConfig } from '../types'\nimport { tokenize } from '../utils'\n\nexport const scoreQuery = (query: string, c: ResolvedConfig): boolean => {\n const tokens = tokenize(query)\n if (tokens.length === 0) return true\n\n const questionWords = c.scoreQuestionWords ?? DEFAULT_QUESTION_WORDS\n const pronouns = c.scorePronouns ?? DEFAULT_PRONOUNS\n const commonVerbs = c.scoreCommonVerbs ?? DEFAULT_COMMON_VERBS\n const stopwords = c.scoreStopwords ?? DEFAULT_STOPWORDS\n\n let scoreKeyword = 0\n let scoreConversational = 0\n\n if (tokens.length <= 3) {\n scoreKeyword += 2\n console.log(` [A] 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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AAC;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\nexport const tokenize = (query: string) => query.split(/\\s+/).filter(Boolean)\n","import type { ResolvedConfig } from '../types'\nimport { tokenize } from '../utils'\n\nexport const checkLength = (value: string, c: ResolvedConfig): boolean => {\n if (!c.maxLength) {\n console.log(' checkLength → true (no maxLength configured)')\n return true\n }\n const wordCount = tokenize(value).length\n const result = wordCount <= c.maxLength\n console.log(` checkLength → ${result} (wordCount=${wordCount} maxLength=${c.maxLength})`)\n return result\n}\n","import type { ResolvedConfig } from '../types'\nimport { tokenize } from '../utils'\n\nconst checkPuncts = (lower: string, c: ResolvedConfig): boolean => {\n for (const punct of c.blackPunctSet ?? []) {\n if (lower.includes(punct)) {\n console.log(` punct \"${punct}\" found in sentence → false (blacklisted)`)\n return false\n }\n }\n return true\n}\n\nconst checkWord = (word: string, c: ResolvedConfig): boolean => {\n if (c.blackWordSet?.has(word)) {\n console.log(` word \"${word}\" → false (blacklisted)`)\n return false\n }\n const hasWhite = (c.whiteSet?.size ?? 0) > 0 || (c.whiteList?.length ?? 0) > 0\n if (hasWhite) {\n const result = !!(c.whiteSet?.has(word) || c.whiteList?.some((s: string) => s.toLowerCase() === word))\n console.log(` word \"${word}\" → ${result} (whitelist check)`)\n return result\n }\n console.log(` word \"${word}\" → true`)\n return true\n}\n\nexport const checkList = (lower: string, c: ResolvedConfig): boolean =>\n checkPuncts(lower, c) && tokenize(lower).every(word => checkWord(word, c))\n","export const DEFAULT_QUESTION_WORDS = [\n 'who',\n 'what',\n 'when',\n 'where',\n 'why',\n 'how',\n 'can',\n 'should',\n 'could',\n 'would',\n 'is',\n 'are',\n 'do',\n 'does',\n 'did',\n]\n\nexport const DEFAULT_PRONOUNS = [\n 'i',\n 'me',\n 'my',\n 'mine',\n 'we',\n 'us',\n 'our',\n 'you',\n 'your',\n 'it',\n 'they',\n 'them',\n]\n\nexport const DEFAULT_COMMON_VERBS = [\n 'is',\n 'are',\n 'was',\n 'were',\n 'do',\n 'does',\n 'did',\n 'make',\n 'create',\n 'find',\n 'get',\n 'buy',\n 'use',\n 'install',\n 'fix',\n 'recommend',\n 'tell',\n 'show',\n]\n\nexport const DEFAULT_STOPWORDS = [\n 'the',\n 'is',\n 'in',\n 'on',\n 'at',\n 'to',\n 'for',\n 'of',\n 'and',\n 'a',\n 'an',\n 'with',\n 'from',\n]\n","import { DEFAULT_COMMON_VERBS, DEFAULT_PRONOUNS, DEFAULT_QUESTION_WORDS, DEFAULT_STOPWORDS } from '../enums'\nimport type { ResolvedConfig } from '../types'\nimport { tokenize } from '../utils'\n\nexport const scoreQuery = (query: string, c: ResolvedConfig): boolean => {\n const tokens = tokenize(query)\n if (tokens.length === 0) return true\n\n const questionWords = c.scoreQuestionWords ?? DEFAULT_QUESTION_WORDS\n const pronouns = c.scorePronouns ?? DEFAULT_PRONOUNS\n const commonVerbs = c.scoreCommonVerbs ?? DEFAULT_COMMON_VERBS\n const stopwords = c.scoreStopwords ?? DEFAULT_STOPWORDS\n\n let scoreKeyword = 0\n let scoreConversational = 0\n\n if (tokens.length <= 3) {\n scoreKeyword += 2\n console.log(` [A] token count: word count=${tokens.length} ≤3 → keyword +2`)\n } else if (tokens.length >= 6) {\n scoreConversational += 2\n console.log(` [A] token count: word count=${tokens.length} ≥6 → conversational +2`)\n } else {\n console.log(` [A] token count: word count=${tokens.length} (no score)`)\n }\n\n const matchedQuestionWords = tokens.filter(t => questionWords.includes(t))\n if (matchedQuestionWords.length > 0) {\n scoreConversational += 2\n console.log(` [B] question words: found [${matchedQuestionWords.join(', ')}] → conversational +2`)\n } else {\n console.log(` [B] question words: none`)\n }\n\n const matchedPronouns = tokens.filter(t => pronouns.includes(t))\n if (matchedPronouns.length > 0) {\n scoreConversational += 1\n console.log(` [C] pronouns: found [${matchedPronouns.join(', ')}] → conversational +1`)\n } else {\n console.log(` [C] pronouns: none`)\n }\n\n const matchedVerbs = tokens.filter(t => commonVerbs.includes(t))\n if (matchedVerbs.length > 0) {\n scoreConversational += 1\n console.log(` [D] common verbs: found [${matchedVerbs.join(', ')}] → conversational +1`)\n } else {\n console.log(` [D] common verbs: none`)\n }\n\n if (query.includes('?')) {\n scoreConversational += 3\n console.log(` [E] question mark: found → conversational +3`)\n } else {\n console.log(` [E] question mark: none`)\n }\n\n const stopwordCount = tokens.filter(t => stopwords.includes(t)).length\n const stopwordRatio = stopwordCount / tokens.length\n if (stopwordRatio > 0.4) {\n scoreConversational += 2\n console.log(\n ` [F] stopword ratio: ${stopwordRatio.toFixed(2)} (${stopwordCount}/${tokens.length}) >0.4 → conversational +2`\n )\n } else {\n scoreKeyword += 1\n console.log(\n ` [F] stopword ratio: ${stopwordRatio.toFixed(2)} (${stopwordCount}/${tokens.length}) ≤0.4 → keyword +1`\n )\n }\n\n const avgLen = tokens.reduce((sum, t) => sum + t.length, 0) / tokens.length\n if (avgLen >= 6) {\n scoreKeyword += 1\n console.log(` [G] avg token length: ${avgLen.toFixed(2)} ≥6 → keyword +1`)\n } else {\n console.log(` [G] avg token length: ${avgLen.toFixed(2)} (no score)`)\n }\n\n const result = scoreKeyword >= scoreConversational\n console.log(\n ` scores: keyword=${scoreKeyword} conversational=${scoreConversational} → ${result ? 'keyword' : 'conversational'}`\n )\n return result\n}\n","import { checkLength } from './modes/length'\nimport { checkList } from './modes/list'\nimport { scoreQuery } from './modes/score'\nimport type { ClarityUtilsConfig, ResolvedConfig } from './types'\nimport { isPunct, tokenize } from './utils'\n\nlet globalResolved: ResolvedConfig = {}\n\nconst setup = async (\n config: ClarityUtilsConfig\n): Promise<{ success: true } | { success: false; error: unknown }> => {\n globalResolved = { ...config }\n const blackJsonPunctSet = new Set<string>()\n const blackJsonWordSet = new Set<string>()\n const whiteSet = new Set<string>()\n\n try {\n await Promise.all([\n config.whiteListJson\n ? fetch(config.whiteListJson)\n .then(r => r.json())\n .then((arr: string[]) => {\n arr.forEach(s => whiteSet.add(s.toLowerCase()))\n })\n : null,\n config.blackListJson\n ? fetch(config.blackListJson)\n .then(r => r.json())\n .then((arr: string[]) => {\n arr.forEach(s => {\n const lower = s.toLowerCase()\n if (isPunct(lower)) blackJsonPunctSet.add(lower)\n else blackJsonWordSet.add(lower)\n })\n })\n : null,\n ])\n globalResolved = {\n ...globalResolved,\n blackJsonPunctSet,\n blackJsonWordSet,\n whiteSet,\n }\n return { success: true }\n } catch (error) {\n return { success: false, error }\n }\n}\n\nconst resolveConfig = (config?: ClarityUtilsConfig): ResolvedConfig => {\n const merged = { ...globalResolved, ...(config ?? {}) }\n merged.blackPunctSet = new Set([...(merged.blackJsonPunctSet ?? [])])\n merged.blackWordSet = new Set([...(merged.blackJsonWordSet ?? [])])\n merged.blackList?.forEach(s => {\n const lower = s.toLowerCase()\n if (isPunct(lower)) {\n merged.blackPunctSet?.add(lower)\n } else {\n merged.blackWordSet?.add(lower)\n }\n })\n\n if (merged.scoreQuestionWords)\n merged.scoreQuestionWords = merged.scoreQuestionWords.map(s => s.toLowerCase())\n if (merged.scorePronouns) merged.scorePronouns = merged.scorePronouns.map(s => s.toLowerCase())\n if (merged.scoreCommonVerbs) merged.scoreCommonVerbs = merged.scoreCommonVerbs.map(s => s.toLowerCase())\n if (merged.scoreStopwords) merged.scoreStopwords = merged.scoreStopwords.map(s => s.toLowerCase())\n\n return merged\n}\n\nconst isSearch = (value: string, config?: ClarityUtilsConfig): boolean => {\n const c = resolveConfig(config)\n const lower = value.toLowerCase()\n\n const tokens = tokenize(lower)\n console.group(`[isSearch] \"${value}\" | mode=${c.mode} | tokens=[${tokens.join(', ')}]`)\n if (c.mode === 'mixed' || c.mode === 'list') {\n console.log(\n `lists: blackWordSet=${c.blackWordSet?.size ?? 0} blackPunctSet=${c.blackPunctSet?.size ?? 0} whiteSet=${c.whiteSet?.size ?? 0} whiteList=${c.whiteList?.length ?? 0}`\n )\n }\n\n let result: boolean\n if (c.mode === 'length') {\n result = checkLength(lower, c)\n } else if (c.mode === 'mixed') {\n result = checkList(lower, c) && checkLength(lower, c)\n } else if (c.mode === 'score') {\n result = scoreQuery(lower, c)\n } else {\n result = scoreQuery(lower, c)\n }\n\n console.log(`→ Result: ${result}`)\n console.groupEnd()\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,8B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