@archoleat/reglib 1.5.4 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -24,27 +24,128 @@ bun i -D @archoleat/reglib
24
24
 
25
25
  ## List of Regex
26
26
 
27
- - `FONT_FILE_NAME_REGEX`: Matches FontFamily-FontWeight.woff2
27
+ This library provides a collection of useful
28
+ regular expressions for various use cases.
29
+ Below is a list of the exported regex
30
+ patterns along with their explanations:
28
31
 
29
- - `ITALIC_REGEX`: Searches for the words `Italic` or `italic`.
32
+ - ATTRIBUTE_REGEX
30
33
 
31
- - `VARIABLE_FONT_REGEX`: Searches for the words `var` or `variable`.
34
+ - Pattern: `\[[^\]]+\]`.
35
+ - Description: Matches an attribute in square brackets.
36
+ - Example: Matches `[attr]`, `[data-test]`, but not `[attr or attr]`.
32
37
 
33
- - `selectors`
34
- - `bem`
35
- - `BLOCK_REGEX`
36
- - `ELEMENT_REGEX`
37
- - `MODIFIER_REGEX`
38
+ - CLASS_REGEX
38
39
 
39
- - `child`
40
- - `ATTRIBUTE_REGEX`
41
- - `CLASS_REGEX`
40
+ - Pattern: `\.[a-z0-9_-]+`.
41
+ - Description: Matches a CSS class name starting with a dot (.).
42
+ - Example: Matches `.class`, `.my-class`, `.class_name`, but not `class` or `.class!`.
42
43
 
