-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
21 lines (21 loc) · 1.02 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module.exports = (inputText, minimum = 3) => {
const RusA = '[абвгдеёжзийклмнопрстуфхцчшщъыьэюя]'
const RusV = '[аеёиоуыэю\я]'
const RusN = '[бвгджзклмнпрстфхцчшщ]'
const RusX = '[йъь]'
const Hyphen = '\xAD'
const regExps = [
new RegExp('(' + RusX + ')(' + RusA + RusA + ')', 'ig'),
new RegExp('(' + RusV + ')(' + RusV + RusA + ')', 'ig'),
new RegExp('(' + RusV + RusN + ')(' + RusN + RusV + ')', 'ig'),
new RegExp('(' + RusN + RusV + ')(' + RusN + RusV + ')', 'ig'),
new RegExp('(' + RusV + RusN + ')(' + RusN + RusN + RusV + ')', 'ig'),
new RegExp('(' + RusV + RusN + RusN + ')(' + RusN + RusN + RusV + ')', 'ig'),
new RegExp('(' + RusA + '{1,' + minimum +'})' + Hyphen + '(' + RusA + '+)', 'ig')
]
let outputText = inputText
for (let i = 0; i < 5; i++) {
outputText = outputText.replace(regExps[i], '$1' + Hyphen + '$2')
}
return outputText.replace(regExps[6], '$1$2')
}