mirror of
https://github.com/oxen-io/session-desktop.git
synced 2023-12-14 02:12:57 +01:00
24 lines
726 B
TypeScript
24 lines
726 B
TypeScript
export function cleanSearchTerm(searchTerm: string) {
|
|
const lowercase = searchTerm.toLowerCase();
|
|
const withoutSpecialCharacters = lowercase.replace(
|
|
/([!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~])/g,
|
|
' '
|
|
);
|
|
const whiteSpaceNormalized = withoutSpecialCharacters.replace(/\s+/g, ' ');
|
|
const byToken = whiteSpaceNormalized.split(' ');
|
|
const withoutSpecialTokens = byToken.filter(
|
|
token =>
|
|
token &&
|
|
token !== 'and' &&
|
|
token !== 'or' &&
|
|
token !== 'not' &&
|
|
token !== ')' &&
|
|
token !== '(' &&
|
|
token !== '+' &&
|
|
token !== ',' &&
|
|
token !== 'near'
|
|
);
|
|
const withWildcards = withoutSpecialTokens.map(token => `${token}*`);
|
|
|
|
return withWildcards.join(' ').trim();
|
|
}
|