@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.
Files changed (3) hide show
  1. package/README.md +208 -210
  2. package/dist/mod.js +6 -2
  3. 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
- - **Brace Expansion**
43
- - `{a,b,c}` - Matches any of the comma-separated patterns
44
- - Nested braces supported: `{a,{b,c}}` expands correctly
45
- - Numeric ranges: `{1..5}` matches 1,2,3,4,5
46
- - Padded numeric ranges: `{01..05}` matches 01,02,03,04,05
47
- - Alphabetic ranges: `{a..e}` matches a,b,c,d,e
48
- - Case-sensitive alphabetic ranges: `{A..E}` vs `{a..e}`
49
-
50
- - **Pattern Negation**
51
- - `!pattern` - Matches anything that doesn't match the pattern
52
- - Multiple negations: `!!pattern` (negates the negation)
53
- - Combining with other patterns: `['*.js', '!test.js']`
54
-
55
- ### Special Features
56
-
57
- - **Dot File Handling**
58
- - By default, `*` won't match files starting with a dot
59
- - Explicit dot matching with `.*.js` or setting `dot: true` option
60
-
61
- - **Path Handling**
62
- - Automatic path normalization (converts backslashes to forward slashes)
63
- - Proper handling of path separators in globstar patterns
64
-
65
- ### Performance Optimizations
66
-
67
- - **Pattern Compilation**
68
- - Automatic caching of compiled patterns
69
- - Efficient regex generation with optimized character classes
70
- - Smart handling of static vs dynamic patterns
71
-
72
- - **Memory Efficiency**
73
- - Minimal memory footprint
74
- - Efficient pattern parsing and compilation
75
- - Smart caching strategies
76
-
77
- ## API Reference
78
-
79
- ### Main Function
80
-
81
- ```typescript
82
- // Returns true if input matches pattern(s)
83
- matcha(pattern: string, input: string, options?: matchaOptions): boolean
84
- matcha(patterns: string[], input: string, options?: matchaOptions): boolean
85
-
86
- // Returns a compiled matcher function
87
- matcha(pattern: string, options?: matchaOptions): Matcher
88
- matcha(patterns: string[], options?: matchaOptions): Matcher
89
- ```
90
-
91
- #### Options
92
-
93
- ```typescript
94
- interface matchaOptions {
95
- dot?: boolean; // Match dotfiles (default: false)
96
- nocase?: boolean; // Case-insensitive matching (default: false)
97
- ignore?: string | string[]; // Patterns to ignore (applies to input)
98
- }
99
- ```
100
-
101
- #### Types
102
-
103
- ```typescript
104
- type Matcher = (input: string) => boolean;
105
-
106
- type ScanResult = {
107
- isGlob: boolean;
108
- negated: boolean;
109
- glob: string;
110
- parts?: string[];
111
- };
112
- ```
113
-
114
- ### Utility Functions
115
-
116
- All utility functions are available as named exports and as properties on the default export:
117
-
118
- ```typescript
119
- compile(pattern: string, options?: matchaOptions): Matcher
120
- makeRegex(pattern: string, options?: matchaOptions): RegExp
121
- makeRe(pattern: string, options?: matchaOptions): RegExp // Alias for makeRegex
122
- normalizePath(pathStr: string): string
123
- escapeGlob(str: string): string
124
- unescapeGlob(str: string): string
125
- isStatic(pattern: string, options?: { dot?: boolean }): boolean
126
- scan(pattern: string, options?: { parts?: boolean }): ScanResult
127
- explode(pattern: string): { static: string[]; dynamic: string[] }
128
- ```
129
-
130
- ## Examples
131
-
132
- ```typescript
133
- import matcha, { compile, normalizePath } from "@reliverse/matcha";
134
-
135
- // Basic matching
136
- matcha("*.js", "file.js"); // → true
137
- matcha("**/*.js", "src/utils/file.js"); // → true
138
- matcha("*.js", "file.ts"); // false
139
-
140
- // Dot files
141
- matcha("*.js", ".hidden.js"); // → false
142
- matcha("*.js", ".hidden.js", { dot: true }); // true
143
-
144
- // Case-insensitive matching
145
- matcha("*.JS", "file.js", { nocase: true }); // true
146
-
147
- // Character classes
148
- matcha("[abc].js", "a.js"); // → true
149
- matcha("[!a-z].js", "9.js"); // true
150
-
151
- // Brace expansion
152
- matcha("file.{js,ts}", "file.js"); // → true
153
- matcha("file{1..3}.js", "file2.js"); // → true
154
- matcha("file{01..03}.js", "file01.js"); // true
155
-
156
- // Multiple patterns and negation
157
- matcha(["*.js", "!test.js"], "file.js"); // → true
158
- matcha(["*.js", "!file.js"], "file.js"); // false
159
-
160
- // Ignore option
161
- matcha("*.js", "file.js", { ignore: "file.js" }); // → false
162
- matcha(["*.js", "!test.js"], "test.js", { ignore: "test.js" }); // false
163
-
164
- // Compiled matcher
165
- const matcher = compile("**/*.{js,ts}");
166
- matcher("src/file.js"); // → true
167
- matcher("deep/nested/file.ts"); // true
168
-
169
- // Path normalization (for Windows paths)
170
- matcha("src/*.js", "src\\file.js"); // → true
171
- normalizePath("src\\file.js"); // "src/file.js"
172
-
173
- // Utility: escape/unescape
174
- matcha(escapeGlob("file[1].js"), "file[1].js"); // → true
175
- unescapeGlob("file\\[1\\].js"); // "file[1].js"
176
-
177
- // Utility: isStatic, scan, explode
178
- isStatic("file.js"); // → true
179
- isStatic("*.js"); // → false
180
- scan("!src/*.js"); // → { isGlob: true, negated: true, glob: "src/*.js" }
181
- explode("src/file[1-3].js"); // → { static: ["src/file"], dynamic: ["[1-3].js"] }
182
- ```
183
-
184
- ## Playground
185
-
186
- To test [example/e-mod.ts](./example/e-mod.ts), run:
187
-
188
- ```bash
189
- git clone https://github.com/reliverse/matcha
190
- cd matcha
191
- bun i
192
- bun dev # beginner-friendly example
193
- bun tests # advanced test suite
194
- ```
195
-
196
- ## Contributing
197
-
198
- - 🧙 Star it on [GitHub](https://github.com/reliverse/matcha)
199
- - 💬 Join our [Discord](https://discord.gg/reliverse)
200
- - 💖 [Sponsor @blefnk](https://github.com/sponsors/blefnk)
201
-
202
- ## Related Reliverse Projects
203
-
204
- - [`@reliverse/reglob`](https://npmjs.com/package/@reliverse/reglob) — Tiny, fast globber
205
- - [`@reliverse/relifso`](https://npmjs.com/package/@reliverse/relifso) — Filesystem made fun again
206
- - [`@reliverse/repackr`](https://npmjs.com/package/@reliverse/repackr) — Alternative to tar/7zip
207
-
208
- ## License
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) return [];
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) return inputs;
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.2.8",
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
- "files": [
20
- "dist",
21
- "package.json"
22
- ],
23
- "license": "MIT"
21
+ "dependencies": {
22
+ "zeptomatch": "^2.1.0"
23
+ }
24
24
  }