-
Notifications
You must be signed in to change notification settings - Fork 0
/
patterns.js
38 lines (33 loc) · 1.31 KB
/
patterns.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const cyrillicLower = 'а-яё';
const cyrillicUpper = 'А-ЯЁ';
const latinLower = 'a-z';
const latinUpper = 'A-Z';
const reLower = new RegExp('^['+cyrillicLower+latinLower+']+$');
//const reLower = /^[a-zа-я]+$/;
const reUpper = new RegExp('^['+cyrillicUpper+latinUpper+']+$');
//const reUpper = /^[A-ZА-Я]+$/;
const reCyrillic = new RegExp('^['+cyrillicLower+cyrillicUpper+']+$');
//const reCyrillic = /^[а-яА-Я]+$/;
const reLatin = new RegExp('^['+latinLower+latinUpper+']+$');
//const reLatin = /^[a-zA-Z]+$/;
const isLower = (str) => reLower.test(str);
const isUpper = (str) => reUpper.test(str);
const isCyrillic = (str) => reCyrillic.test(str);
const isLatin = (str) => reLatin.test(str);
const isWord = (str) => isLatin(str) || isCyrillic(str);
const isFamily = (str) => str.split('-').every(
(s) => isWord(s) && isUpper(s[0]) && (s.length === 1 || isLower(s.substr(1)))
);
const dot = '.';
const isInitials = (str) => (
str[1] === dot && (
(str.length === 2 && isWord(str[0]) && isUpper(str[0])) ||
(str.length === 4 && str[3] === dot && isWord(str[0]+str[2]) && isUpper(str[0]+str[2]))
)
);
module.exports.isLower = isLower;
module.exports.isUpper = isUpper;
module.exports.isCyrillic = isCyrillic;
module.exports.isLatin = isLatin;
module.exports.isFamily = isFamily;
module.exports.isInitials = isInitials;