28 lines
904 B
TypeScript
28 lines
904 B
TypeScript
import { TranslatableComponent } from '@src/__components/components';
|
|
import _ from 'lodash';
|
|
|
|
export const getAllTranslationsToString = (str: string, input: TranslatableComponent): string => {
|
|
for (const key in input) {
|
|
if (Object.prototype.hasOwnProperty.call(input, key)) {
|
|
str = str + '#' + input[key].toLowerCase();
|
|
}
|
|
}
|
|
return str;
|
|
};
|
|
|
|
export const getSearchString = (...inputs: (string | TranslatableComponent)[]): string => {
|
|
let str = '';
|
|
|
|
for (let index = 0; index < inputs.length; index++) {
|
|
const element = inputs[index];
|
|
if (_.isString(element)) str = str + '#' + element.toLowerCase();
|
|
else str = getAllTranslationsToString(str, element);
|
|
}
|
|
|
|
return str;
|
|
};
|
|
|
|
//escape regex => for special characters in email
|
|
export const escapeRegex = (regex) => {
|
|
return regex.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
|
|
} |