@archoleat/reglib 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. package/index.d.ts +92 -0
  2. package/index.js +1 -0
  3. package/package.json +3 -3
package/index.d.ts ADDED
@@ -0,0 +1,92 @@
1
+ const LETTERS_REGEX = '[A-Z][a-z]';
2
+ const FONT_FAMILY_REGEX = `^${LETTERS_REGEX}+(${LETTERS_REGEX}+)?`;
3
+ const ALLOWED_FONT_WEIGHT_REGEX = [
4
+ 'Thin',
5
+ 'Hairline',
6
+ 'ExtraLight',
7
+ 'UltraLight',
8
+ 'Light',
9
+ 'Regular',
10
+ 'Medium',
11
+ 'SemiBold',
12
+ 'DemiBold',
13
+ 'Bold',
14
+ 'ExtraBold',
15
+ 'UltraBold',
16
+ 'Black',
17
+ 'Heavy',
18
+ 'ExtraBlack',
19
+ 'UltraBlack',
20
+ ].join('|');
21
+ const ALLOWED_FONT_EXTENSION_REGEX = ['otf', 'ttf', 'woff', 'woff2'].join('|');
22
+ const FAMILY_REGEX = `(${FONT_FAMILY_REGEX})`;
23
+ const WEIGHT_REGEX = `(${ALLOWED_FONT_WEIGHT_REGEX})`;
24
+ const EXTENSION_REGEX = `(${ALLOWED_FONT_EXTENSION_REGEX})$`;
25
+ const FONT_FILE_NAME_REGEX = new RegExp(
26
+ `${FAMILY_REGEX}-${WEIGHT_REGEX}\\.${EXTENSION_REGEX}`,
27
+ );
28
+
29
+ const SPLIT_CHARS_REGEX = String.raw`(?:_|__|-|\s)`;
30
+
31
+ const ITALIC_REGEX = new RegExp(`${SPLIT_CHARS_REGEX}?(italic)`, 'i');
32
+
33
+ const VARIABLE_FONT_REGEX = new RegExp(`${SPLIT_CHARS_REGEX}?(var)`, 'i');
34
+
35
+ const EMAIL_REGEX = new RegExp(
36
+ String.raw`^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$`,
37
+ );
38
+
39
+ const LETTERS_WITH_SPACES_REGEX = new RegExp(String.raw`^[\sA-Za-zЁА-яё]+$`);
40
+
41
+ const NOT_SEPARATE_REGEX = new RegExp(String.raw`^\+[\d-]+$`);
42
+
43
+ const NOT_SPACE_REGEX = new RegExp(String.raw`^\S+$`, 'i');
44
+
45
+ const HTML_EXTENSION_REGEX = '.html';
46
+ const PUG_EXTENSION_REGEX = '.pug';
47
+
48
+ const extensions = {
49
+ HTML_EXTENSION_REGEX,
50
+ PUG_EXTENSION_REGEX,
51
+ FILE_EXTENSION_REGEX: new RegExp(String.raw`\.[^.]+$`),
52
+ JS_EXTENSION_REGEX: new RegExp(String.raw`\.js$`),
53
+ PUG_EXTENSION_REGEX_REGEX: new RegExp(`${PUG_EXTENSION_REGEX}$`),
54
+ SCSS_EXTENSION_REGEX: new RegExp(String.raw`\.s[ac]ss$`),
55
+
56
+ NODE_MODULES_REGEX: new RegExp('node_modules'),
57
+ };
58
+
59
+ const numbers = {
60
+ ALL_REGEX: new RegExp(String.raw`^\d+$`),
61
+ };
62
+
63
+ const phones = {
64
+ RU_REGEX: new RegExp(String.raw`^\+7 \((9\d{2,3})\) \d{3}-\d{2}-\d{2}$`),
65
+ US_REGEX: new RegExp(String.raw`^\+1 \((\d{3})\) \d{3}-\d{4}$`),
66
+ };
67
+
68
+ const SYMBOLS_REGEX = '[a-z0-9]';
69
+ const ATTRIBUTE_REGEX = String.raw`?\[(.*)\]`;
70
+ const CLASS_REGEX = String.raw`?\.(.*)`;
71
+ const MODIFIER_REGEX = '--';
72
+ const ELEMENT_REGEX = '__';
73
+
74
+ const selectors = {
75
+ bem: {
76
+ BLOCK_REGEX: `[a-z]${SYMBOLS_REGEX}*(-${SYMBOLS_REGEX}+)`,
77
+ ELEMENT_REGEX: `(${ELEMENT_REGEX}${SYMBOLS_REGEX}+(-${SYMBOLS_REGEX}+)*)`,
78
+ MODIFIER_REGEX: `(${MODIFIER_REGEX}${SYMBOLS_REGEX}+(-${SYMBOLS_REGEX}+)*)`,
79
+ },
80
+ nested: {
81
+ ATTRIBUTE_REGEX,
82
+ CLASS_REGEX,
83
+ ELEMENT_REGEX,
84
+ MODIFIER_REGEX,
85
+ },
86
+ child: {
87
+ ATTRIBUTE_REGEX: `${ATTRIBUTE_REGEX} &`,
88
+ CLASS_REGEX: `${CLASS_REGEX} &`,
89
+ },
90
+ };
91
+
92
+ export { EMAIL_REGEX, FONT_FILE_NAME_REGEX, ITALIC_REGEX, LETTERS_WITH_SPACES_REGEX, NOT_SEPARATE_REGEX, NOT_SPACE_REGEX, VARIABLE_FONT_REGEX, extensions, numbers, phones, selectors };
package/index.js ADDED
@@ -0,0 +1 @@
1
+ const n="[A-Z][a-z]",o=`^${n}+(${n}+)?`,s=["Thin","Hairline","ExtraLight","UltraLight","Light","Regular","Medium","SemiBold","DemiBold","Bold","ExtraBold","UltraBold","Black","Heavy","ExtraBlack","UltraBlack"].join("|"),G=["otf","ttf","woff","woff2"].join("|"),r=`(${o})`,w=`(${s})`,T=`(${G})$`,c=new RegExp(`${r}-${w}\\.${T}`),R=String.raw`(?:_|__|-|\s)`,g=new RegExp(`${R}?(italic)`,"i"),$=new RegExp(`${R}?(var)`,"i"),a=new RegExp(String.raw`^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$`),i=new RegExp(String.raw`^[\sA-Za-zЁА-яё]+$`),L=new RegExp(String.raw`^\+[\d-]+$`),N=new RegExp(String.raw`^\S+$`,"i"),I=".html",_=".pug",O={HTML_EXTENSION_REGEX:I,PUG_EXTENSION_REGEX:_,FILE_EXTENSION_REGEX:new RegExp(String.raw`\.[^.]+$`),JS_EXTENSION_REGEX:new RegExp(String.raw`\.js$`),PUG_EXTENSION_REGEX_REGEX:new RegExp(`${_}$`),SCSS_EXTENSION_REGEX:new RegExp(String.raw`\.s[ac]ss$`),NODE_MODULES_REGEX:new RegExp("node_modules")},A={ALL_REGEX:new RegExp(String.raw`^\d+$`)},x={RU_REGEX:new RegExp(String.raw`^\+7 \((9\d{2,3})\) \d{3}-\d{2}-\d{2}$`),US_REGEX:new RegExp(String.raw`^\+1 \((\d{3})\) \d{3}-\d{4}$`)},E="[a-z0-9]",t=String.raw`?\[(.*)\]`,e=String.raw`?\.(.*)`,X="--",S="__",d={bem:{BLOCK_REGEX:`[a-z]${E}*(-${E}+)`,ELEMENT_REGEX:`(${S}${E}+(-${E}+)*)`,MODIFIER_REGEX:`(${X}${E}+(-${E}+)*)`},nested:{ATTRIBUTE_REGEX:t,CLASS_REGEX:e,ELEMENT_REGEX:S,MODIFIER_REGEX:X},child:{ATTRIBUTE_REGEX:`${t} &`,CLASS_REGEX:`${e} &`}};export{a as EMAIL_REGEX,c as FONT_FILE_NAME_REGEX,g as ITALIC_REGEX,i as LETTERS_WITH_SPACES_REGEX,L as NOT_SEPARATE_REGEX,N as NOT_SPACE_REGEX,$ as VARIABLE_FONT_REGEX,O as extensions,A as numbers,x as phones,d as selectors};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@archoleat/reglib",
3
3
  "description": "Library with ready-to-use regex",
4
- "version": "1.0.3",
4
+ "version": "1.1.0",
5
5
  "license": "MIT",
6
6
  "author": {
7
7
  "email": "archoleat@gmail.com",
@@ -75,7 +75,7 @@
75
75
  "@semantic-release/git": "^10.0.1",
76
76
  "@typescript-eslint/eslint-plugin": "^7.18.0",
77
77
  "@typescript-eslint/parser": "^7.18.0",
78
- "@vitest/coverage-v8": "^2.0.4",
78
+ "@vitest/coverage-v8": "^2.0.5",
79
79
  "conventional-changelog-conventionalcommits": "^8.0.0",
80
80
  "cz-conventional-changelog": "^3.3.0",
81
81
  "editorconfig-checker": "^5.1.8",
@@ -100,6 +100,6 @@
100
100
  "rollup-plugin-esbuild": "^6.1.1",
101
101
  "semantic-release": "^24.0.0",
102
102
  "typescript": "^5.5.4",
103
- "vitest": "^2.0.4"
103
+ "vitest": "^2.0.5"
104
104
  }
105
105
  }