MCPcopy Index your code
hub / github.com/tinyplex/tinybase / tokenize

Function tokenize

site/js/common/search.ts:228–243  ·  view source on GitHub ↗
(string: string, tokens: Set<string>, reverse?: boolean)

Source from the content-addressed store, hash-verified

226
227// Tokenize a string into words, optionally reversing the order
228const tokenize = (string: string, tokens: Set<string>, reverse?: boolean) => {
229 const words = string.replaceAll(/[^a-zA-Z0-9]/g, ' ').split(/\s+/);
230 if (reverse) {
231 words.reverse();
232 }
233 words.forEach((word) => {
234 [word, ...word.replaceAll(/([a-z])([A-Z])/g, '$1 $2').split(' ')].forEach(
235 (wordPart) => {
236 const token = wordPart.toLowerCase();
237 if (token.length > 3 || SHORT_WORDS.includes(token)) {
238 tokens.add(token);
239 }
240 },
241 );
242 });
243};
244
245// Get the weighting of a word in a string based on its position
246const getWeighting = (tokens: string, word: string) => {

Callers 1

searchLoadFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…