2022-02-16 22:19:04 +00:00
|
|
|
import XRegExp from 'xregexp';
|
2023-05-29 15:03:24 +00:00
|
|
|
import { slugify } from 'transliteration';
|
2022-02-16 22:19:04 +00:00
|
|
|
|
|
|
|
// Matches letters from any alphabet and numbers
|
|
|
|
const likeStringRegex = XRegExp('[^\\p{L}\\p{Nd}]', 'g');
|
|
|
|
export const sanitizeLikeString = (str?: string): string | undefined => str?.replace(likeStringRegex, '_');
|
|
|
|
|
2023-05-29 15:03:24 +00:00
|
|
|
// Will change any non-latin character to return a lower latin character string
|
|
|
|
// Example:
|
|
|
|
// slugifyLikeString('測試123') => 'ce-shi-123'
|
|
|
|
// slugifyLikeString('テスト123') => 'tesuto123'
|
|
|
|
export const slugifyLikeString = (str?: string) => {
|
|
|
|
if (!str) return '';
|
|
|
|
str?.replace(likeStringRegex, '_');
|
|
|
|
const slugified = slugify(str);
|
|
|
|
return slugified;
|
|
|
|
};
|
|
|
|
|
2022-02-16 22:19:04 +00:00
|
|
|
export const sanitizer = (r: object): object => r;
|