2024-07-05 14:08:12 +00:00
|
|
|
import translitConfig from './abc-translit.json'
|
2024-06-24 17:50:27 +00:00
|
|
|
|
|
|
|
const ru2en: { [key: string]: string } = translitConfig
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2022-12-01 18:45:35 +00:00
|
|
|
export const translit = (str: string) => {
|
|
|
|
if (!str) {
|
|
|
|
return ''
|
|
|
|
}
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2022-12-01 18:45:35 +00:00
|
|
|
const isCyrillic = /[ЁА-яё]/.test(str)
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2022-12-01 18:45:35 +00:00
|
|
|
if (!isCyrillic) {
|
|
|
|
return str
|
|
|
|
}
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2022-12-01 18:45:35 +00:00
|
|
|
return [...str].map((c) => ru2en[c] || c).join('')
|
2022-09-09 11:53:35 +00:00
|
|
|
}
|
2024-07-05 14:08:12 +00:00
|
|
|
|
|
|
|
export const slugify = (text: string) => {
|
|
|
|
return translit(text.toLowerCase())
|
|
|
|
.replaceAll(' ', '-')
|
|
|
|
.replaceAll(/[^\da-z]/g, '')
|
|
|
|
}
|