@reliverse/matcha 2.2.8 → 2.3.1
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 +208 -210
- package/dist/mod.js +6 -2
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -1,210 +1,208 @@
|
|
|
1
|
-
# @reliverse/matcha
|
|
2
|
-
|
|
3
|
-
> @reliverse/matcha is a high-performance minimal glob matcher, with micromatch-level power, zepto-level size, and reliverse-grade dx.
|
|
4
|
-
|
|
5
|
-
[sponsor](https://github.com/sponsors/blefnk) — [discord](https://discord.gg/reliverse) — [npm](https://npmjs.com/package/@reliverse/matcha) — [github](https://github.com/reliverse/matcha)
|
|
6
|
-
|
|
7
|
-
## Installation
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
bun add @reliverse/matcha
|
|
11
|
-
# bun • pnpm • yarn • npm
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
## Features
|
|
15
|
-
|
|
16
|
-
You want **micromatch/picomatch features** in a **zeptomatch-sized**(🔜) package.
|
|
17
|
-
|
|
18
|
-
- 🧩 Drop-in replacement for `micromatch`, `zeptomatch`, `picomatch`
|
|
19
|
-
- 🧠 Full bash-style globbing support with advanced pattern matching
|
|
20
|
-
- 🪶 Tiny ([7.5 kB](https://bundlephobia.com/package/@reliverse/matcha@latest)), tree-shakeable, dependency-free implementation
|
|
21
|
-
- ⚡ Fast runtime with optimized regex compilation and caching
|
|
22
|
-
- 🔧 Complete toolset: escape, parse, compile, and match
|
|
23
|
-
- 🔜 1700+ picomatch and zeptomatch tests passed
|
|
24
|
-
- 🪄 Rich feature set with intuitive API
|
|
25
|
-
|
|
26
|
-
## Features in Detail
|
|
27
|
-
|
|
28
|
-
### Core Pattern Matching
|
|
29
|
-
|
|
30
|
-
- **Wildcards**
|
|
31
|
-
- `*` - Matches any characters except path separators
|
|
32
|
-
- `**` - Matches any characters including path separators (globstar)
|
|
33
|
-
- `?` - Matches exactly one character except path separators
|
|
34
|
-
|
|
35
|
-
### Advanced Pattern Matching
|
|
36
|
-
|
|
37
|
-
- **Character Classes**
|
|
38
|
-
- `[abc]` - Matches any single character from the set
|
|
39
|
-
- `[a-z]` - Matches any single character in the range
|
|
40
|
-
- `[!abc]` or `[^abc]` - Matches any single character not in the set
|
|
41
|
-
|
|
42
|
-
-
|
|
43
|
-
- `{a,b,c}`
|
|
44
|
-
-
|
|
45
|
-
-
|
|
46
|
-
-
|
|
47
|
-
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
-
|
|
51
|
-
-
|
|
52
|
-
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
-
|
|
58
|
-
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
-
|
|
68
|
-
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
-
|
|
73
|
-
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
type
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
//
|
|
136
|
-
matcha("*.js", "file.
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
//
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
//
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
//
|
|
152
|
-
matcha("file.
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
//
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
//
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
//
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
//
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
//
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
bun
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
- [`@reliverse/
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
💖 [MIT](./LICENSE) © [blefnk (Nazar Kornienko)](https://github.com/blefnk)
|
|
1
|
+
# @reliverse/matcha
|
|
2
|
+
|
|
3
|
+
> @reliverse/matcha is a high-performance minimal glob matcher, with micromatch-level power, zepto-level size, and reliverse-grade dx.
|
|
4
|
+
|
|
5
|
+
[sponsor](https://github.com/sponsors/blefnk) — [discord](https://discord.gg/reliverse) — [npm](https://npmjs.com/package/@reliverse/matcha) — [github](https://github.com/reliverse/matcha)
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
bun add @reliverse/matcha
|
|
11
|
+
# bun • pnpm • yarn • npm
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Features
|
|
15
|
+
|
|
16
|
+
You want **micromatch/picomatch features** in a **zeptomatch-sized**(🔜) package.
|
|
17
|
+
|
|
18
|
+
- 🧩 Drop-in replacement for `micromatch`, `zeptomatch`, `picomatch`
|
|
19
|
+
- 🧠 Full bash-style globbing support with advanced pattern matching
|
|
20
|
+
- 🪶 Tiny ([7.5 kB](https://bundlephobia.com/package/@reliverse/matcha@latest)), tree-shakeable, dependency-free implementation
|
|
21
|
+
- ⚡ Fast runtime with optimized regex compilation and caching
|
|
22
|
+
- 🔧 Complete toolset: escape, parse, compile, and match
|
|
23
|
+
- 🔜 1700+ picomatch and zeptomatch tests passed
|
|
24
|
+
- 🪄 Rich feature set with intuitive API
|
|
25
|
+
|
|
26
|
+
## Features in Detail
|
|
27
|
+
|
|
28
|
+
### Core Pattern Matching
|
|
29
|
+
|
|
30
|
+
- **Wildcards**
|
|
31
|
+
- `*` - Matches any characters except path separators
|
|
32
|
+
- `**` - Matches any characters including path separators (globstar)
|
|
33
|
+
- `?` - Matches exactly one character except path separators
|
|
34
|
+
|
|
35
|
+
### Advanced Pattern Matching
|
|
36
|
+
|
|
37
|
+
- **Character Classes**
|
|
38
|
+
- `[abc]` - Matches any single character from the set
|
|
39
|
+
- `[a-z]` - Matches any single character in the range
|
|
40
|
+
- `[!abc]` or `[^abc]` - Matches any single character not in the set
|
|
41
|
+
- **Brace Expansion**
|
|
42
|
+
- `{a,b,c}` - Matches any of the comma-separated patterns
|
|
43
|
+
- Nested braces supported: `{a,{b,c}}` expands correctly
|
|
44
|
+
- Numeric ranges: `{1..5}` matches 1,2,3,4,5
|
|
45
|
+
- Padded numeric ranges: `{01..05}` matches 01,02,03,04,05
|
|
46
|
+
- Alphabetic ranges: `{a..e}` matches a,b,c,d,e
|
|
47
|
+
- Case-sensitive alphabetic ranges: `{A..E}` vs `{a..e}`
|
|
48
|
+
|
|
49
|
+
- **Pattern Negation**
|
|
50
|
+
- `!pattern` - Matches anything that doesn't match the pattern
|
|
51
|
+
- Multiple negations: `!!pattern` (negates the negation)
|
|
52
|
+
- Combining with other patterns: `['*.js', '!test.js']`
|
|
53
|
+
|
|
54
|
+
### Special Features
|
|
55
|
+
|
|
56
|
+
- **Dot File Handling**
|
|
57
|
+
- By default, `*` won't match files starting with a dot
|
|
58
|
+
- Explicit dot matching with `.*.js` or setting `dot: true` option
|
|
59
|
+
- **Path Handling**
|
|
60
|
+
- Automatic path normalization (converts backslashes to forward slashes)
|
|
61
|
+
- Proper handling of path separators in globstar patterns
|
|
62
|
+
|
|
63
|
+
### Performance Optimizations
|
|
64
|
+
|
|
65
|
+
- **Pattern Compilation**
|
|
66
|
+
- Automatic caching of compiled patterns
|
|
67
|
+
- Efficient regex generation with optimized character classes
|
|
68
|
+
- Smart handling of static vs dynamic patterns
|
|
69
|
+
|
|
70
|
+
- **Memory Efficiency**
|
|
71
|
+
- Minimal memory footprint
|
|
72
|
+
- Efficient pattern parsing and compilation
|
|
73
|
+
- Smart caching strategies
|
|
74
|
+
|
|
75
|
+
## API Reference
|
|
76
|
+
|
|
77
|
+
### Main Function
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
// Returns true if input matches pattern(s)
|
|
81
|
+
matcha(pattern: string, input: string, options?: matchaOptions): boolean
|
|
82
|
+
matcha(patterns: string[], input: string, options?: matchaOptions): boolean
|
|
83
|
+
|
|
84
|
+
// Returns a compiled matcher function
|
|
85
|
+
matcha(pattern: string, options?: matchaOptions): Matcher
|
|
86
|
+
matcha(patterns: string[], options?: matchaOptions): Matcher
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
#### Options
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
interface matchaOptions {
|
|
93
|
+
dot?: boolean; // Match dotfiles (default: false)
|
|
94
|
+
nocase?: boolean; // Case-insensitive matching (default: false)
|
|
95
|
+
ignore?: string | string[]; // Patterns to ignore (applies to input)
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
#### Types
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
type Matcher = (input: string) => boolean;
|
|
103
|
+
|
|
104
|
+
type ScanResult = {
|
|
105
|
+
isGlob: boolean;
|
|
106
|
+
negated: boolean;
|
|
107
|
+
glob: string;
|
|
108
|
+
parts?: string[];
|
|
109
|
+
};
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Utility Functions
|
|
113
|
+
|
|
114
|
+
All utility functions are available as named exports and as properties on the default export:
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
compile(pattern: string, options?: matchaOptions): Matcher
|
|
118
|
+
makeRegex(pattern: string, options?: matchaOptions): RegExp
|
|
119
|
+
makeRe(pattern: string, options?: matchaOptions): RegExp // Alias for makeRegex
|
|
120
|
+
normalizePath(pathStr: string): string
|
|
121
|
+
escapeGlob(str: string): string
|
|
122
|
+
unescapeGlob(str: string): string
|
|
123
|
+
isStatic(pattern: string, options?: { dot?: boolean }): boolean
|
|
124
|
+
scan(pattern: string, options?: { parts?: boolean }): ScanResult
|
|
125
|
+
explode(pattern: string): { static: string[]; dynamic: string[] }
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Examples
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
import matcha, { compile, normalizePath } from "@reliverse/matcha";
|
|
132
|
+
|
|
133
|
+
// Basic matching
|
|
134
|
+
matcha("*.js", "file.js"); // → true
|
|
135
|
+
matcha("**/*.js", "src/utils/file.js"); // → true
|
|
136
|
+
matcha("*.js", "file.ts"); // → false
|
|
137
|
+
|
|
138
|
+
// Dot files
|
|
139
|
+
matcha("*.js", ".hidden.js"); // → false
|
|
140
|
+
matcha("*.js", ".hidden.js", { dot: true }); // → true
|
|
141
|
+
|
|
142
|
+
// Case-insensitive matching
|
|
143
|
+
matcha("*.JS", "file.js", { nocase: true }); // → true
|
|
144
|
+
|
|
145
|
+
// Character classes
|
|
146
|
+
matcha("[abc].js", "a.js"); // → true
|
|
147
|
+
matcha("[!a-z].js", "9.js"); // → true
|
|
148
|
+
|
|
149
|
+
// Brace expansion
|
|
150
|
+
matcha("file.{js,ts}", "file.js"); // → true
|
|
151
|
+
matcha("file{1..3}.js", "file2.js"); // → true
|
|
152
|
+
matcha("file{01..03}.js", "file01.js"); // → true
|
|
153
|
+
|
|
154
|
+
// Multiple patterns and negation
|
|
155
|
+
matcha(["*.js", "!test.js"], "file.js"); // → true
|
|
156
|
+
matcha(["*.js", "!file.js"], "file.js"); // → false
|
|
157
|
+
|
|
158
|
+
// Ignore option
|
|
159
|
+
matcha("*.js", "file.js", { ignore: "file.js" }); // → false
|
|
160
|
+
matcha(["*.js", "!test.js"], "test.js", { ignore: "test.js" }); // → false
|
|
161
|
+
|
|
162
|
+
// Compiled matcher
|
|
163
|
+
const matcher = compile("**/*.{js,ts}");
|
|
164
|
+
matcher("src/file.js"); // → true
|
|
165
|
+
matcher("deep/nested/file.ts"); // → true
|
|
166
|
+
|
|
167
|
+
// Path normalization (for Windows paths)
|
|
168
|
+
matcha("src/*.js", "src\\file.js"); // → true
|
|
169
|
+
normalizePath("src\\file.js"); // → "src/file.js"
|
|
170
|
+
|
|
171
|
+
// Utility: escape/unescape
|
|
172
|
+
matcha(escapeGlob("file[1].js"), "file[1].js"); // → true
|
|
173
|
+
unescapeGlob("file\\[1\\].js"); // → "file[1].js"
|
|
174
|
+
|
|
175
|
+
// Utility: isStatic, scan, explode
|
|
176
|
+
isStatic("file.js"); // → true
|
|
177
|
+
isStatic("*.js"); // → false
|
|
178
|
+
scan("!src/*.js"); // → { isGlob: true, negated: true, glob: "src/*.js" }
|
|
179
|
+
explode("src/file[1-3].js"); // → { static: ["src/file"], dynamic: ["[1-3].js"] }
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Playground
|
|
183
|
+
|
|
184
|
+
To test [example/e-mod.ts](./example/e-mod.ts), run:
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
git clone https://github.com/reliverse/matcha
|
|
188
|
+
cd matcha
|
|
189
|
+
bun i
|
|
190
|
+
bun dev # beginner-friendly example
|
|
191
|
+
bun tests # advanced test suite
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## Contributing
|
|
195
|
+
|
|
196
|
+
- 🧙 Star it on [GitHub](https://github.com/reliverse/matcha)
|
|
197
|
+
- 💬 Join our [Discord](https://discord.gg/reliverse)
|
|
198
|
+
- 💖 [Sponsor @blefnk](https://github.com/sponsors/blefnk)
|
|
199
|
+
|
|
200
|
+
## Related Reliverse Projects
|
|
201
|
+
|
|
202
|
+
- [`@reliverse/reglob`](https://npmjs.com/package/@reliverse/reglob) — Tiny, fast globber
|
|
203
|
+
- [`@reliverse/relifso`](https://npmjs.com/package/@reliverse/relifso) — Filesystem made fun again
|
|
204
|
+
- [`@reliverse/repackr`](https://npmjs.com/package/@reliverse/repackr) — Alternative to tar/7zip
|
|
205
|
+
|
|
206
|
+
## License
|
|
207
|
+
|
|
208
|
+
💖 [MIT](./LICENSE) © [blefnk (Nazar Kornienko)](https://github.com/blefnk)
|
package/dist/mod.js
CHANGED
|
@@ -12,7 +12,9 @@ export const filter = (patterns, inputs, options = {}) => {
|
|
|
12
12
|
}
|
|
13
13
|
if (patterns.length === 1) {
|
|
14
14
|
const pattern = patterns[0];
|
|
15
|
-
if (pattern === void 0)
|
|
15
|
+
if (pattern === void 0) {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
16
18
|
return inputs.filter((input) => zeptomatch(pattern, input, options));
|
|
17
19
|
}
|
|
18
20
|
return [];
|
|
@@ -24,7 +26,9 @@ export const exclude = (patterns, inputs, options = {}) => {
|
|
|
24
26
|
}
|
|
25
27
|
if (patterns.length === 1) {
|
|
26
28
|
const pattern = patterns[0];
|
|
27
|
-
if (pattern === void 0)
|
|
29
|
+
if (pattern === void 0) {
|
|
30
|
+
return inputs;
|
|
31
|
+
}
|
|
28
32
|
return inputs.filter((input) => !zeptomatch(pattern, input, options));
|
|
29
33
|
}
|
|
30
34
|
return inputs;
|
package/package.json
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reliverse/matcha",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"private": false,
|
|
5
|
-
"type": "module",
|
|
6
5
|
"description": "@reliverse/matcha is a high-performance minimal matcher, with micromatch-level power, zepto-level size, and reliverse-grade dx.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"package.json"
|
|
10
|
+
],
|
|
11
|
+
"type": "module",
|
|
7
12
|
"exports": {
|
|
8
13
|
".": {
|
|
9
14
|
"types": "./dist/mod.d.ts",
|
|
10
15
|
"default": "./dist/mod.js"
|
|
11
16
|
}
|
|
12
17
|
},
|
|
13
|
-
"dependencies": {
|
|
14
|
-
"zeptomatch": "^2.1.0"
|
|
15
|
-
},
|
|
16
18
|
"publishConfig": {
|
|
17
19
|
"access": "public"
|
|
18
20
|
},
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
],
|
|
23
|
-
"license": "MIT"
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"zeptomatch": "^2.1.0"
|
|
23
|
+
}
|
|
24
24
|
}
|