43
- - `nested`
44
- - `ATTRIBUTE_REGEX`
45
- - `CLASS_REGEX`
46
- - `ELEMENT_REGEX`
47
- - `MODIFIER_REGEX`
44
+ - BLOCK_REGEX
45
+
46
+ - Pattern: `[a-z][a-z0-9]*(-[a-z0-9]+)*`.
47
+ - Description: Matches a BEM block name.
48
+ - Example: Matches `block`, `my-block`, `block-name`, but not `Block` or `block!`.
49
+
50
+ - ELEMENT_REGEX
51
+
52
+ - Pattern: `(__[a-z0-9]+(-[a-z0-9]+)*)`.
53
+ - Description: Matches a BEM element name.
54
+ - Example: Matches `__element`, `__my-element`, but not `element` or `__element!`.
55
+
56
+ - MODIFIER_REGEX
57
+
58
+ - Pattern: `(--[a-z0-9]+(-[a-z0-9]+)*)`.
59
+ - Description: Matches a BEM modifier name.
60
+ - Example: Matches `--modifier`, `--my-modifier`, but not `modifier` or `--modifier!`.
61
+
62
+ - SIBLING_REGEX
63
+
64
+ - Pattern: `(?:[^ ,{}]+\s*)?\+\s*[^ ,{}]+`.
65
+ - Description: Matches a sibling selector in CSS.
66
+ - Example: Matches `+ p`, `div + p`, `.class + .another-class`, but not `div > p`.
67
+
68
+ - CHILD_REGEX
69
+
70
+ - Pattern: `(?:[^ ,{}]+\s*)?>\s*[^ ,{}]+`.
71
+ - Description: Matches a child selector in CSS.
72
+ - Example: Matches `> p`, `div > p`, `.class > .another-class`, but not `div + p`.
73
+
74
+ - ATTRIBUTE_SIBLING_REGEX
75
+
76
+ - Pattern: `\[[^\]]+\]\s*\+\s*[^ ,{}]+`.
77
+ - Description: Matches an attribute selector followed by a sibling selector.
78
+ - Example: Matches `[attr] + div`, `[data-test] + .class`.
79
+
80
+ - ATTRIBUTE_CHILD_REGEX
81
+
82
+ - Pattern: `\[[^\]]+\]\s*>\s*[^ ,{}]+`.
83
+ - Description: Matches an attribute selector followed by a child selector.
84
+ - Example: Matches `[attr] > div`, `[data-test] > .class`.
85
+
86
+ - CLASS_SIBLING_REGEX
87
+
88
+ - Pattern: `\.[a-z0-9_-]+\s*\+\s*[^ ,{}]+`.
89
+ - Description: Matches a class selector followed by a sibling selector.
90
+ - Example: Matches `.class + div`, `.my-class + .another-class`.
91
+
92
+ - CLASS_CHILD_REGEX
93
+
94
+ - Pattern: `\.[a-z0-9_-]+\s*>\s*[^ ,{}]+`.
95
+ - Description: Matches a class selector followed by a child selector.
96
+ - Example: Matches `.class > div`, `.my-class > .another-class`.
97
+
98
+ - NESTED_ATTRIBUTE_SIBLING_REGEX
99
+
100
+ - Pattern: `&\[[^\]]+\]\s*\+\s*[^ ,{}]+`.
101
+
102
+ - Description: Matches a nested attribute selector
103
+ followed by a sibling selector.
104
+
105
+ - Example: Matches `&[attr] + div`, `&[data-test] + .class`.
106
+
107
+ - NESTED_ATTRIBUTE_CHILD_REGEX
108
+
109
+ - Pattern: `&\[[^\]]+\]\s*>\s*[^ ,{}]+`.
110
+
111
+ - Description: Matches a nested attribute selector
112
+ followed by a child selector.
113
+
114
+ - Example: Matches `&[attr] > div`, `&[data-test] > .class`.
115
+
116
+ - NESTED_CLASS_SIBLING_REGEX
117
+
118
+ - Pattern: `&\.[a-z0-9_-]+\s*\+\s*[^ ,{}]+`.
119
+ - Description: Matches a nested class selector followed by a sibling selector.
120
+ - Example: Matches `&.class + div`, `&.my-class + .another-class`.
121
+
122
+ - NESTED_CLASS_CHILD_REGEX
123
+
124
+ - Pattern: `&\.[a-z0-9_-]+\s*>\s*[^ ,{}]+`.
125
+ - Description: Matches a nested class selector followed by a child selector.
126
+ - Example: Matches `&.class > div`, `&.my-class > .another-class`.
127
+
128
+ - NESTED_ATTRIBUTE_REGEX
129
+
130
+ - Pattern: `&\[[^\]]+\]`.
131
+ - Description: Matches a nested attribute selector.
132
+ - Example: Matches `&[attr]`, `&[data-test]`.
133
+
134
+ - NESTED_CLASS_REGEX
135
+
136
+ - Pattern: `&\.[a-z0-9_-]+`.
137
+ - Description: Matches a nested class selector.
138
+ - Example: Matches `&.class`, `&.my-class`.
139
+
140
+ - FONT_FILE_NAME_REGEX
141
+
142
+ - Pattern: A complex regex for matching font file names.
143
+
144
+ - Description: Matches font file names based on family,
145
+ weight, italic, variable, and extension.
146
+
147
+ - Example: Matches `Roboto-Bold.woff2`, `OpenSans-Italic-Variable.ttf`.
148
+ > More info [validate-font-file-name](https://github.com/archoleat/validate-font-file-name)
48
149
 
49
150
  ## Contributing
50
151
 
package/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  declare const FONT_FILE_NAME_REGEX: RegExp;
2
2
 
3
+ declare const ATTRIBUTE_REGEX: string;
4
+ declare const CLASS_REGEX: string;
3
5
  declare const BLOCK_REGEX = '[a-z][a-z0-9]*(-[a-z0-9]+)*';
4
6
  declare const ELEMENT_REGEX = '(__[a-z0-9]+(-[a-z0-9]+)*)';
5
7
  declare const MODIFIER_REGEX = '(--[a-z0-9]+(-[a-z0-9]+)*)';
@@ -15,13 +17,17 @@ declare const NESTED_CLASS_SIBLING_REGEX: string;
15
17
  declare const NESTED_CLASS_CHILD_REGEX: string;
16
18
  declare const NESTED_ATTRIBUTE_REGEX: string;
17
19
  declare const NESTED_CLASS_REGEX: string;
20
+ declare const NESTED_MODIFIER_REGEX = '&--.+';
21
+ declare const NESTED_ELEMENT_REGEX = '&__.+';
18
22
 
19
23
  export {
20
24
  ATTRIBUTE_CHILD_REGEX,
25
+ ATTRIBUTE_REGEX,
21
26
  ATTRIBUTE_SIBLING_REGEX,
22
27
  BLOCK_REGEX,
23
28
  CHILD_REGEX,
24
29
  CLASS_CHILD_REGEX,
30
+ CLASS_REGEX,
25
31
  CLASS_SIBLING_REGEX,
26
32
  ELEMENT_REGEX,
27
33
  FONT_FILE_NAME_REGEX,
@@ -32,5 +38,7 @@ export {
32
38
  NESTED_CLASS_CHILD_REGEX,
33
39
  NESTED_CLASS_REGEX,
34
40
  NESTED_CLASS_SIBLING_REGEX,
41
+ NESTED_ELEMENT_REGEX,
42
+ NESTED_MODIFIER_REGEX,
35
43
  SIBLING_REGEX,
36
44
  };
package/index.js CHANGED
@@ -1 +1 @@
1
- const S="(Italic)",T="(Variable)",o="[A-Z][a-z]",G=`^${o}+(${o}+)?`,s=["Thin","Hairline","ExtraLight","UltraLight","Light","Regular","Medium","SemiBold","DemiBold","Bold","ExtraBold","UltraBold","Black","Heavy","ExtraBlack","UltraBlack"].join("|"),I=["otf","ttf","woff","woff2"].join("|"),c=`(${G})`,L=`(${s})`,X=`(${I})$`,A=[`${c}-${L}`,`(${S}?)(${T}?)`,`\\.${X}`].join(""),a=new RegExp(A),_="[a-z0-9]",E="[^ ,{}]+",t=String.raw`\[[^\]]+\]`,R=String.raw`\.[a-z0-9_-]+`,B="--",N="__",$=String.raw`\s*\+\s*`,n=String.raw`\s*>\s*`,r=`[a-z]${_}*(-${_}+)*`,i=`(${N}${_}+(-${_}+)*)`,O=`(${B}${_}+(-${_}+)*)`,D=String.raw`(?:${E}\s*)?${$}${E}`,l=String.raw`(?:${E}\s*)?${n}${E}`,C=`${t}${$}${E}`,g=`${t}${n}${E}`,M=`${R}${$}${E}`,e=`${R}${n}${E}`,H=`&${t}${$}${E}`,w=`&${t}${n}${E}`,F=`&${R}${$}${E}`,U=`&${R}${n}${E}`,d=`&${t}`,f=`&${R}`;export{g as ATTRIBUTE_CHILD_REGEX,C as ATTRIBUTE_SIBLING_REGEX,r as BLOCK_REGEX,l as CHILD_REGEX,e as CLASS_CHILD_REGEX,M as CLASS_SIBLING_REGEX,i as ELEMENT_REGEX,a as FONT_FILE_NAME_REGEX,O as MODIFIER_REGEX,w as NESTED_ATTRIBUTE_CHILD_REGEX,d as NESTED_ATTRIBUTE_REGEX,H as NESTED_ATTRIBUTE_SIBLING_REGEX,U as NESTED_CLASS_CHILD_REGEX,f as NESTED_CLASS_REGEX,F as NESTED_CLASS_SIBLING_REGEX,D as SIBLING_REGEX};
1
+ const G="(Italic)",s="(Variable)",o="[A-Z][a-z]",I=`^${o}+(${o}+)?`,c=["Thin","Hairline","ExtraLight","UltraLight","Light","Regular","Medium","SemiBold","DemiBold","Bold","ExtraBold","UltraBold","Black","Heavy","ExtraBlack","UltraBlack"].join("|"),L=["otf","ttf","woff","woff2"].join("|"),X=`(${I})`,A=`(${c})`,N=`(${L})$`,a=[`${X}-${A}`,`(${G}?)(${s}?)`,`\\.${N}`].join(""),B=new RegExp(a),_="[a-z0-9]",E="[^ ,{}]+",R=String.raw`\[[^\]]+\]`,t=String.raw`\.[a-z0-9_-]+`,T="--",S="__",$=String.raw`\s*\+\s*`,n=String.raw`\s*>\s*`,r=`[a-z]${_}*(-${_}+)*`,i=`(${S}${_}+(-${_}+)*)`,D=`(${T}${_}+(-${_}+)*)`,O=String.raw`(?:${E}\s*)?${$}${E}`,l=String.raw`(?:${E}\s*)?${n}${E}`,C=`${R}${$}${E}`,M=`${R}${n}${E}`,g=`${t}${$}${E}`,e=`${t}${n}${E}`,F=`&${R}${$}${E}`,H=`&${R}${n}${E}`,w=`&${t}${$}${E}`,U=`&${t}${n}${E}`,d=`&${R}`,f=`&${t}`,x=`&${T}.+`,P=`&${S}.+`;export{M as ATTRIBUTE_CHILD_REGEX,R as ATTRIBUTE_REGEX,C as ATTRIBUTE_SIBLING_REGEX,r as BLOCK_REGEX,l as CHILD_REGEX,e as CLASS_CHILD_REGEX,t as CLASS_REGEX,g as CLASS_SIBLING_REGEX,i as ELEMENT_REGEX,B as FONT_FILE_NAME_REGEX,D as MODIFIER_REGEX,H as NESTED_ATTRIBUTE_CHILD_REGEX,d as NESTED_ATTRIBUTE_REGEX,F as NESTED_ATTRIBUTE_SIBLING_REGEX,U as NESTED_CLASS_CHILD_REGEX,f as NESTED_CLASS_REGEX,w as NESTED_CLASS_SIBLING_REGEX,P as NESTED_ELEMENT_REGEX,x as NESTED_MODIFIER_REGEX,O as SIBLING_REGEX};
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.5.4",
4
+ "version": "1.7.0",
5
5
  "license": "MIT",
6
6
  "author": {
7
7
  "email": "archoleat@gmail.com",