(string: string, tokens: Set<string>, reverse?: boolean)
| 226 | |
| 227 | // Tokenize a string into words, optionally reversing the order |
| 228 | const 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 |
| 246 | const getWeighting = (tokens: string, word: string) => { |
no outgoing calls
no test coverage detected
searching dependent graphs…