Last active
October 22, 2022 17:49
-
-
Save dmjcomdem/11252d2ff2df87512a46914c05499b51 to your computer and use it in GitHub Desktop.
Typography rus language
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function typographer( | |
string, | |
words = ['в', 'во', 'без', 'до', 'из', 'к', 'ко', 'на', 'по', 'о', 'от', 'при', 'с', 'у', 'не', 'за', 'над', 'для', 'об', 'под', 'про', 'и', 'а', 'но', 'да', 'или', 'ли', 'бы', 'то', 'что', 'как', 'я', 'он', 'мы', 'они', 'ни', 'же', 'вы', 'им'] | |
){ | |
if (!string && typeof string !== 'string') throw Error('can\'t find string'); | |
let pattern = new RegExp( words.map(w => ` ${w} `).join('|'), 'gi' ); | |
return string.replace(pattern, str => str.slice(0, -1) + ' ' ); | |
} | |
console.log( typographer('Экспериментаниум – идеальная площадка для проведения открытых уроков и интерактивных занятий') ); | |
// Экспериментаниум – идеальная площадка для проведения открытых уроков и интерактивных занятий |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment