Skip to content

Commit 6625f5e

Browse files
add: rus to latin script for headers
1 parent 6f45522 commit 6625f5e

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

utils/rus-to-latin.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//Используйте этот скрипт, чтобы узнать, как будет выглядеть ссылка на сайте на конкретную главу
2+
3+
function generateHash(header) {
4+
return String(header)
5+
.replace(/#/g, '')
6+
.trim()
7+
.toLowerCase()
8+
.replace(/\s+/g, '-')
9+
.replace(/[^a-z\-а-я]/g, '-');
10+
}
11+
12+
function rusToLatin(str) {
13+
var ru = {
14+
'а': 'a', 'б': 'b', 'в': 'v', 'г': 'g', 'д': 'd',
15+
'е': 'e', 'ё': 'e', 'ж': 'j', 'з': 'z', 'и': 'i',
16+
'к': 'k', 'л': 'l', 'м': 'm', 'н': 'n', 'о': 'o',
17+
'п': 'p', 'р': 'r', 'с': 's', 'т': 't', 'у': 'u',
18+
'ф': 'f', 'х': 'h', 'ц': 'c', 'ч': 'ch', 'ш': 'sh',
19+
'щ': 'shch', 'ы': 'y', 'э': 'e', 'ю': 'u', 'я': 'ya'
20+
}, n_str = [];
21+
22+
str = str.replace(/[ъь]+/g, '').replace(/й/g, 'i');
23+
24+
for (var i = 0; i < str.length; ++i) {
25+
n_str.push(
26+
ru[str[i]]
27+
|| ru[str[i].toLowerCase()] == undefined && str[i]
28+
|| ru[str[i].toLowerCase()].toUpperCase()
29+
);
30+
}
31+
32+
return n_str.join('');
33+
}
34+
35+
console.log(rusToLatin(generateHash("Связаться с командой Amplicode")))

0 commit comments

Comments
 (0)