8b51f174d8
Co-authored-by: Lee Randy <randy.lee@metronom.com> Co-authored-by: Evan Hahn <69474926+EvanHahn-Signal@users.noreply.github.com> See [#5053][0]. [0]: https://github.com/signalapp/Signal-Desktop/pull/5053
27 lines
824 B
TypeScript
27 lines
824 B
TypeScript
// Copyright 2019-2020 Signal Messenger, LLC
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
export function cleanSearchTerm(searchTerm: string): 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();
|
|
}
|